use of com.ait.lienzo.client.core.types.Point2DArray in project lienzo-core by ahome-it.
the class Geometry method getCardinalIntersects.
public static void getCardinalIntersects(final PathPartList path, final Point2DArray cardinals, final Set<Point2D>[] intersections, final boolean addCenter) {
final Point2D center = cardinals.get(0);
Point2D pathStart = new Point2D(0, 0);
Point2D segmentStart = pathStart;
int i = PathPartList.skipRedundantLeadingMoveTo(path);
// A set is used as vertex's may intersect, so the start/end of two liens will intersect
for (; i < path.size(); i++) {
final PathPartEntryJSO entry = path.get(i);
NFastDoubleArrayJSO points = entry.getPoints();
switch(entry.getCommand()) {
case PathPartEntryJSO.MOVETO_ABSOLUTE:
{
points = entry.getPoints();
final Point2D m = new Point2D(points.get(0), points.get(1));
if (i == 0) {
// This position is needed, if we close the path.
pathStart = m;
}
segmentStart = m;
break;
}
case PathPartEntryJSO.LINETO_ABSOLUTE:
{
points = entry.getPoints();
final double x0 = points.get(0);
final double y0 = points.get(1);
final Point2D end = new Point2D(x0, y0);
for (int j = 1; j < cardinals.size(); j++) {
final Point2D cardinal = cardinals.get(j);
final Point2D intersectPoint = Geometry.intersectLineLine(center, cardinal, segmentStart, end);
if (intersectPoint != null) {
addIntersect(intersections, j, intersectPoint);
}
}
segmentStart = end;
break;
}
case PathPartEntryJSO.CLOSE_PATH_PART:
{
final double x0 = pathStart.getX();
final double y0 = pathStart.getY();
final Point2D end = new Point2D(x0, y0);
for (int j = 1; j < cardinals.size(); j++) {
final Point2D cardinal = cardinals.get(j);
final Point2D intersectPoint = Geometry.intersectLineLine(center, cardinal, segmentStart, end);
if (intersectPoint != null) {
addIntersect(intersections, j, intersectPoint);
}
}
segmentStart = end;
break;
}
case PathPartEntryJSO.CANVAS_ARCTO_ABSOLUTE:
{
points = entry.getPoints();
final double x0 = points.get(0);
final double y0 = points.get(1);
final Point2D p0 = new Point2D(x0, y0);
final double x1 = points.get(2);
final double y1 = points.get(3);
final Point2D p1 = new Point2D(x1, y1);
final Point2D end = p1;
final double r = points.get(4);
for (int j = 1; j < cardinals.size(); j++) {
final Point2D cardinal = cardinals.get(j);
final Point2DArray intersectPoints = Geometry.intersectLineArcTo(center, cardinal, segmentStart, p0, p1, r);
if (intersectPoints.size() > 0) {
for (final Point2D p : intersectPoints) {
addIntersect(intersections, j, p);
}
}
}
segmentStart = end;
}
break;
}
}
if (addCenter) {
addIntersect(intersections, 0, center);
}
}
use of com.ait.lienzo.client.core.types.Point2DArray in project lienzo-core by ahome-it.
the class Geometry method getIntersectPolyLinePath.
public static Point2DArray getIntersectPolyLinePath(final Point2DArray points, final PathPartList path, final boolean closed) {
Point2DArray intersectPoints = null;
if (null != path) {
final int size = closed ? points.size() : points.size() - 1;
for (int i = 0; i < size; i++) {
final Point2D p1 = points.get(i);
Point2D p2;
if (closed) {
p2 = (i < (size - 1)) ? points.get(i + 1) : points.get(0);
} else {
p2 = points.get(i + 1);
}
final Point2DArray segmentIntersectPoints = getIntersectLineSegmentPath(p1, p2, path);
if (segmentIntersectPoints != null) {
if (intersectPoints == null) {
intersectPoints = new Point2DArray();
}
for (final Point2D p : segmentIntersectPoints) {
intersectPoints.push(p);
}
}
}
}
return intersectPoints;
}
use of com.ait.lienzo.client.core.types.Point2DArray in project lienzo-core by ahome-it.
the class Geometry method getBoundingBoxOfArcTo.
public static BoundingBox getBoundingBoxOfArcTo(final Point2D p0, final Point2D p1, final Point2D p2, final double r) {
final Point2DArray arcPoints = getCanvasArcToPoints(p0, p1, p2, r);
final BoundingBox box = getBoundingBoxOfArc(arcPoints.get(0), arcPoints.get(1), arcPoints.get(2), r);
if (!arcPoints.get(0).equals(p0)) {
// p0 is always the start point of the path, but not necessary of the arc - depending on the radius
box.add(p0);
}
return box;
}
use of com.ait.lienzo.client.core.types.Point2DArray in project lienzo-core by ahome-it.
the class Geometry method removeInnerPoints.
public static final Point2DArray removeInnerPoints(final Point2D c, final Set<Point2D>[] pointSet) {
final Point2DArray points = new Point2DArray();
int i = 0;
for (final Set<Point2D> set : pointSet) {
double furthestDistance = -1;
if ((set != null) && !set.isEmpty()) {
for (final Point2D p : set) {
final double currentDistance = p.distance(c);
if (currentDistance > furthestDistance) {
furthestDistance = currentDistance;
points.set(i, p);
}
}
i++;
}
}
return points;
}
use of com.ait.lienzo.client.core.types.Point2DArray in project lienzo-core by ahome-it.
the class Geometry method getCardinalIntersects.
public static final Point2DArray getCardinalIntersects(final AbstractMultiPathPartShape<?> shape, final Direction[] requestedCardinals) {
final Point2DArray cardinals = getCardinals(shape.getBoundingBox(), requestedCardinals);
final Set<Point2D>[] intersections = getCardinalIntersects(shape, cardinals);
final Point2DArray points = removeInnerPoints(cardinals.get(0), intersections);
return points;
}
Aggregations