diff options
| author | Francis Kung <fkung@redhat.com> | 2006-07-27 20:59:41 +0000 |
|---|---|---|
| committer | Francis Kung <fkung@redhat.com> | 2006-07-27 20:59:41 +0000 |
| commit | c85d2bb435ae16ab1e6765b0f6e241aaeba9932b (patch) | |
| tree | 51ea4fd0829e7406e4b3dc338cbfc31d2bbb0e12 /gnu/java/awt/java2d/CubicSegment.java | |
| parent | acd96c927546bf72dd29df5bb8a0cca8ede496c2 (diff) | |
| download | classpath-c85d2bb435ae16ab1e6765b0f6e241aaeba9932b.tar.gz | |
2006-07-27 Francis Kung <fkung@redhat.com>classpath-0_92-branch-point
* gnu/java/awt/java2d/CubicSegment.java: Added import.
(cp1): Renamed from first().
(c2): Renamed from last().
(first): Renamed to cp1().
(getDisplacedSegments): Implemented.
(last): Renamed to cp2().
* gnu/java/awt/java2d/LineSegment.java
(cp1): Renamed from first().
(c2): Renamed from last().
(first): Renamed to cp1().
(last): Renamed to cp2().
* gnu/java/awt/java2d/QuadSegment.java
(cp1): Renamed from first().
(c2): Renamed from last().
(first): Renamed to cp1().
(last): Renamed to cp2().
* gnu/java/awt/java2d/Segment.java: Added comments.
(first): New field.
(Segment): Keep track of first element in list.
(add): Update first & last element variables.
(cp1): Renamed from first().
(c2): Renamed from last().
(first()): Renamed to cp1() to reduce ambiguity.
(last()): Renamed to cp2() to reduce ambiguity.
(reverseAll): Update first element variable..
* gnu/java/awt/peer/gtk/CairoGraphics2D.java
(draw): Remove flattening path iterator.
* java/awt/BasicStroke.java: Clarified comments.
(addSegments): Refactored some code into joinSegments and
joinInnerSegments.
(capEnd): Rename of Segment.first() and Segment.end().
(joinInnerSegments): New method.
(joinOuterSegments): New method.
(joinSegments): Refactored some code into joinOuterSegments.
(solidStroke): Connect segments together properly.
Diffstat (limited to 'gnu/java/awt/java2d/CubicSegment.java')
| -rw-r--r-- | gnu/java/awt/java2d/CubicSegment.java | 78 |
1 files changed, 59 insertions, 19 deletions
diff --git a/gnu/java/awt/java2d/CubicSegment.java b/gnu/java/awt/java2d/CubicSegment.java index 7d169b78e..bf66be870 100644 --- a/gnu/java/awt/java2d/CubicSegment.java +++ b/gnu/java/awt/java2d/CubicSegment.java @@ -39,6 +39,7 @@ exception statement from your version. */ package gnu.java.awt.java2d; +import java.awt.geom.CubicCurve2D; import java.awt.geom.Point2D; /** @@ -100,28 +101,67 @@ public class CubicSegment extends Segment } /** - * Get the "top" and "bottom" segments of this segment. - * First array element is p0 + normal, second is p0 - normal. + * Get the "top" and "bottom" segments of this segment. First array element is + * p0 + normal, second is p0 - normal. */ public Segment[] getDisplacedSegments(double radius) { + // It is, apparently, impossible to derive a curve parallel to a bezier + // curve (unless it's a straight line), so we have no choice but to + // approximate the displaced segments. Similar to FlattenPathIterator. + + Segment segmentTop = null; + Segment segmentBottom = null; this.radius = radius; - double x0 = P1.getX(); - double y0 = P1.getY(); - double x1 = cp1.getX(); - double y1 = cp1.getY(); - double x2 = cp2.getX(); - double y2 = cp2.getY(); - double x3 = P2.getX(); - double y3 = P2.getY(); - double[] p1 = normal(x0, y0, x1, y1); - double[] p2 = normal(x2, y2, x3, y3); - - // FIXME: Doesn't compile. - // return new Segment[]{s1, s2}; - return new Segment[0]; - } + CubicCurve2D[] curves = new CubicCurve2D[10]; + curves[0] = new CubicCurve2D.Double(P1.getX(), P1.getY(), cp1.getX(), + cp1.getY(), cp2.getX(), cp2.getY(), + P2.getX(), P2.getY()); + int numCurves = 1; + + // Hard-coded a recursion limit of 10 and flatness of 1... should we make + // this an option somewhere? + while (numCurves > 0) + { + // The curve is flat enough, or we've reached our recursion limit, + // so take the current start/end points and add it as a line segment + // to our final approximated curves + if (curves[numCurves - 1].getFlatnessSq() <= (radius / 3) || numCurves == 10) + { + Segment[] displaced = new LineSegment( + curves[numCurves - 1].getP1(), + curves[numCurves - 1].getP2()).getDisplacedSegments(radius); + if (segmentTop == null) + { + segmentTop = displaced[0]; + segmentBottom = displaced[1]; + } + else + { + segmentTop.add(displaced[0]); + segmentBottom.add(displaced[1]); + } + numCurves--; + } + + // Otherwise, subdivide again and continue + else + { + CubicCurve2D left = new CubicCurve2D.Double(); + CubicCurve2D right = new CubicCurve2D.Double(); + curves[numCurves - 1].subdivide(left, right); + curves[numCurves - 1] = right; + curves[numCurves] = left; + curves[numCurves - 1] = right; + curves[numCurves] = left; + numCurves++; + } + } + + return new Segment[] { segmentTop, segmentBottom }; + } + public void reverse() { Point2D temp = P1; @@ -132,12 +172,12 @@ public class CubicSegment extends Segment cp2 = temp; } - public double[] first() + public double[] cp1() { return new double[]{cp1.getX(), cp1.getY()}; } - public double[] last() + public double[] cp2() { return new double[]{cp2.getX(), cp2.getY()}; } |
