import java.util.HashSet;
import java.util.Set;
-import javax.vecmath.Tuple2d;
-import javax.vecmath.Vector2d;
-
+import org.apache.commons.math3.geometry.euclidean.twod.Vector2D;
import org.simantics.databoard.Bindings;
import org.simantics.db.ReadGraph;
import org.simantics.db.Resource;
// Calculate split position and edge line nearest intersection point
// ab = normalize( vec(a -> b) )
// ap = vec(a -> split pos)
- Vector2d ab = new Vector2d(nearestEdge.getX2() - nearestEdge.getX1(), nearestEdge.getY2() - nearestEdge.getY1());
- Vector2d ap = new Vector2d(splitCanvasPos.getX() - nearestEdge.getX1(), splitCanvasPos.getY() - nearestEdge.getY1());
- double theta = Math.atan2(ab.y, ab.x);
- ab.normalize();
+ Vector2D a = new Vector2D(nearestEdge.getX1(), nearestEdge.getY1());
+ Vector2D ab = new Vector2D(nearestEdge.getX2() - nearestEdge.getX1(), nearestEdge.getY2() - nearestEdge.getY1());
+ Vector2D ap = new Vector2D(splitCanvasPos.getX() - nearestEdge.getX1(), splitCanvasPos.getY() - nearestEdge.getY1());
+ double theta = Math.atan2(ab.getY(), ab.getX());
+ ab = ab.normalize();
// intersection = a + ab*(ap.ab)
- Vector2d intersection = new Vector2d(ab);
- intersection.scale(ap.dot(ab));
- intersection.add(new Vector2d(nearestEdge.getX1(), nearestEdge.getY1()));
+ Vector2D intersection = a.add( ab.scalarMultiply(ap.dotProduct(ab)) );
// Offset flag positions from the intersection point.
- Vector2d pos1 = new Vector2d(intersection);
- Vector2d pos2 = new Vector2d(intersection);
-
// TODO: improve logic for flag positioning, flags just move on the nearest line without boundaries
- ab.normalize();
- ab.scale(5);
- pos2.add(ab);
- ab.negate();
- pos1.add(ab);
+ Vector2D pos1 = intersection.subtract(5, ab);
+ Vector2D pos2 = intersection.add(5, ab);
FlagLabelingScheme scheme = DiagramFlagPreferences.getActiveFlagLabelingScheme(graph);
String commonLabel = scheme.generateLabel(graph, diagram);
FlagUtil.join(graph, flag1, flag2);
}
- private AffineTransform getFlagTransform(Tuple2d pos, double theta) {
- AffineTransform at = AffineTransform.getTranslateInstance(pos.x, pos.y);
+ private AffineTransform getFlagTransform(Vector2D pos, double theta) {
+ AffineTransform at = AffineTransform.getTranslateInstance(pos.getX(), pos.getY());
at.rotate(theta);
return at;
}