ArcIterator.java revision 2362
583N/A * Copyright (c) 1997, 2003, Oracle and/or its affiliates. All rights reserved. 583N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 583N/A * This code is free software; you can redistribute it and/or modify it 583N/A * under the terms of the GNU General Public License version 2 only, as 583N/A * published by the Free Software Foundation. Oracle designates this 583N/A * particular file as subject to the "Classpath" exception as provided 583N/A * by Oracle in the LICENSE file that accompanied this code. 583N/A * This code is distributed in the hope that it will be useful, but WITHOUT 583N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 583N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 583N/A * version 2 for more details (a copy is included in the LICENSE file that 583N/A * accompanied this code). 583N/A * You should have received a copy of the GNU General Public License version 583N/A * 2 along with this work; if not, write to the Free Software Foundation, 583N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 583N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 583N/A * or visit www.oracle.com if you need additional information or have any 583N/A * A utility class to iterate over the path segments of an arc 583N/A * through the PathIterator interface. 583N/A * Return the winding rule for determining the insideness of the 583N/A * Tests if there are more points to read. 583N/A * @return true if there are more points to read 583N/A * Moves the iterator to the next segment of the path forwards 583N/A * along the primary direction of traversal as long as there are 583N/A * more points in that direction. 583N/A * btan computes the length (k) of the control segments at 583N/A * the beginning and end of a cubic bezier that approximates 583N/A * a segment of an arc with extent less than or equal to 583N/A * 90 degrees. This length (k) will be used to generate the 583N/A * 2 bezier control points for such a segment. 583N/A * a) arc is centered on 0,0 with radius of 1.0 583N/A * b) arc extent is less than 90 degrees * c) control points should preserve tangent * d) control segments should have equal length * end angle: ang2 = ang1 + extent * start point: P1 = (x1, y1) = (cos(ang1), sin(ang1)) * end point: P4 = (x4, y4) = (cos(ang2), sin(ang2)) * | x2 = x1 - k * sin(ang1) = cos(ang1) - k * sin(ang1) * | y2 = y1 + k * cos(ang1) = sin(ang1) + k * cos(ang1) * | x3 = x4 + k * sin(ang2) = cos(ang2) + k * sin(ang2) * | y3 = y4 - k * cos(ang2) = sin(ang2) - k * cos(ang2) * The formula for this length (k) can be found using the * = (P1 + 3P2 + 3P3 + P4)/8 * aPm = (cos((ang1 + ang2)/2), sin((ang1 + ang2)/2)) * Let angb = (ang2 - ang1)/2; angb is half of the angle * Solve the equation bPm == aPm * x1 + 3*x2 + 3*x3 + x4 = 8*cos((ang1 + ang2)/2) * cos(ang1) + 3*cos(ang1) - 3*k*sin(ang1) + * 3*cos(ang2) + 3*k*sin(ang2) + cos(ang2) = * = 8*cos((ang1 + ang2)/2) * 4*cos(ang1) + 4*cos(ang2) + 3*k*(sin(ang2) - sin(ang1)) = * = 8*cos((ang1 + ang2)/2) * 8*cos((ang1 + ang2)/2)*cos((ang2 - ang1)/2) + * 6*k*sin((ang2 - ang1)/2)*cos((ang1 + ang2)/2) = * = 8*cos((ang1 + ang2)/2) * 4*cos(angb) + 3*k*sin(angb) = 4 * k = 4 / 3 * (1 - cos(angb)) / sin(angb) * b) For ym coord we derive the same formula. * Since this formula can generate "NaN" values for small * angles, we will derive a safer form that does not involve * dividing by very small values: * (1 - cos(angb)) / sin(angb) = * = (1 - cos(angb))*(1 + cos(angb)) / sin(angb)*(1 + cos(angb)) = * = (1 - cos(angb)^2) / sin(angb)*(1 + cos(angb)) = * = sin(angb)^2 / sin(angb)*(1 + cos(angb)) = * = sin(angb) / (1 + cos(angb)) * Returns the coordinates and type of the current path segment in * The return value is the path segment type: * SEG_MOVETO, SEG_LINETO, SEG_QUADTO, SEG_CUBICTO, or SEG_CLOSE. * A float array of length 6 must be passed in and may be used to * store the coordinates of the point(s). * Each point is stored as a pair of float x,y coordinates. * SEG_MOVETO and SEG_LINETO types will return one point, * SEG_QUADTO will return two points, * SEG_CUBICTO will return 3 points * and SEG_CLOSE will not return any points. * Returns the coordinates and type of the current path segment in * The return value is the path segment type: * SEG_MOVETO, SEG_LINETO, SEG_QUADTO, SEG_CUBICTO, or SEG_CLOSE. * A double array of length 6 must be passed in and may be used to * store the coordinates of the point(s). * Each point is stored as a pair of double x,y coordinates. * SEG_MOVETO and SEG_LINETO types will return one point, * SEG_QUADTO will return two points, * SEG_CUBICTO will return 3 points * and SEG_CLOSE will not return any points.