use of org.graphstream.ui.geom.Vector2 in project gs-ui-javafx by graphstream.
the class BlobShape method makeLoop.
private void makeLoop(DefaultCamera2D camera, double sox, double soy, double swx, double swy) {
double fromx = skel.apply(0).x + sox;
double fromy = skel.apply(0).y + soy;
double tox = skel.apply(3).x + sox;
double toy = skel.apply(3).y + soy;
double c1x = skel.apply(1).x + sox;
double c1y = skel.apply(1).y + soy;
double c2x = skel.apply(2).x + sox;
double c2y = skel.apply(2).y + soy;
double srcsz = Math.min(theSourceSize.x, theSourceSize.y);
// double trgsz = min( theTargetSizeX, theTargetSizeY )
Vector2 dirFrom = new Vector2(c1x - fromx, c1y - fromy);
Vector2 dirTo = new Vector2(tox - c2x, toy - c2y);
Vector2 mainDir = new Vector2(c2x - c1x, c2y - c1y);
Vector2 perpFrom = new Vector2(dirFrom.y(), -dirFrom.x());
perpFrom.normalize();
Vector2 mid1 = new Vector2(dirFrom);
mid1.sub(mainDir);
mid1.normalize();
Vector2 mid2 = new Vector2(mainDir);
mid2.sub(dirTo);
mid2.normalize();
perpFrom.scalarMult((srcsz + swx) * 0.3f);
if (isDirected) {
mid1.scalarMult((theSize + swx) * 4f);
mid2.scalarMult((theSize + swx) * 2f);
} else {
mid1.scalarMult((theSize + swx) * 4f);
mid2.scalarMult((theSize + swx) * 4f);
}
theShape = new Path2D(10, true);
theShape.moveTo(fromx + perpFrom.x(), fromy + perpFrom.y());
if (isDirected) {
theShape.curveTo(c1x + mid1.x(), c1y + mid1.y(), c2x + mid2.x(), c2y + mid2.y(), tox, toy);
theShape.curveTo(c2x - mid2.x(), c2y - mid2.y(), c1x - mid1.x(), c1y - mid1.y(), fromx - perpFrom.x(), fromy - perpFrom.y());
} else {
Vector2 perpTo = new Vector2(dirTo.y(), -dirTo.x());
perpTo.normalize();
perpTo.scalarMult((srcsz + swx) * 0.3f);
theShape.curveTo(c1x + mid1.x(), c1y + mid1.y(), c2x + mid2.x(), c2y + mid2.y(), tox + perpTo.x(), toy + perpTo.y());
theShape.lineTo(tox - perpTo.x(), toy - perpTo.y());
theShape.curveTo(c2x - mid2.x(), c2y - mid2.y(), c1x - mid1.x(), c1y - mid1.y(), fromx - perpFrom.x(), fromy - perpFrom.y());
}
theShape.closePath();
}
use of org.graphstream.ui.geom.Vector2 in project gs-ui-javafx by graphstream.
the class BlobShape method makeMulti.
private void makeMulti(DefaultCamera2D camera, double sox, double soy, double swx, double swy) {
double fromx = skel.apply(0).x + sox;
double fromy = skel.apply(0).y + soy;
double tox = skel.apply(3).x + sox;
double toy = skel.apply(3).y + soy;
double c1x = skel.apply(1).x + sox;
double c1y = skel.apply(1).y + soy;
double c2x = skel.apply(2).x + sox;
double c2y = skel.apply(2).y + soy;
double srcsz = Math.min(theSourceSize.x, theSourceSize.y);
double trgsz = Math.min(theTargetSize.x, theTargetSize.y);
Vector2 maindir = new Vector2(c2x - c1x, c2y - c1y);
Vector2 perp1 = new Vector2(maindir.y(), -maindir.x());
// 1/2 perp vector to the from point.
perp1.normalize();
// 1/2 perp vector to the to point.
Vector2 perp2 = new Vector2(perp1.x(), perp1.y());
// 1/2 perp vector to the middle point on the edge.
Vector2 perpm = new Vector2(perp1.x(), perp1.y());
double t = 5f;
perp1.scalarMult((srcsz + swx) / 2f);
perpm.scalarMult((theSize + swx) / 2f);
if (isDirected)
perp2.scalarMult((theSize + swx) / 2f);
else
perp2.scalarMult((trgsz + swx) / 2f);
theShape = new Path2D(10, true);
theShape.moveTo(fromx + perp1.x(), fromy + perp1.y());
theShape.quadTo(c1x + perpm.x(), c1y + perpm.y(), c1x + maindir.x() / t + perpm.x(), c1y + maindir.y() / t + perpm.y());
theShape.lineTo(c2x - maindir.x() / t + perpm.x(), c2y - maindir.y() / t + perpm.y());
theShape.quadTo(c2x + perpm.x(), c2y + perpm.y(), tox + perp2.x(), toy + perp2.y());
theShape.lineTo(tox - perp2.x(), toy - perp2.y());
theShape.quadTo(c2x - perpm.x(), c2y - perpm.y(), c2x - maindir.x() / t - perpm.x(), c2y - maindir.y() / t - perpm.y());
theShape.lineTo(c1x + maindir.x() / t - perpm.x(), c1y + maindir.y() / t - perpm.y());
theShape.quadTo(c1x - perpm.x(), c1y - perpm.y(), fromx - perp1.x(), fromy - perp1.y());
theShape.closePath();
}
use of org.graphstream.ui.geom.Vector2 in project gs-ui-javafx by graphstream.
the class BlobShape method makeOnLine.
private void makeOnLine(DefaultCamera2D camera, double sox, double soy, double swx, double swy) {
double fromx = skel.from().x + sox;
double fromy = skel.from().y + soy;
double tox = skel.to().x + sox;
double toy = skel.to().y + soy;
Vector2 dir = new Vector2(tox - fromx, toy - fromy);
Vector2 perp1 = new Vector2(dir.y(), -dir.x());
// 1/2 perp vector to the from point.
perp1.normalize();
// 1/2 perp vector to the to point.
Vector2 perp2 = new Vector2(perp1.x(), perp1.y());
// 1/2 perp vector to the middle point on the edge.
Vector2 perpm = new Vector2(perp1.x(), perp1.y());
double srcsz = Math.min(theSourceSize.x, theSourceSize.y);
double trgsz = Math.min(theTargetSize.x, theTargetSize.y);
perp1.scalarMult((srcsz + swx) / 2f);
perpm.scalarMult((theSize + swx) / 2f);
if (isDirected)
perp2.scalarMult((theSize + swx) / 2f);
else
perp2.scalarMult((trgsz + swx) / 2f);
double t1 = 5f;
double t2 = 2.3f;
double m = 1f;
theShape = new Path2D(10, true);
theShape.moveTo(fromx + perp1.x(), fromy + perp1.y());
theShape.quadTo(fromx + dir.x() / t1 + perpm.x() * m, fromy + dir.y() / t1 + perpm.y() * m, fromx + dir.x() / t2 + perpm.x(), fromy + dir.y() / t2 + perpm.y());
theShape.lineTo(tox - dir.x() / t2 + perpm.x(), toy - dir.y() / t2 + perpm.y());
theShape.quadTo(tox - dir.x() / t1 + perpm.x() * m, toy - dir.y() / t1 + perpm.y() * m, tox + perp2.x(), toy + perp2.y());
theShape.lineTo(tox - perp2.x(), toy - perp2.y());
theShape.quadTo(tox - dir.x() / t1 - perpm.x() * m, toy - dir.y() / t1 - perpm.y() * m, tox - dir.x() / t2 - perpm.x(), toy - dir.y() / t2 - perpm.y());
theShape.lineTo(fromx + dir.x() / t2 - perpm.x(), fromy + dir.y() / t2 - perpm.y());
theShape.quadTo(fromx + dir.x() / t1 - perpm.x() * m, fromy + dir.y() / t1 - perpm.y() * m, fromx - perp1.x(), fromy - perp1.y());
theShape.closePath();
}
use of org.graphstream.ui.geom.Vector2 in project gs-ui-javafx by graphstream.
the class LSquareEdgeShape method makeSingle.
private void makeSingle(DefaultCamera2D camera, double sox, double soy, double swx, double swy) {
Point3 from = new Point3(skel.from().x + sox, skel.from().y + soy, 0);
Point3 to = new Point3(skel.to().x + sox, skel.to().y + soy, 0);
Vector2 mainDir = new Vector2(from, to);
double length = mainDir.length();
double angle = mainDir.y() / length;
Point3 inter = null;
if (angle > 0.707107f || angle < -0.707107f) {
// North or south.
inter = new Point3(from.x, to.y, 0);
} else {
// East or west.
inter = new Point3(to.x, from.y, 0);
}
if (sox == 0 && soy == 0) {
Point3[] pts = { from, inter, to };
skel.setPoly(pts);
}
theShape = new Path2D(5, false);
theShape.moveTo(from.x, from.y);
theShape.lineTo(inter.x, inter.y);
theShape.lineTo(to.x, to.y);
}
use of org.graphstream.ui.geom.Vector2 in project gs-ui-javafx by graphstream.
the class DiamondOnEdge method makeOnCurve.
private void makeOnCurve(boolean forShadow, DefaultCamera2D camera) {
Tuple<Point2, Double> tuple = CubicCurve.approxIntersectionPointOnCurve(theEdge, theConnector, camera);
Point2 p1 = tuple.x;
double t = tuple.y;
Style style = theEdge.getStyle();
Point2 p2 = CubicCurve.eval(theConnector.fromPos(), theConnector.byPos1(), theConnector.byPos2(), theConnector.toPos(), t - 0.1f);
Vector2 dir = new Vector2(p1.x - p2.x, p1.y - p2.y);
dir.normalize();
dir.scalarMult(theSize.x);
Vector2 per = new Vector2(dir.y(), -dir.x());
per.normalize();
per.scalarMult(theSize.y);
// Create a polygon.
theShape = new Path2D(5, true);
theShape.moveTo(p1.x, p1.y);
theShape.lineTo(p1.x - dir.x() / 2 + per.x(), p1.y - dir.y() / 2 + per.y());
theShape.lineTo(p1.x - dir.x(), p1.y - dir.y());
theShape.lineTo(p1.x - dir.x() / 2 - per.x(), p1.y - dir.y() / 2 - per.y());
theShape.closePath();
}
Aggregations