public class PolygonUtils extends Object
PolygonUtils
is a Java version of the General Polygon Clipper
algorithm developed by Alan Murta (gpc@cs.man.ac.uk). The home page for the
original source can be found at
http://www.cs.man.ac.uk/aig/staff/alan/software/.
polyClass:
Some of the public methods below take a
polyClass
argument. This java.lang.Class
object is
assumed to implement the Polygon
interface and have a no
argument constructor. This was done so that the user of the algorithm could
create their own classes that implement the Polygon
interface
and still uses this algorithm.
Implementation Note: The converted algorithm does support the difference operation, but a public method has not been provided and it has not been tested. To do so, simply follow what has been done for intersection.
Modifier and Type | Field and Description |
---|---|
static int |
ABOVE
ABOVE
|
static int |
BELOW
BELOW
|
static int |
CLIP
CLIP
|
static int |
LEFT
LEFT
|
static int |
RIGHT
RIGHT
|
static int |
SUBJ
SUBJ
|
Constructor and Description |
---|
PolygonUtils()
Creates a new instance of PolygonUtils
|
Modifier and Type | Method and Description |
---|---|
Polygon |
intersection(Polygon p1,
Polygon p2)
Return the intersection of
p1 and p2 where the
return type is of PolyDefault . |
Polygon |
intersection(Polygon p1,
Polygon p2,
Class<Polygon> polyClass)
Return the intersection of
p1 and p2 where the
return type is of polyClass . |
static int |
NEXT_INDEX(int i,
int n) |
static int |
PREV_INDEX(int i,
int n) |
Polygon |
union(Polygon p1,
Polygon p2)
Return the union of
p1 and p2 where the return
type is of PolyDefault . |
Polygon |
union(Polygon p1,
Polygon p2,
Class<Polygon> polyClass)
Return the union of
p1 and p2 where the return
type is of polyClass . |
Polygon |
xor(Polygon p1,
Polygon p2)
Return the xor of
p1 and p2 where the return
type is of PolyDefault . |
Polygon |
xor(Polygon p1,
Polygon p2,
Class<Polygon> polyClass)
Return the xor of
p1 and p2 where the return
type is of polyClass . |
public static final int LEFT
public static final int RIGHT
public static final int ABOVE
public static final int BELOW
public static final int CLIP
public static final int SUBJ
public PolygonUtils()
public Polygon intersection(Polygon p1, Polygon p2, Class<Polygon> polyClass)
p1
and p2
where the
return type is of polyClass
. See the note in the class
description for more on p1
- One of the polygons to perform the intersection withp2
- One of the polygons to perform the intersection withpolyClass
- The type of Polygon
to returnpublic Polygon union(Polygon p1, Polygon p2, Class<Polygon> polyClass)
p1
and p2
where the return
type is of polyClass
. See the note in the class description
for more on p1
- One of the polygons to perform the union withp2
- One of the polygons to perform the union withpolyClass
- The type of Polygon
to returnpublic Polygon xor(Polygon p1, Polygon p2, Class<Polygon> polyClass)
p1
and p2
where the return
type is of polyClass
. See the note in the class description
for more on polyClass
.p1
- One of the polygons to perform the xor withp2
- One of the polygons to perform the xor withpolyClass
- The type of Polygon
to returnpublic Polygon intersection(Polygon p1, Polygon p2)
p1
and p2
where the
return type is of PolyDefault
.p1
- One of the polygons to perform the intersection withp2
- One of the polygons to perform the intersection withpublic Polygon union(Polygon p1, Polygon p2)
p1
and p2
where the return
type is of PolyDefault
.p1
- One of the polygons to performt he union withp2
- One of the polygons to performt he union withpublic Polygon xor(Polygon p1, Polygon p2)
p1
and p2
where the return
type is of PolyDefault
.p1
- One of the polygons to perform the xor withp2
- One of the polygons to perform the xor withpublic static int PREV_INDEX(int i, int n)
i
- n
- public static int NEXT_INDEX(int i, int n)
i
- n
-