Search in sources :

Example 11 with Direction

use of com.ait.lienzo.shared.core.types.Direction in project lienzo-core by ahome-it.

the class OrthogonalPolyLine method drawOrthogonalLinePoints.

private static final NFastDoubleArrayJSO drawOrthogonalLinePoints(final Point2DArray points, final Direction headDirection, final Direction tailDirection, final double correction, final OrthogonalPolyLine pline, final double breakDistance, final boolean write) {
    final NFastDoubleArrayJSO buffer = NFastDoubleArrayJSO.make();
    Point2D p0 = points.get(0);
    p0 = correctP0(headDirection, correction, pline, write, buffer, p0);
    Direction direction = headDirection;
    final int size = points.size();
    Point2D p1;
    Point2D p2;
    for (int i = 1; i < (size - 1); i++) {
        p1 = points.get(i);
        p2 = points.get(i + 1);
        direction = drawOrthogonalLineSegment(buffer, direction, null, p0.getX(), p0.getY(), p1.getX(), p1.getY(), p2.getX(), p2.getY(), write);
        if (null == direction) {
            return null;
        }
        p0 = p1;
    }
    p1 = points.get(size - 1);
    drawTail(points, buffer, direction, tailDirection, p0, p1, correction, pline);
    return buffer;
}
Also used : NFastDoubleArrayJSO(com.ait.tooling.nativetools.client.collection.NFastDoubleArrayJSO) Point2D(com.ait.lienzo.client.core.types.Point2D) Direction(com.ait.lienzo.shared.core.types.Direction)

Example 12 with Direction

use of com.ait.lienzo.shared.core.types.Direction in project lienzo-core by ahome-it.

the class OrthogonalPolyLine method parse.

@Override
public boolean parse(final Attributes attr) {
    Point2DArray points = attr.getControlPoints();
    points = correctBreakDistance(points, m_breakDistance);
    if (null != points) {
        if (points.size() > 1) {
            final double headOffset = attr.getHeadOffset();
            final double correction = attr.getCorrectionOffset();
            Direction headDirection = attr.getHeadDirection();
            final Direction tailDirection = attr.getTailDirection();
            if (headDirection == NONE) {
                final Point2D p0 = points.get(0);
                final Point2D p1 = points.get(1);
                final double headOffsetAndCorrect = headOffset + correction;
                headDirection = getHeadDirection(points, null, headDirection, tailDirection, p0, p1, headOffsetAndCorrect, correction, this);
            }
            final NFastDoubleArrayJSO opoint = drawOrthogonalLinePoints(points, headDirection, tailDirection, correction, this, m_breakDistance, true);
            m_headOffsetPoint = points.get(0);
            m_tailOffsetPoint = points.get(points.size() - 1);
            if (null != opoint) {
                final PathPartList list = getPathPartList();
                list.M(m_headOffsetPoint.getX(), m_headOffsetPoint.getY());
                final double radius = getCornerRadius();
                m_computedPoint2DArray = Point2DArray.fromNFastDoubleArrayJSO(opoint);
                if (radius > 0) {
                    Geometry.drawArcJoinedLines(list, m_computedPoint2DArray, radius);
                } else {
                    final int size = opoint.size();
                    // start at 2, as M is for opoint[0]
                    for (int i = 2; i < size; i += 2) {
                        list.L(opoint.get(i), opoint.get(i + 1));
                    }
                }
                return true;
            }
        }
    }
    m_computedPoint2DArray = null;
    return false;
}
Also used : Point2DArray(com.ait.lienzo.client.core.types.Point2DArray) NFastDoubleArrayJSO(com.ait.tooling.nativetools.client.collection.NFastDoubleArrayJSO) Point2D(com.ait.lienzo.client.core.types.Point2D) Direction(com.ait.lienzo.shared.core.types.Direction) PathPartList(com.ait.lienzo.client.core.types.PathPartList)

Aggregations

Point2D (com.ait.lienzo.client.core.types.Point2D)12 Direction (com.ait.lienzo.shared.core.types.Direction)12 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)6 BoundingBox (com.ait.lienzo.client.core.types.BoundingBox)5 Point2DArray (com.ait.lienzo.client.core.types.Point2DArray)4 NFastDoubleArrayJSO (com.ait.tooling.nativetools.client.collection.NFastDoubleArrayJSO)2 MultiPath (com.ait.lienzo.client.core.shape.MultiPath)1 IControlHandleList (com.ait.lienzo.client.core.shape.wires.IControlHandleList)1 WiresMagnet (com.ait.lienzo.client.core.shape.wires.WiresMagnet)1 PathPartList (com.ait.lienzo.client.core.types.PathPartList)1 HashSet (java.util.HashSet)1