Beispiel #1
0
        /**
         * Returns how many times rectangle stripe cross path or the are intersect
         */
        public static int intersectPath(java.awt.geom.PathIterator p, double x, double y, double w, double h)
        {
            int cross = 0;
            int count;
            double mx, my, cx, cy;
            mx = my = cx = cy = 0.0;
            double[] coords = new double[6];

            double rx1 = x;
            double ry1 = y;
            double rx2 = x + w;
            double ry2 = y + h;

            while (!p.isDone())
            {
                count = 0;
                switch (p.currentSegment(coords))
                {
                    case java.awt.geom.PathIteratorConstants.SEG_MOVETO:
                        if (cx != mx || cy != my)
                        {
                            count = intersectLine(cx, cy, mx, my, rx1, ry1, rx2, ry2);
                        }
                        mx = cx = coords[0];
                        my = cy = coords[1];
                        break;
                    case java.awt.geom.PathIteratorConstants.SEG_LINETO:
                        count = intersectLine(cx, cy, cx = coords[0], cy = coords[1], rx1, ry1, rx2, ry2);
                        break;
                    case java.awt.geom.PathIteratorConstants.SEG_QUADTO:
                        count = intersectQuad(cx, cy, coords[0], coords[1], cx = coords[2], cy = coords[3], rx1, ry1, rx2, ry2);
                        break;
                    case java.awt.geom.PathIteratorConstants.SEG_CUBICTO:
                        count = intersectCubic(cx, cy, coords[0], coords[1], coords[2], coords[3], cx = coords[4], cy = coords[5], rx1, ry1, rx2, ry2);
                        break;
                    case java.awt.geom.PathIteratorConstants.SEG_CLOSE:
                        if (cy != my || cx != mx)
                        {
                            count = intersectLine(cx, cy, mx, my, rx1, ry1, rx2, ry2);
                        }
                        cx = mx;
                        cy = my;
                        break;
                }
                if (count == CROSSING)
                {
                    return CROSSING;
                }
                cross += count;
                p.next();
            }
            if (cy != my)
            {
                count = intersectLine(cx, cy, mx, my, rx1, ry1, rx2, ry2);
                if (count == CROSSING)
                {
                    return CROSSING;
                }
                cross += count;
            }
            return cross;
        }
Beispiel #2
0
        /**
         * Returns how many times ray from point (x,y) cross path
         */
        public static int crossPath(java.awt.geom.PathIterator p, double x, double y)
        {
            int cross = 0;
            double mx, my, cx, cy;
            mx = my = cx = cy = 0.0;
            double[] coords = new double[6];

            while (!p.isDone())
            {
                switch (p.currentSegment(coords))
                {
                    case java.awt.geom.PathIteratorConstants.SEG_MOVETO:
                        if (cx != mx || cy != my)
                        {
                            cross += crossLine(cx, cy, mx, my, x, y);
                        }
                        mx = cx = coords[0];
                        my = cy = coords[1];
                        break;
                    case java.awt.geom.PathIteratorConstants.SEG_LINETO:
                        cross += crossLine(cx, cy, cx = coords[0], cy = coords[1], x, y);
                        break;
                    case java.awt.geom.PathIteratorConstants.SEG_QUADTO:
                        cross += crossQuad(cx, cy, coords[0], coords[1], cx = coords[2], cy = coords[3], x, y);
                        break;
                    case java.awt.geom.PathIteratorConstants.SEG_CUBICTO:
                        cross += crossCubic(cx, cy, coords[0], coords[1], coords[2], coords[3], cx = coords[4], cy = coords[5], x, y);
                        break;
                    case java.awt.geom.PathIteratorConstants.SEG_CLOSE:
                        if (cy != my || cx != mx)
                        {
                            cross += crossLine(cx, cy, cx = mx, cy = my, x, y);
                        }
                        break;
                }

                // checks if the point (x,y) is the vertex of shape with PathIterator p
                if (x == cx && y == cy)
                {
                    cross = 0;
                    cy = my;
                    break;
                }
                p.next();
            }
            if (cy != my)
            {
                cross += crossLine(cx, cy, mx, my, x, y);
            }
            return cross;
        }