Package com.emitrom.lienzo.client.core.types

Examples of com.emitrom.lienzo.client.core.types.Point2D


     */
    public Line(double x1, double y1, double x2, double y2)
    {
        super(ShapeType.LINE);

        setPoints(new Point2DArray(new Point2D(x1, y1), new Point2D(x2, y2)));
    }
View Full Code Here


                        if (data.length > 0)
                        {
                            if (setStrokeParams(context, attr, alpha))
                            {
                                Point2D p0 = list.getPoint(0);

                                Point2D p1 = list.getPoint(1);

                                context.beginPath();

                                drawDashedLine(context, p0.getX(), p0.getY(), p1.getX(), p1.getY(), data, attr.getStrokeWidth() / 2);
                            }
                            return true;
                        }
                    }
                }
            }
            Point2D point = list.getPoint(0);

            context.beginPath();

            context.moveTo(point.getX(), point.getY());

            point = list.getPoint(1);

            context.lineTo(point.getX(), point.getY());

            return true;
        }
        return false;
    }
View Full Code Here

     */
    public BezierCurve(double x, double y, double controlX1, double controlY1, double controlX2, double controlY2, double endX, double endY)
    {
        super(ShapeType.BEZIER_CURVE);

        setControlPoints(new Point2DArray(new Point2D(x, y), new Point2D(controlX1, controlY1), new Point2D(controlX2, controlY2), new Point2D(endX, endY)));
    }
View Full Code Here

        if ((points != null) && (points.getLength() == 4))
        {
            context.beginPath();

            Point2D p0 = points.getPoint(0);

            Point2D p1 = points.getPoint(1);

            Point2D p2 = points.getPoint(2);

            Point2D p3 = points.getPoint(3);

            context.moveTo(p0.getX(), p0.getY());

            context.bezierCurveTo(p1.getX(), p1.getY(), p2.getX(), p2.getY(), p3.getX(), p3.getY());

            return true;
        }
        return false;
    }
View Full Code Here

        if ((null != list) && (list.getLength() >= 2))
        {
            final int leng = list.getLength();

            Point2D point = list.getPoint(0);

            context.beginPath();

            context.moveTo(point.getX(), point.getY());

            for (int i = 1; i < leng; i++)
            {
                point = list.getPoint(i);

                context.lineTo(point.getX(), point.getY());
            }
            return true;
        }
        return false;
    }
View Full Code Here

     *
     * @return Point2D
     */
    public Point2D getLocation()
    {
        return new Point2D(getX(), getY());
    }
View Full Code Here

    {
        Point2DArray list = getPolygon(); // is null for invalid arrow definition

        if ((null != list) && (list.getLength() > 2))
        {
            Point2D point = list.getPoint(0);

            context.beginPath();

            context.moveTo(point.getX(), point.getY());

            final int leng = list.getLength();

            for (int i = 1; i < leng; i++)
            {
                point = list.getPoint(i);

                context.lineTo(point.getX(), point.getY());
            }
            context.closePath();

            return true;
        }
View Full Code Here

                double sinb = Math.sin(b);
                double cosb = Math.cos(b);
                double w = getBaseWidth();
                double aw = getHeadWidth();

                Point2D s = getStart(); // arr.getPoint(0);
                Point2D e = getEnd(); // arr.getPoint(1);
                Point2D dv = e.minus(s);
                Point2D dx = dv.unit(); // unit vector in the direction of SE
                Point2D dy = dx.perpendicular();

                if (type == ArrowType.AT_END || type == ArrowType.AT_END_TAPERED || type == ArrowType.AT_BOTH_ENDS)
                {
                    // cosa*r
                    //
                    // S----+---E
                    // | a/ sina*r=aw/2
                    // sina*r | / r
                    // |/
                    // 2
                    //
                    double r = aw / (2 * sina);
                    double z = r * cosa;
                    Point2D p2 = e.minus(dx.times(z)).minus(dy.times(aw / 2));
                    Point2D p4 = e.minus(dx.times(z)).plus(dy.times(aw / 2));

                    // cosb*r2
                    //
                    // 1---+
                    // \b |
                    // \ | sinb*r2=(aw-w)/2
                    // r2 \|
                    // 2
                    //

                    Point2D p1 = p2.plus(dy.times((aw - w) / 2));
                    Point2D p5 = p4.minus(dy.times((aw - w) / 2));
                    if (b_degrees != 90)
                    {
                        double r2 = (aw - w) / (2 * sinb);
                        Point2D d1 = dx.times(r2 * cosb);
                        p1 = p1.minus(d1);
                        p5 = p5.minus(d1);
                    }

                    arr.push(p1);
                    arr.push(p2);
                    arr.push(e);
                    arr.push(p4);
                    arr.push(p5);
                }
                else if (type == ArrowType.AT_START)
                {
                    Point2D q0 = e.plus(dy.times(-w / 2));
                    Point2D q6 = e.plus(dy.times(w / 2));
                    arr.push(q0);
                    arr.push(q6);
                }
                else
                // ArrowType.AT_START_TAPERED
                {
                    arr.push(e);
                }

                if (type == ArrowType.AT_START || type == ArrowType.AT_START_TAPERED || type == ArrowType.AT_BOTH_ENDS)
                {
                    // cosa*r
                    //
                    // S----+---E
                    // | a/ sina*r=aw/2
                    // sina*r | / r
                    // |/
                    // 2
                    //
                    double r = aw / (2 * sina);
                    double z = r * cosa;
                    Point2D q2 = s.plus(dx.times(z)).minus(dy.times(aw / 2));
                    Point2D q4 = s.plus(dx.times(z)).plus(dy.times(aw / 2));

                    // cosb*r2
                    //
                    // 1---+
                    // \b |
                    // \ | sinb*r2=(aw-w)/2
                    // r2 \|
                    // 2
                    //

                    Point2D q1 = q2.plus(dy.times((aw - w) / 2));
                    Point2D q5 = q4.minus(dy.times((aw - w) / 2));
                    if (b_degrees != 90)
                    {
                        double r2 = (aw - w) / (2 * sinb);
                        Point2D d1 = dx.times(r2 * cosb);
                        q1 = q1.plus(d1);
                        q5 = q5.plus(d1);
                    }

                    arr.push(q5);
                    arr.push(q4);
                    arr.push(s);
                    arr.push(q2);
                    arr.push(q1);
                }
                else if (type == ArrowType.AT_END)
                {
                    Point2D p0 = s.plus(dy.times(-w / 2));
                    Point2D p6 = s.plus(dy.times(w / 2));

                    arr.push(p6);
                    arr.push(p0);
                }
                else
View Full Code Here

            {
                xfrm.rotate(r);
            }
            if (attr.isDefined(Attribute.SCALE))
            {
                Point2D scale = attr.getScale();

                if (null != scale)
                {
                    x = scale.getX();

                    y = scale.getY();

                    if ((x != 1) || (y != 1))
                    {
                        xfrm.scale(x, y);
                    }
                }
            }
            if (attr.isDefined(Attribute.SHEAR))
            {
                Point2D shear = attr.getShear();

                if (null != shear)
                {
                    x = shear.getX();

                    y = shear.getY();

                    if ((x != 0) || (y != 0))
                    {
                        xfrm.shear(x, y);
                    }
                }
            }
            if (attr.isDefined(Attribute.OFFSET))
            {
                Point2D offset = attr.getOffset();

                if (null != offset)
                {
                    x = offset.getX();

                    y = offset.getY();

                    if ((x != 0) || (y != 0))
                    {
                        xfrm.translate(x, y);
                    }
View Full Code Here

        int vw = vp.getWidth();

        int vh = vp.getHeight();

        Point2D a = new Point2D(0, 0);

        Point2D b = new Point2D(vw, vh);

        double scaleX = 1, scaleY = 1;

        Transform t = isTransformable() ? vp.getTransform() : getTransform();

        if (t != null)
        {
            scaleX = t.getScaleX();

            scaleY = t.getScaleY();

            t = t.getInverse();

            t.transform(a, a);

            t.transform(b, b);
        }
        double x1 = a.getX();

        double y1 = a.getY();

        double x2 = b.getX();

        double y2 = b.getY();

        for (int direction = X; direction <= Y; direction++)
        {
            boolean vertical = (direction == X);

            double scale = vertical ? scaleX : scaleY;

            double min = vertical ? x1 : y1;

            double max = vertical ? x2 : y2;

            for (int primSec = 0; primSec <= 1; primSec++)
            {
                int index = primSec * 2 + direction;

                boolean isSecondary = (primSec == 1);

                if (m_lines[index] == null)
                {
                    continue;
                }
                int n = 0;

                if (isSecondary)
                {
                    // n = primarySize div secondary
                    // ASSUMPTION: primarySize is a multiple of secondarySize

                    n = (int) Math.round(m_sizes[direction] / m_sizes[index]);
                }
                Line line = m_lines[index];

                double size = m_sizes[index];

                double previousLineWidth = line.getStrokeWidth();

                line.setStrokeWidth(previousLineWidth / scale);

                DashArray previousDashes = line.getDashArray();

                if (previousDashes != null)
                {
                    double[] d = previousDashes.getNormalizedArray();

                    DashArray dashes = new DashArray();

                    for (int i = 0; i < d.length; i++)
                    {
                        dashes.push(d[i] / scale);
                    }
                    line.setDashArray(dashes);
                }
                long n1 = Math.round(min / size);

                if (n1 * size < min)
                {
                    n1++;
                }
                long n2 = Math.round(max / size);

                if (n2 * size > max)
                {
                    n2--;
                }
                Point2DArray points = line.getPoints();

                Point2D p1 = points.getPoint(0);

                Point2D p2 = points.getPoint(1);

                if (vertical)
                {
                    p1.setY(y1);

                    p2.setY(y2);
                }
                else
                {
                    p1.setX(x1);

                    p2.setX(x2);
                }
                for (long ni = n1; ni <= n2; ni++)
                {
                    if (isSecondary && (ni % n == 0)) // skip primary lines
                    {
                        continue;
                    }
                    if (vertical)
                    {
                        double x = ni * size;

                        p1.setX(x);

                        p2.setX(x);
                    }
                    else
                    {
                        double y = ni * size;

                        p1.setY(y);

                        p2.setY(y);
                    }
                    line.drawWithTransforms(context);
                }
                line.setStrokeWidth(previousLineWidth); // restore stroke width

View Full Code Here

TOP

Related Classes of com.emitrom.lienzo.client.core.types.Point2D

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.