Search in sources :

Example 36 with Point2DArray

use of com.ait.lienzo.client.core.types.Point2DArray in project lienzo-core by ahome-it.

the class Geometry method getIntersectLineSegmentPath.

public static Point2DArray getIntersectLineSegmentPath(final Point2D l0, final Point2D l1, final PathPartList path) {
    // the line is on the root container, it's points must be translated to be within the group of the path
    final Point2DArray line = new Point2DArray(l0, l1);
    @SuppressWarnings("unchecked") final Set<Point2D>[] // this is a line, there won't be more than one
    intersections = new Set[line.size()];
    getCardinalIntersects(path, line, intersections, false);
    Point2DArray intersectPoints = null;
    if ((intersections[1] != null) && !intersections[1].isEmpty()) {
        intersectPoints = new Point2DArray();
        for (final Point2D p : intersections[1]) {
            intersectPoints.push(p);
        }
    }
    return intersectPoints;
}
Also used : Point2DArray(com.ait.lienzo.client.core.types.Point2DArray) Set(java.util.Set) HashSet(java.util.HashSet) Point2D(com.ait.lienzo.client.core.types.Point2D)

Example 37 with Point2DArray

use of com.ait.lienzo.client.core.types.Point2DArray in project lienzo-core by ahome-it.

the class Geometry method intersectLineCircle.

/**
 * @param a0 start of the line
 * @param a1 end of the line
 * @param pc centore of the circle
 * @param r radius of the circle
 * @return
 */
public static final Point2DArray intersectLineCircle(final Point2D a0, final Point2D a1, final Point2D pc, final double r) {
    // http://stackoverflow.com/a/29067085
    // http://mathworld.wolfram.com/Circle-LineIntersection.html
    final Point2D p1 = a0.sub(pc);
    final Point2D p2 = a1.sub(pc);
    final Point2D d = p2.sub(p1);
    final double det = p1.crossScalar(p2);
    final double dSq = d.dot(d);
    final double discrimant = (r * r * dSq) - (det * det);
    if (discrimant < 0) {
        // line does not intersect
        return new Point2DArray();
    }
    if (discrimant == 0) {
        // line only intersects once, so the start or end is inside of the circle
        return new Point2DArray(((det * d.getY()) / dSq) + pc.getX(), ((-det * d.getX()) / dSq) + pc.getY());
    }
    final double discSqrt = Math.sqrt(discrimant);
    double sgn = 1;
    if (d.getY() < 0) {
        sgn = -1;
    }
    final Point2DArray intr = new Point2DArray((((det * d.getY()) + (sgn * d.getX() * discSqrt)) / dSq) + pc.getX(), (((-det * d.getX()) + (Math.abs(d.getY()) * discSqrt)) / dSq) + pc.getY());
    return intr.push((((det * d.getY()) - (sgn * d.getX() * discSqrt)) / dSq) + pc.getX(), (((-det * d.getX()) - (Math.abs(d.getY()) * discSqrt)) / dSq) + pc.getY());
}
Also used : Point2DArray(com.ait.lienzo.client.core.types.Point2DArray) Point2D(com.ait.lienzo.client.core.types.Point2D)

Example 38 with Point2DArray

use of com.ait.lienzo.client.core.types.Point2DArray in project lienzo-core by ahome-it.

the class Spline method getPathPoints.

private static final PathPoint[] getPathPoints(final Point2DArray array) {
    if ((null == array) || (array.size() < 2)) {
        return new PathPoint[0];
    }
    final Point2DArray unique = array.noAdjacentPoints();
    final int size = unique.size();
    if (size < 2) {
        return new PathPoint[0];
    }
    final PathPoint[] points = new PathPoint[size];
    for (int i = 0; i < size; i++) {
        final Point2D point = unique.get(i);
        points[i] = new PathPoint(point.getX(), point.getY());
    }
    return points;
}
Also used : Point2DArray(com.ait.lienzo.client.core.types.Point2DArray) Point2D(com.ait.lienzo.client.core.types.Point2D)

Example 39 with Point2DArray

use of com.ait.lienzo.client.core.types.Point2DArray in project lienzo-core by ahome-it.

the class Star method parse.

private boolean parse(final Attributes attr) {
    final int sp = attr.getStarPoints();
    final double ir = attr.getInnerRadius();
    final double or = attr.getOuterRadius();
    if ((sp > 4) && (ir > 0) && (or > 0) && (or > ir)) {
        m_list.M(0, 0 - or);
        final int s2 = sp * 2;
        final double corner = getCornerRadius();
        if (corner <= 0) {
            for (int n = 1; n < s2; n++) {
                final double stheta = ((n * Math.PI) / sp);
                final double radius = (((n % 2) == 0) ? or : ir);
                m_list.L(radius * Math.sin(stheta), -1 * radius * Math.cos(stheta));
            }
            m_list.Z();
        } else {
            final Point2DArray list = new Point2DArray(0, 0 - or);
            for (int n = 1; n < s2; n++) {
                final double stheta = ((n * Math.PI) / sp);
                final double radius = (((n % 2) == 0) ? or : ir);
                list.push(radius * Math.sin(stheta), -1 * radius * Math.cos(stheta));
            }
            Geometry.drawArcJoinedLines(m_list, list.push(0, 0 - or), corner);
        }
        return true;
    }
    return false;
}
Also used : Point2DArray(com.ait.lienzo.client.core.types.Point2DArray)

Example 40 with Point2DArray

use of com.ait.lienzo.client.core.types.Point2DArray in project lienzo-core by ahome-it.

the class OrthogonalPolyLine method correctBreakDistance.

public static final Point2DArray correctBreakDistance(final Point2DArray points, final double breakDistance) {
    final Point2DArray cPoints = points.copy();
    Point2D p1, p2;
    final int size = cPoints.size();
    for (int i = 0; i < (size - 1); i++) {
        p1 = cPoints.get(i);
        p2 = cPoints.get(i + 1);
        if (Geometry.closeEnough(p1.getX(), p2.getX(), breakDistance)) {
            p2.setX(p1.getX());
        }
        if (Geometry.closeEnough(p1.getY(), p2.getY(), breakDistance)) {
            p2.setY(p1.getY());
        }
    }
    return cPoints;
}
Also used : Point2DArray(com.ait.lienzo.client.core.types.Point2DArray) Point2D(com.ait.lienzo.client.core.types.Point2D)

Aggregations

Point2DArray (com.ait.lienzo.client.core.types.Point2DArray)47 Point2D (com.ait.lienzo.client.core.types.Point2D)37 BoundingBox (com.ait.lienzo.client.core.types.BoundingBox)6 HashSet (java.util.HashSet)6 Set (java.util.Set)5 Direction (com.ait.lienzo.shared.core.types.Direction)4 IControlHandle (com.ait.lienzo.client.core.shape.wires.IControlHandle)3 IControlHandleList (com.ait.lienzo.client.core.shape.wires.IControlHandleList)3 PathPartList (com.ait.lienzo.client.core.types.PathPartList)3 Attributes (com.ait.lienzo.client.core.shape.Attributes)2 MultiPath (com.ait.lienzo.client.core.shape.MultiPath)2 WiresMagnet (com.ait.lienzo.client.core.shape.wires.WiresMagnet)2 DashArray (com.ait.lienzo.client.core.types.DashArray)2 Transform (com.ait.lienzo.client.core.types.Transform)2 NFastDoubleArrayJSO (com.ait.tooling.nativetools.client.collection.NFastDoubleArrayJSO)2 Test (org.junit.Test)2 Group (com.ait.lienzo.client.core.shape.Group)1 Line (com.ait.lienzo.client.core.shape.Line)1 Node (com.ait.lienzo.client.core.shape.Node)1 OrthogonalPolyLine (com.ait.lienzo.client.core.shape.OrthogonalPolyLine)1