use of com.ait.lienzo.client.core.types.Point2DArray in project kie-wb-common by kiegroup.
the class DirectionalLineTest method testStkipParse.
@Test
public void testStkipParse() throws Exception {
final Attributes attr = mock(Attributes.class);
final Point2DArray points = new Point2DArray();
when(attr.getControlPoints()).thenReturn(points);
final boolean parsed = tested.parse(attr);
assertFalse(parsed);
}
use of com.ait.lienzo.client.core.types.Point2DArray in project lienzo-core by ahome-it.
the class Geometry method findIntersection.
/**
* Finds intersecting point from the center of a path
* @param x
* @param y
* @param path
* @return the path's intersection point, or null if there's no intersection point
*/
public static Point2D findIntersection(final int x, final int y, final MultiPath path) {
final Point2D pointerPosition = new Point2D(x, y);
final BoundingBox box = path.getBoundingBox();
final Point2D center = findCenter(box);
// length just needs to ensure the c to xy is outside of the path
final double length = box.getWidth() + box.getHeight();
final Point2D projectionPoint = getProjection(center, pointerPosition, length);
final Point2DArray points = new Point2DArray();
points.push(center);
points.push(projectionPoint);
final Set<Point2D>[] intersects = Geometry.getCardinalIntersects(path, points);
Point2D nearest = null;
for (final Set<Point2D> set : intersects) {
double nearesstDistance = length;
if ((set != null) && !set.isEmpty()) {
for (final Point2D p : set) {
final double currentDistance = p.distance(pointerPosition);
if (currentDistance < nearesstDistance) {
nearesstDistance = currentDistance;
nearest = p;
}
}
}
}
return nearest;
}
use of com.ait.lienzo.client.core.types.Point2DArray in project lienzo-core by ahome-it.
the class Geometry method getCardinals.
/**
* Returns cardinal points for a given bounding box
*
* @param box the bounding box
* @return [C, N, NE, E, SE, S, SW, W, NW]
*/
public static final Point2DArray getCardinals(final BoundingBox box, final Direction[] requestedCardinals) {
final Set<Direction> set = new HashSet<>(Arrays.asList(requestedCardinals));
final Point2DArray points = new Point2DArray();
final Point2D c = findCenter(box);
final Point2D n = new Point2D(c.getX(), box.getY());
final Point2D e = new Point2D(box.getX() + box.getWidth(), c.getY());
final Point2D s = new Point2D(c.getX(), box.getY() + box.getHeight());
final Point2D w = new Point2D(box.getX(), c.getY());
final Point2D sw = new Point2D(w.getX(), s.getY());
final Point2D se = new Point2D(e.getX(), s.getY());
final Point2D ne = new Point2D(e.getX(), n.getY());
final Point2D nw = new Point2D(w.getX(), n.getY());
points.push(c);
if (set.contains(Direction.NORTH)) {
points.push(n);
}
if (set.contains(Direction.NORTH_EAST)) {
points.push(ne);
}
if (set.contains(Direction.EAST)) {
points.push(e);
}
if (set.contains(Direction.SOUTH_EAST)) {
points.push(se);
}
if (set.contains(Direction.SOUTH)) {
points.push(s);
}
if (set.contains(Direction.SOUTH_WEST)) {
points.push(sw);
}
if (set.contains(Direction.WEST)) {
points.push(w);
}
if (set.contains(Direction.NORTH_WEST)) {
points.push(nw);
}
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 Point2DArray getCardinalIntersects(final PathPartList path, final Direction[] requestedCardinals) {
final Point2DArray cardinals = getCardinals(path.getBoundingBox(), requestedCardinals);
@SuppressWarnings("unchecked") final Set<Point2D>[] // c is removed, so -1
intersections = new Set[cardinals.size()];
getCardinalIntersects(path, cardinals, intersections, true);
return removeInnerPoints(cardinals.get(0), intersections);
}
use of com.ait.lienzo.client.core.types.Point2DArray in project lienzo-core by ahome-it.
the class Geometry method getPathIntersect.
/**
* Finds the intersection of the connector's end segment on a path.
* @param connection
* @param path
* @param c
* @param pointIndex
* @return
*/
public static Point2D getPathIntersect(final WiresConnection connection, final MultiPath path, final Point2D c, final int pointIndex) {
final Point2DArray plist = connection.getConnector().getLine().getPoint2DArray();
Point2D p = plist.get(pointIndex).copy();
final Point2D offsetP = path.getComputedLocation();
p.offset(-offsetP.getX(), -offsetP.getY());
// p may be within the path boundary, so work of a vector that guarantees a point outside
final double width = path.getBoundingBox().getWidth();
if (c.equals(p)) {
// this happens with the magnet is over the center of the opposite shape
// so either the shapes are horizontall or vertically aligned.
// this means we can just take the original centre point for the project
// without this the project throw an error as you cannot unit() something of length 0,0
p.offset(offsetP.getX(), offsetP.getY());
}
try {
p = getProjection(c, p, width);
final Set<Point2D>[] set = Geometry.getCardinalIntersects(path, new Point2DArray(c, p));
final Point2DArray points = Geometry.removeInnerPoints(c, set);
return (points.size() > 1) ? points.get(1) : null;
} catch (final Exception e) {
return null;
}
}
Aggregations