use of com.ait.lienzo.client.core.types.BoundingBox in project kie-wb-common by kiegroup.
the class DelegateWiresCompositeControlTest method testBoundConstraints.
@Test
public void testBoundConstraints() {
BoundingBox boundingBox = mock(BoundingBox.class);
tested.setBoundsConstraint(boundingBox);
verify(delegate, times(1)).setBoundsConstraint(eq(boundingBox));
}
use of com.ait.lienzo.client.core.types.BoundingBox 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.BoundingBox in project lienzo-core by ahome-it.
the class Geometry method setScaleToFit.
public static final IPrimitive<?> setScaleToFit(final IPrimitive<?> prim, final double wide, final double high) {
final Point2D scale = prim.getScale();
final BoundingBox bbox = prim.getBoundingBox();
if (null != scale) {
final double sx = scale.getX();
final double sy = scale.getY();
if ((sx != 1) || (sy != 1)) {
return setScaleToFit(prim, wide, high, new BoundingPoints(bbox).transform(new Transform().scale(sx, sy)).getBoundingBox());
}
}
return setScaleToFit(prim, wide, high, bbox);
}
use of com.ait.lienzo.client.core.types.BoundingBox in project lienzo-core by ahome-it.
the class Geometry method getBoundingBoxOfArc.
public static BoundingBox getBoundingBoxOfArc(final Point2D ps, final Point2D pc, final Point2D pe, final double r) {
final double xs = ps.getX();
final double ys = ps.getY();
final double xe = pe.getX();
final double ye = pe.getY();
// the length doesn't matter, just take largest x
final Point2D p0 = new Point2D(xs > xe ? xs : xe, pc.getY());
double as = Geometry.getAngleBetweenTwoLines(ps, pc, p0);
if (ps.getY() < pc.getY()) {
// deduct from 360, if angle is above
as = Geometry.RADIANS_360 - as;
}
double ae = Geometry.getAngleBetweenTwoLines(pe, pc, p0);
if (pe.getY() < pc.getY()) {
// deduct from 360, if angle is above
ae = Geometry.RADIANS_360 - ae;
}
if (!clockwise(as, ae)) {
// reverse to make clockwise
final double t = ae;
ae = as;
as = t;
}
if (ae < as) {
// this only happens when as is before RADIANS_270 and and ae is after RADIANS_270
ae += Geometry.RADIANS_360;
}
double xmin = 0, xmax = 0;
double ymin = 0, ymax = 0;
if (xs < xe) {
xmin = xs;
xmax = xe;
} else {
xmin = xe;
xmax = xs;
}
if (ys < ye) {
ymin = ys;
ymax = ye;
} else {
ymin = ye;
ymax = ys;
}
if (ae > RADIANS_90) {
if (as < RADIANS_90) {
ymax = pc.getY() + r;
}
if (ae > RADIANS_180) {
if (as < RADIANS_180) {
xmin = pc.getX() - r;
}
if (ae > RADIANS_270) {
if (as < RADIANS_270) {
ymin = pc.getY() - r;
}
if (ae > RADIANS_360) {
xmax = pc.getX() + r;
if (ae > RADIANS_450) {
ymax = pc.getY() + r;
if (ae > RADIANS_540) {
xmin = pc.getX() - r;
if (ae > RADIANS_630) {
ymin = pc.getY() - r;
}
}
}
}
}
}
}
return new BoundingBox(xmin, ymin, xmax, ymax);
}
use of com.ait.lienzo.client.core.types.BoundingBox 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;
}
Aggregations