Package pointgon
Class Pointgon
java.lang.Object
pointgon.Pointgon
- All Implemented Interfaces:
Serializable
Class for pointgons (polygons with holes that are points).
- Since:
- 2005.02.18 (Christian Borgelt)
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionPointgon
(int vertcnt, int holecnt) Create a pointgon.Create a random pointgon.Pointgon
(InputStream in) Read a pointgon from an input stream.Read a pointgon from a string description.Pointgon
(util.Scanner s) Read a pointgon from a scanner. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Add an inner edge to the pointgon (triangulation).void
addHole
(double x, double y) Add a hole vertex to a pointgon.void
addVertex
(double x, double y) Add a perimeter vertex to a pointgon.boolean
Check whether all holes are inside the pointgon.boolean
Check for duplicate holes.findEdge
(double x, double y) Find the closest edge to a given point.findVertex
(double x, double y) Find the closest vertex to a given point.double
Get the height of the bounding box.double
getWidth()
Get the width the bounding box.double
getX()
Get the x-coordinate of lower left corner of the bounding box.double
getY()
Get the y-coordinate of lower left corner of the bounding box.boolean
isConvex()
Check whether the pointgon is convex.boolean
isects()
Check for perimieter intersections.boolean
Check whether a vertex is inside the pointgon.boolean
isValid()
Check for a valid state of the pointgon.static void
Main program for command line invocation.void
removeEdge
(Edge edge) Remove an inner edge from the pointgon (triangulation).void
resize
(int vertcnt, int holecnt) Resize a pointgon (change number of vertices).void
reverse()
Reverse (the order of) the perimeter vertices.void
Set the inner edges of the pointgon (triangulation).toString()
Create a string description of the pointgon.void
transform
(double scale, double xoff, double yoff) Scale and shift a pointgon.double
weight
(boolean withPerimeter) Compute the total weight of the edges.
-
Field Details
-
verts
vector of perimeter vertices -
holes
vector of hole vertices -
edges
edges of partition
-
-
Constructor Details
-
Pointgon
public Pointgon(int vertcnt, int holecnt) Create a pointgon.- Parameters:
vertcnt
- the number of perimeter verticesholecnt
- the number of holes- Since:
- 2005.02.18 (Christian Borgelt)
-
Pointgon
Create a random pointgon.- Parameters:
vertcnt
- the number of perimeter verticesholecnt
- the number of holesradius
- the radius parameter (maximum perimeter vertex distance from origin)rand
- the random number generator- Since:
- 2005.02.18 (Christian Borgelt)
-
Pointgon
Read a pointgon from a scanner.- Parameters:
s
- the scanner to read from- Throws:
IOException
- if a read error occcurred- Since:
- 2005.02.18 (Christian Borgelt)
-
Pointgon
Read a pointgon from a string description.- Parameters:
desc
- the string description to read from- Throws:
IOException
- if a read error occcurred- Since:
- 2005.02.18 (Christian Borgelt)
-
Pointgon
Read a pointgon from an input stream.- Parameters:
in
- the input stream to read from- Throws:
IOException
- if a read error occcurred- Since:
- 2005.02.18 (Christian Borgelt)
-
-
Method Details
-
addVertex
public void addVertex(double x, double y) Add a perimeter vertex to a pointgon.- Parameters:
x
- the x-coordinate of the vertexy
- the y-coordinate of the vertex- Since:
- 2005.02.18 (Christian Borgelt)
-
addHole
public void addHole(double x, double y) Add a hole vertex to a pointgon.- Parameters:
x
- the x-coordinate of the hole vertexy
- the y-coordinate of the hole vertex- Since:
- 2005.02.18 (Christian Borgelt)
-
setEdges
Set the inner edges of the pointgon (triangulation).- Parameters:
edges
- the array of edges to set- Since:
- 2005.02.18 (Christian Borgelt)
-
addEdge
Add an inner edge to the pointgon (triangulation).- Parameters:
edge
- the edge to add- Returns:
- whether the edge was added
- Since:
- 2005.02.18 (Christian Borgelt)
-
removeEdge
Remove an inner edge from the pointgon (triangulation).- Parameters:
edge
- the edge to remove- Since:
- 2005.02.18 (Christian Borgelt)
-
resize
public void resize(int vertcnt, int holecnt) Resize a pointgon (change number of vertices).- Parameters:
vertcnt
- the new number of perimeter verticesholecnt
- the new number of holes- Since:
- 2005.02.18 (Christian Borgelt)
-
transform
public void transform(double scale, double xoff, double yoff) Scale and shift a pointgon.- Parameters:
scale
- the scaling parameterxoff
- the x-offset by which to shiftyoff
- the y-offset by which to shift- Since:
- 2005.02.18 (Christian Borgelt)
-
getX
public double getX()Get the x-coordinate of lower left corner of the bounding box.- Returns:
- the x-coordinate of lower left corner of the bounding box
- Since:
- 2005.02.18 (Christian Borgelt)
-
getY
public double getY()Get the y-coordinate of lower left corner of the bounding box.- Returns:
- the y-coordinate of lower left corner of the bounding box
- Since:
- 2005.02.18 (Christian Borgelt)
-
getWidth
public double getWidth()Get the width the bounding box.- Returns:
- the width of the bounding box
- Since:
- 2005.02.18 (Christian Borgelt)
-
getHeight
public double getHeight()Get the height of the bounding box.- Returns:
- the height of the bounding box
- Since:
- 2005.02.18 (Christian Borgelt)
-
reverse
public void reverse()Reverse (the order of) the perimeter vertices.- Since:
- 2005.02.18 (Christian Borgelt)
-
isConvex
public boolean isConvex()Check whether the pointgon is convex.- Returns:
- whether the pointgon is convex
- Since:
- 2005.02.18 (Christian Borgelt)
-
isInside
Check whether a vertex is inside the pointgon.- Parameters:
v
- the vertex to check- Returns:
- whether the vertex is inside the pointgon
- Since:
- 2005.02.18 (Christian Borgelt)
-
allHolesInside
public boolean allHolesInside()Check whether all holes are inside the pointgon.- Returns:
- whether all holes are inside the pointgon
- Since:
- 2005.02.18 (Christian Borgelt)
-
duplicates
public boolean duplicates()Check for duplicate holes.- Returns:
- whether there are duplicate holes
- Since:
- 2005.02.18 (Christian Borgelt)
-
isects
public boolean isects()Check for perimieter intersections.- Returns:
- whether there are perimeter intersections
- Since:
- 2005.02.18 (Christian Borgelt)
-
isValid
public boolean isValid()Check for a valid state of the pointgon.A pointgon is valid if there are no duplicate holes, all holes are inside the pointgon and there are no perimeter intersections.
- Returns:
- whether there are perimeter intersections
- Since:
- 2005.02.18 (Christian Borgelt)
-
weight
public double weight(boolean withPerimeter) Compute the total weight of the edges.- Parameters:
withPerimeter
- whether to include the perimeter edges- Returns:
- the total weight of the edges
- Since:
- 2005.02.18 (Christian Borgelt)
-
findVertex
Find the closest vertex to a given point.- Parameters:
x
- the x-coordinate of the pointy
- the y-coordinate of the point- Returns:
- the closest vertex to the point
- Since:
- 2005.02.18 (Christian Borgelt)
-
findEdge
Find the closest edge to a given point.- Parameters:
x
- the x-coordinate of the pointy
- the y-coordinate of the point- Returns:
- the closest edge to the point
- Since:
- 2005.02.18 (Christian Borgelt)
-
toString
Create a string description of the pointgon. -
main
Main program for command line invocation.- Parameters:
args
- the command line arguments- Since:
- 2005.02.18 (Christian Borgelt)
-