diff --git a/src/main/java/pythagoras/f/Crossing.java b/src/main/java/pythagoras/f/Crossing.java index eeb089d..66e4548 100644 --- a/src/main/java/pythagoras/f/Crossing.java +++ b/src/main/java/pythagoras/f/Crossing.java @@ -4,6 +4,9 @@ package pythagoras.f; +/** + * Internal utility methods for computing intersections and containment. + */ class Crossing { /** Return value indicating that a crossing was found. */ @@ -850,13 +853,9 @@ class Crossing return UNKNOWN; } - /** - * Allowable tolerance for bounds comparison - */ + /** Allowable tolerance for bounds comparison */ protected static final float DELTA = 1E-5f; - /** - * If roots have distance less then ROOT_DELTA they are double - */ + /** If roots have distance less then ROOT_DELTA they are double */ protected static final float ROOT_DELTA = 1E-10f; } diff --git a/src/main/java/pythagoras/f/FlatteningPathIterator.java b/src/main/java/pythagoras/f/FlatteningPathIterator.java index 162d38a..82c0152 100644 --- a/src/main/java/pythagoras/f/FlatteningPathIterator.java +++ b/src/main/java/pythagoras/f/FlatteningPathIterator.java @@ -6,88 +6,11 @@ package pythagoras.f; import java.util.NoSuchElementException; -public class FlatteningPathIterator implements PathIterator +/** + * A path iterator that flattens curves. + */ +class FlatteningPathIterator implements PathIterator { - /** - * The default points buffer size - */ - private static final int BUFFER_SIZE = 16; - - /** - * The default curve subdivision limit - */ - private static final int BUFFER_LIMIT = 16; - - /** - * The points buffer capacity - */ - private static final int BUFFER_CAPACITY = 16; - - /** - * The type of current segment to be flat - */ - int bufType; - - /** - * The curve subdivision limit - */ - int bufLimit; - - /** - * The current points buffer size - */ - int bufSize; - - /** - * The inner cursor position in points buffer - */ - int bufIndex; - - /** - * The current subdivision count - */ - int bufSubdiv; - - /** - * The points buffer - */ - float buf[]; - - /** - * The indicator of empty points buffer - */ - boolean bufEmpty = true; - - /** - * The source PathIterator - */ - PathIterator p; - - /** - * The flatness of new path - */ - float flatness; - - /** - * The square of flatness - */ - float flatness2; - - /** - * The x coordinate of previous path segment - */ - float px; - - /** - * The y coordinate of previous path segment - */ - float py; - - /** - * The tamporary buffer for getting points from PathIterator - */ - float coords[] = new float[6]; - public FlatteningPathIterator (PathIterator path, float flatness) { this(path, flatness, BUFFER_LIMIT); } @@ -119,23 +42,51 @@ public class FlatteningPathIterator implements PathIterator return bufLimit; } + @Override + // from interface PathIterator public int getWindingRule () { return p.getWindingRule(); } + @Override + // from interface PathIterator public boolean isDone () { return bufEmpty && p.isDone(); } - /** - * Calculates flat path points for the current segment of the source shape. Line segment is + @Override + // from interface PathIterator + public void next () { + if (bufEmpty) { + p.next(); + } + } + + @Override + // from interface PathIterator + public int currentSegment (float[] coords) { + if (isDone()) { + throw new NoSuchElementException("Iterator out of bounds"); + } + evaluate(); + int type = bufType; + if (type != SEG_CLOSE) { + coords[0] = px; + coords[1] = py; + if (type != SEG_MOVETO) { + type = SEG_LINETO; + } + } + return type; + } + + /** Calculates flat path points for the current segment of the source shape. Line segment is * flat by itself. Flatness of quad and cubic curves are evaluated by the getFlatnessSq() * method. Curves are subdivided until current flatness is bigger than user defined value and * subdivision limit isn't exhausted. Single source segments are translated to a series of * buffer points. The smaller the flatness the bigger the series. Every currentSegment() call * extracts one point from the buffer. When a series is completed, evaluate() takes the next - * source shape segment. - */ + * source shape segment. */ protected void evaluate () { if (bufEmpty) { bufType = p.currentSegment(coords); @@ -232,25 +183,51 @@ public class FlatteningPathIterator implements PathIterator } } - public void next () { - if (bufEmpty) { - p.next(); - } - } + /** The type of current segment to be flat */ + private int bufType; - public int currentSegment (float[] coords) { - if (isDone()) { - throw new NoSuchElementException("Iterator out of bounds"); - } - evaluate(); - int type = bufType; - if (type != SEG_CLOSE) { - coords[0] = px; - coords[1] = py; - if (type != SEG_MOVETO) { - type = SEG_LINETO; - } - } - return type; - } + /** The curve subdivision limit */ + private int bufLimit; + + /** The current points buffer size */ + private int bufSize; + + /** The inner cursor position in points buffer */ + private int bufIndex; + + /** The current subdivision count */ + private int bufSubdiv; + + /** The points buffer */ + private float buf[]; + + /** The indicator of empty points buffer */ + private boolean bufEmpty = true; + + /** The source PathIterator */ + private PathIterator p; + + /** The flatness of new path */ + private float flatness; + + /** The square of flatness */ + private float flatness2; + + /** The x coordinate of previous path segment */ + private float px; + + /** The y coordinate of previous path segment */ + private float py; + + /** The tamporary buffer for getting points from PathIterator */ + private float coords[] = new float[6]; + + /** The default points buffer size */ + private static final int BUFFER_SIZE = 16; + + /** The default curve subdivision limit */ + private static final int BUFFER_LIMIT = 16; + + /** The points buffer capacity */ + private static final int BUFFER_CAPACITY = 16; }