Formatting and javadoc cleanup.
This commit is contained in:
@@ -4,6 +4,9 @@
|
|||||||
|
|
||||||
package pythagoras.f;
|
package pythagoras.f;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Internal utility methods for computing intersections and containment.
|
||||||
|
*/
|
||||||
class Crossing
|
class Crossing
|
||||||
{
|
{
|
||||||
/** Return value indicating that a crossing was found. */
|
/** Return value indicating that a crossing was found. */
|
||||||
@@ -850,13 +853,9 @@ class Crossing
|
|||||||
return UNKNOWN;
|
return UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** Allowable tolerance for bounds comparison */
|
||||||
* Allowable tolerance for bounds comparison
|
|
||||||
*/
|
|
||||||
protected static final float DELTA = 1E-5f;
|
protected static final float DELTA = 1E-5f;
|
||||||
|
|
||||||
/**
|
/** If roots have distance less then <code>ROOT_DELTA</code> they are double */
|
||||||
* If roots have distance less then <code>ROOT_DELTA</code> they are double
|
|
||||||
*/
|
|
||||||
protected static final float ROOT_DELTA = 1E-10f;
|
protected static final float ROOT_DELTA = 1E-10f;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,88 +6,11 @@ package pythagoras.f;
|
|||||||
|
|
||||||
import java.util.NoSuchElementException;
|
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) {
|
public FlatteningPathIterator (PathIterator path, float flatness) {
|
||||||
this(path, flatness, BUFFER_LIMIT);
|
this(path, flatness, BUFFER_LIMIT);
|
||||||
}
|
}
|
||||||
@@ -119,23 +42,51 @@ public class FlatteningPathIterator implements PathIterator
|
|||||||
return bufLimit;
|
return bufLimit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
// from interface PathIterator
|
||||||
public int getWindingRule () {
|
public int getWindingRule () {
|
||||||
return p.getWindingRule();
|
return p.getWindingRule();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
// from interface PathIterator
|
||||||
public boolean isDone () {
|
public boolean isDone () {
|
||||||
return bufEmpty && p.isDone();
|
return bufEmpty && p.isDone();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* Calculates flat path points for the current segment of the source shape. Line segment is
|
// 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()
|
* 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
|
* 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
|
* 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
|
* 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
|
* extracts one point from the buffer. When a series is completed, evaluate() takes the next
|
||||||
* source shape segment.
|
* source shape segment. */
|
||||||
*/
|
|
||||||
protected void evaluate () {
|
protected void evaluate () {
|
||||||
if (bufEmpty) {
|
if (bufEmpty) {
|
||||||
bufType = p.currentSegment(coords);
|
bufType = p.currentSegment(coords);
|
||||||
@@ -232,25 +183,51 @@ public class FlatteningPathIterator implements PathIterator
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void next () {
|
/** The type of current segment to be flat */
|
||||||
if (bufEmpty) {
|
private int bufType;
|
||||||
p.next();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int currentSegment (float[] coords) {
|
/** The curve subdivision limit */
|
||||||
if (isDone()) {
|
private int bufLimit;
|
||||||
throw new NoSuchElementException("Iterator out of bounds");
|
|
||||||
}
|
/** The current points buffer size */
|
||||||
evaluate();
|
private int bufSize;
|
||||||
int type = bufType;
|
|
||||||
if (type != SEG_CLOSE) {
|
/** The inner cursor position in points buffer */
|
||||||
coords[0] = px;
|
private int bufIndex;
|
||||||
coords[1] = py;
|
|
||||||
if (type != SEG_MOVETO) {
|
/** The current subdivision count */
|
||||||
type = SEG_LINETO;
|
private int bufSubdiv;
|
||||||
}
|
|
||||||
}
|
/** The points buffer */
|
||||||
return type;
|
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;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user