Search in sources :

Example 11 with NFastDoubleArrayJSO

use of com.ait.tooling.nativetools.client.collection.NFastDoubleArrayJSO in project lienzo-core by ahome-it.

the class PathPartList method getBoundingBox.

public BoundingBox getBoundingBox() {
    final int size = size();
    if (size < 1) {
        return new BoundingBox(0, 0, 0, 0);
    }
    if (m_box != null) {
        return m_box;
    }
    m_box = new BoundingBox();
    double oldx = 0;
    double oldy = 0;
    int i = skipRedundantLeadingMoveTo(this);
    for (; i < size; i++) {
        final PathPartEntryJSO part = get(i);
        final NFastDoubleArrayJSO p = part.getPoints();
        switch(part.getCommand()) {
            case PathPartEntryJSO.LINETO_ABSOLUTE:
                m_box.add(oldx = p.get(0), oldy = p.get(1));
                break;
            case PathPartEntryJSO.MOVETO_ABSOLUTE:
                m_box.add(oldx = p.get(0), oldy = p.get(1));
                break;
            case PathPartEntryJSO.BEZIER_CURVETO_ABSOLUTE:
                m_box.add(Geometry.getBoundingBoxOfCurve(new Point2DArray(new Point2D(oldx, oldy), new Point2D(p.get(0), p.get(1)), new Point2D(p.get(2), p.get(3)), new Point2D(oldx = p.get(4), oldy = p.get(5)))));
                break;
            case PathPartEntryJSO.QUADRATIC_CURVETO_ABSOLUTE:
                m_box.add(Geometry.getBoundingBoxOfCurve(new Point2DArray(new Point2D(oldx, oldy), new Point2D(p.get(0), p.get(1)), new Point2D(oldx = p.get(2), oldy = p.get(3)))));
                break;
            case PathPartEntryJSO.ARCTO_ABSOLUTE:
                final double cx = p.get(0);
                final double cy = p.get(1);
                final double rx = p.get(2);
                final double ry = p.get(3);
                m_box.addX(cx + rx);
                m_box.addX(cx - rx);
                m_box.addY(cy + ry);
                m_box.addY(cy - ry);
                oldx = p.get(8);
                oldy = p.get(9);
                break;
            case PathPartEntryJSO.CANVAS_ARCTO_ABSOLUTE:
                final double x0 = p.get(0);
                final double y0 = p.get(1);
                final double x1 = p.get(2);
                final double y1 = p.get(3);
                final double ra = p.get(4);
                final Point2D p0 = new Point2D(oldx, oldy);
                final Point2DArray pa = Geometry.getCanvasArcToPoints(p0, new Point2D(x0, y0), new Point2D(x1, y1), ra);
                final BoundingBox bb = Geometry.getBoundingBoxOfArc(pa.get(0), pa.get(1), pa.get(2), ra);
                if (false == pa.get(0).equals(p0)) {
                    // p0 is always the start point of the path, but not necessary of the arc - depending on the radius
                    bb.add(p0);
                }
                m_box.add(bb);
                // this is always the end point of the path
                final Point2D ep = pa.get(2);
                oldx = ep.getX();
                oldy = ep.getY();
                break;
        }
    }
    return m_box;
}
Also used : NFastDoubleArrayJSO(com.ait.tooling.nativetools.client.collection.NFastDoubleArrayJSO)

Example 12 with NFastDoubleArrayJSO

use of com.ait.tooling.nativetools.client.collection.NFastDoubleArrayJSO in project lienzo-core by ahome-it.

the class PathPartList method convertEndpointToCenterParameterization.

public static final NFastDoubleArrayJSO convertEndpointToCenterParameterization(final double x1, final double y1, final double x2, final double y2, final double fa, final double fs, final double rx, final double ry, final double pv) {
    final NFastDoubleArrayJSO points = NFastDoubleArrayJSO.make();
    convertEndpointToCenterParameterization(points, x1, y1, x2, y2, fa, fs, rx, ry, pv);
    return points;
}
Also used : NFastDoubleArrayJSO(com.ait.tooling.nativetools.client.collection.NFastDoubleArrayJSO)

Example 13 with NFastDoubleArrayJSO

use of com.ait.tooling.nativetools.client.collection.NFastDoubleArrayJSO in project lienzo-core by ahome-it.

the class PathPartList method getPoints.

public Point2DArray getPoints() {
    final int size = size();
    final Point2DArray points = new Point2DArray();
    if (size < 1) {
        return points;
    }
    double oldx = 0;
    double oldy = 0;
    for (int i = 0; i < size; i++) {
        final PathPartEntryJSO part = get(i);
        final NFastDoubleArrayJSO p = part.getPoints();
        switch(part.getCommand()) {
            case PathPartEntryJSO.LINETO_ABSOLUTE:
                points.push(oldx = p.get(0), oldy = p.get(1));
                break;
            case PathPartEntryJSO.MOVETO_ABSOLUTE:
                points.push(oldx = p.get(0), oldy = p.get(1));
                break;
            case PathPartEntryJSO.BEZIER_CURVETO_ABSOLUTE:
                points.push(oldx = p.get(4), oldy = p.get(5));
                break;
            case PathPartEntryJSO.QUADRATIC_CURVETO_ABSOLUTE:
                points.push(oldx = p.get(2), oldy = p.get(3));
                break;
            case PathPartEntryJSO.ARCTO_ABSOLUTE:
                points.push(oldx = p.get(8), oldy = p.get(9));
                break;
            case PathPartEntryJSO.CANVAS_ARCTO_ABSOLUTE:
                final double x0 = p.get(0);
                final double y0 = p.get(1);
                final double x1 = p.get(2);
                final double y1 = p.get(3);
                final double ra = p.get(4);
                final Point2D p0 = new Point2D(oldx, oldy);
                final Point2DArray pa = Geometry.getCanvasArcToPoints(p0, new Point2D(x0, y0), new Point2D(x1, y1), ra);
                // this is always the end point of the path
                final Point2D ep = pa.get(2);
                points.push(oldx = ep.getX(), oldy = ep.getY());
                break;
        }
    }
    return points;
}
Also used : NFastDoubleArrayJSO(com.ait.tooling.nativetools.client.collection.NFastDoubleArrayJSO)

Example 14 with NFastDoubleArrayJSO

use of com.ait.tooling.nativetools.client.collection.NFastDoubleArrayJSO in project lienzo-core by ahome-it.

the class TextUtils method getBoundingBox.

public static BoundingBox getBoundingBox(final String text, final double size, final String style, final String family, final TextUnit unit, final TextBaseLine baseline, final TextAlign align) {
    if ((null == text) || (text.isEmpty()) || (false == (size > 0))) {
        return new BoundingBox(0, 0, 0, 0);
    }
    final String font = getFontString(size, unit, style, family);
    final String base = font + " " + baseline.getValue();
    NFastDoubleArrayJSO offs = OFFSCACHE.get(base);
    if (null == offs) {
        OFFSCACHE.put(base, offs = getTextOffsets(font, baseline));
    }
    if (null == offs) {
        return new BoundingBox(0, 0, 0, 0);
    }
    FORBOUNDS.getContext().setTextFont(font);
    FORBOUNDS.getContext().setTextAlign(TextAlign.LEFT);
    FORBOUNDS.getContext().setTextBaseline(TextBaseLine.ALPHABETIC);
    final double wide = FORBOUNDS.getContext().measureText(text).getWidth();
    final BoundingBox bbox = new BoundingBox().addY(offs.get(0)).addY(offs.get(1));
    switch(align) {
        case LEFT:
        case START:
            bbox.addX(0).addX(wide);
            break;
        case END:
        case RIGHT:
            bbox.addX(0).addX(0 - wide);
            break;
        case CENTER:
            bbox.addX(wide / 2).addX(0 - (wide / 2));
            break;
    }
    return bbox;
}
Also used : NFastDoubleArrayJSO(com.ait.tooling.nativetools.client.collection.NFastDoubleArrayJSO) BoundingBox(com.ait.lienzo.client.core.types.BoundingBox)

Example 15 with NFastDoubleArrayJSO

use of com.ait.tooling.nativetools.client.collection.NFastDoubleArrayJSO 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)

Aggregations

NFastDoubleArrayJSO (com.ait.tooling.nativetools.client.collection.NFastDoubleArrayJSO)16 Point2D (com.ait.lienzo.client.core.types.Point2D)6 PathPartEntryJSO (com.ait.lienzo.client.core.types.PathPartEntryJSO)4 BoundingBox (com.ait.lienzo.client.core.types.BoundingBox)3 PathPartList (com.ait.lienzo.client.core.types.PathPartList)3 Point2DArray (com.ait.lienzo.client.core.types.Point2DArray)2 Direction (com.ait.lienzo.shared.core.types.Direction)2 Context2D (com.ait.lienzo.client.core.Context2D)1 Path2D (com.ait.lienzo.client.core.Path2D)1 ImageData (com.ait.lienzo.client.core.types.ImageData)1 ScratchPad (com.ait.lienzo.client.core.util.ScratchPad)1 NFastStringMap (com.ait.tooling.nativetools.client.collection.NFastStringMap)1