Package java.awt.geom.Point2D

Examples of java.awt.geom.Point2D.Float


            ((Graphics2D) g).translate(tw/2, th/2);
        }

        PathIterator pi = trajectory.getPathIterator(null);
        float[] coords = new float[6];
        Float cp = new Point2D.Float();
        Point2D.Float sp = new Point2D.Float();
        int ret;
        float totalDist = 0;
        List<float[]> segStack = new ArrayList<float[]>();
        do {
            try {
                ret = pi.currentSegment(coords);
            } catch (NoSuchElementException e) {
                // invalid object definition - one of the bounds is zero or less
                return;
            }
            if (ret == PathIterator.SEG_LINETO || (ret == PathIterator.SEG_CLOSE && (sp.x != cp.x || sp.y != cp.y))) {
                //close by line
                float c = calcLine(coords, cp);
                totalDist += c;
                // move the point to the end (just so it is same for all of them
                segStack.add(new float[] { c, 0, 0, 0, 0, coords[0], coords[1], ret });
                cp.x = coords[0];
                cp.y = coords[1];
            }
            if (ret == PathIterator.SEG_MOVETO) {
                sp.x = cp.x = coords[0];
                sp.y = cp.y = coords[1];

            }
            if (ret == PathIterator.SEG_CUBICTO) {
                float c = calcCube(coords, cp);
                totalDist += c;
                segStack.add(new float[] { c, coords[0], coords[1], coords[2],
                        coords[3], coords[4], coords[5], ret });
                cp.x = coords[4];
                cp.y = coords[5];
            }
            if (ret == PathIterator.SEG_QUADTO) {
                float c = calcLengthOfQuad(coords, cp);
                totalDist += c;
                segStack.add(new float[] { c, coords[0], coords[1], 0 ,0 , coords[2],
                        coords[3], ret });
                cp.x = coords[2];
                cp.y = coords[3];
            }
            // got a starting point, center point on it.
            pi.next();
        } while (!pi.isDone());
        float nxtP = totalDist / getPoints();
        List<Point2D.Float> pList = new ArrayList<Point2D.Float>();
        pList.add(new Float(sp.x, sp.y));
        int sgIdx = 0;
        float[] sgmt = segStack.get(sgIdx);
        float len = sgmt[0];
        float travDist = nxtP;
        Float center = new Float(sp.x, sp.y);
        for (int i = 1; i < getPoints(); i++) {
            while (len < nxtP) {
                sgIdx++;
                // Be carefull when messing around with points.
                sp.x = sgmt[5];
                sp.y = sgmt[6];
                sgmt = segStack.get(sgIdx);
                travDist = nxtP - len;
                len += sgmt[0];
            }
            len -= nxtP;
            Float p = calcPoint(travDist, sp, sgmt, width, height);
            pList.add(p);
            center.x += p.x;
            center.y += p.y;
            travDist += nxtP;
        }
View Full Code Here


    }

    private Point2D.Float calcPoint(float dist2go, Point2D.Float startPoint,
            float[] sgmt, int w, int h) {
        Float f = new Point2D.Float();
        if (sgmt[7] == PathIterator.SEG_LINETO) {
            // linear
            float a = sgmt[5] - startPoint.x;
            float b = sgmt[6] - startPoint.y;
            float pathLen = sgmt[0];
            f.x = startPoint.x + a * dist2go / pathLen;
            f.y = startPoint.y + b * dist2go / pathLen;
        } else if (sgmt[7] == PathIterator.SEG_QUADTO) {
            // quadratic curve
            Float ctrl = new Point2D.Float(sgmt[1]/w, sgmt[2]/h);
            Float end = new Point2D.Float(sgmt[5]/w, sgmt[6]/h);
            Float start = new Float(startPoint.x/w, startPoint.y/h);

            // trans coords from abs to rel
            f = getXY(dist2go / sgmt[0], start, ctrl, end);
            f.x *= w;
            f.y *= h;
View Full Code Here

     * @param coords Segment coordinates
     * @param cp Start point.
     * @return Length of the segment.
     */
    private float calcLengthOfQuad(float[] coords, Point2D.Float cp) {
        Float ctrl = new Point2D.Float(coords[0], coords[1]);
        Float end = new Point2D.Float(coords[2], coords[3]);
        // get abs values
        // ctrl1
        float c1ax = Math.abs(cp.x - ctrl.x) ;
        float c1ay = Math.abs(cp.y - ctrl.y) ;
        // end1
        float e1ax = Math.abs(cp.x - end.x) ;
        float e1ay = Math.abs(cp.y - end.y) ;
        // get max value on each axis
        float maxX = Math.max(c1ax, e1ax);
        float maxY = Math.max(c1ay, e1ay);

        // trans coords from abs to rel
        // ctrl1
        ctrl.x = c1ax / maxX;
        ctrl.y = c1ay / maxY;
        // end1
        end.x = e1ax / maxX;
        end.y = e1ay / maxY;

        // claculate length
        float prevLength = 0, prevX = 0, prevY = 0;
        for (float t = 0.01f; t <= 1.0f; t += .01f) {
            Point2D.Float xy = getXY(t, new Float(0,0), ctrl, end);
            prevLength += (float) Math.sqrt((xy.x - prevX) * (xy.x - prevX)
                    + (xy.y - prevY) * (xy.y - prevY));
            prevX = xy.x;
            prevY = xy.y;
        }
View Full Code Here

    /**
     * {@inheritDoc}
     */
    @Override
    Float getCharMetrics(char ch){
        return new Float(getCodePointAdvance(ch), 0);
    }
View Full Code Here

TOP

Related Classes of java.awt.geom.Point2D.Float

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.