Package mgui.geometry
Class Polygon2D
java.lang.Object
mgui.geometry.Shape2D
mgui.geometry.Polygon2D
public class Polygon2D extends Shape2D
Represents a series of connected 2D points, defining either a polyline
or a closed polygon.
- Since:
- 1.0
- Version:
- 1.0
- Author:
- Andrew Reid
-
Nested Class Summary
Nested classes/interfaces inherited from interface mgui.interfaces.xml.XMLObject
XMLObject.XMLEncoding, XMLObject.XMLType
-
Field Summary
Fields Modifier and Type Field Description java.util.ArrayList<java.lang.Boolean>
render_vertex
java.util.ArrayList<java.lang.Boolean>
segments
java.util.ArrayList<org.jogamp.vecmath.Point2f>
vertices
-
Constructor Summary
-
Method Summary
Modifier and Type Method Description void
addVertex(org.jogamp.vecmath.Point2f p)
Adds a vertex.void
addVertex(org.jogamp.vecmath.Point2f p, boolean include_segment)
Adds a vertex.void
addVertex(org.jogamp.vecmath.Point2f p, boolean include_segment, boolean render_vertex)
Adds a vertex.java.lang.Object
clone()
boolean
contains(org.jogamp.vecmath.Point2f pt)
static org.jogamp.vecmath.Point2f
getCenterOfGravity(Polygon2D thisPoly)
org.jogamp.vecmath.Point2f
getCenterPt()
float[]
getCoords()
Returns the coordinates of this shape as an array of length2*n
.org.jogamp.vecmath.Point2f
getFirstVertex()
org.jogamp.vecmath.Point2f
getLastVertex()
org.jogamp.vecmath.Point2f
getNextVertex(int i)
org.jogamp.vecmath.Point2f
getPrevVertex(int i)
float
getProximity(org.jogamp.vecmath.Point2f thisPt)
org.jogamp.vecmath.Point2f
getProximityPoint(org.jogamp.vecmath.Point2f thisPt)
int
getSize()
Returns the number of vertices in this shape.org.jogamp.vecmath.Point2f
getVertex(int i)
java.util.ArrayList<org.jogamp.vecmath.Point2f>
getVertices()
void
handleXMLElementEnd(java.lang.String localName)
Handles the end of an XML element.void
handleXMLElementStart(java.lang.String localName, org.xml.sax.Attributes attributes, XMLObject.XMLType type)
Handles the start of an XML element.void
handleXMLString(java.lang.String s)
Handles a string within an XML element.void
removeVertex(int idx)
Removes the vertex at idxvoid
setCoords(float[] coords)
Sets the coordinates of this shape fromcoords
.void
setRenderVertices(java.util.ArrayList<java.lang.Boolean> render)
void
setVertices(java.util.ArrayList<org.jogamp.vecmath.Point2f> vertices)
void
writeXML(int tab, java.io.Writer writer, InterfaceProgressBar progress_bar)
Methods inherited from class mgui.geometry.Shape2D
getBounds, getDTD, getLocalName, getShortXML, getVertices, getXML, getXML, getXMLSchema, setVertices, transform, transform, writeXML, writeXML, writeXML
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Field Details
-
vertices
public java.util.ArrayList<org.jogamp.vecmath.Point2f> vertices -
segments
public java.util.ArrayList<java.lang.Boolean> segments -
render_vertex
public java.util.ArrayList<java.lang.Boolean> render_vertex
-
-
Constructor Details
-
Polygon2D
public Polygon2D() -
Polygon2D
public Polygon2D(java.util.ArrayList<org.jogamp.vecmath.Point2f> nodeList) -
Polygon2D
public Polygon2D(java.util.ArrayList<org.jogamp.vecmath.Point2f> vertices, java.util.ArrayList<java.lang.Boolean> segments)
-
-
Method Details
-
setRenderVertices
public void setRenderVertices(java.util.ArrayList<java.lang.Boolean> render) -
getCoords
public float[] getCoords()Description copied from class:Shape2D
Returns the coordinates of this shape as an array of length2*n
. Every two sequential elements in the array represents a coordinate.All shape classes which implement coordinates must implement this method.
-
setCoords
public void setCoords(float[] coords)Description copied from class:Shape2D
Sets the coordinates of this shape fromcoords
. Every two sequential elements in the array represents a coordinate.All shape classes which implement coordinates must implement this method.
-
getCenterPt
public org.jogamp.vecmath.Point2f getCenterPt()- Overrides:
getCenterPt
in classShape2D
-
getVertex
public org.jogamp.vecmath.Point2f getVertex(int i) -
getNextVertex
public org.jogamp.vecmath.Point2f getNextVertex(int i) -
getSize
public int getSize()Description copied from class:Shape2D
Returns the number of vertices in this shape. Subclasses can provide more efficient implementations. -
getPrevVertex
public org.jogamp.vecmath.Point2f getPrevVertex(int i) -
getFirstVertex
public org.jogamp.vecmath.Point2f getFirstVertex() -
getLastVertex
public org.jogamp.vecmath.Point2f getLastVertex() -
addVertex
public void addVertex(org.jogamp.vecmath.Point2f p)Adds a vertex.- Parameters:
p
-include
-
-
addVertex
public void addVertex(org.jogamp.vecmath.Point2f p, boolean include_segment)Adds a vertex.include
determines whether the segment i-1, i is included in this polygon- Parameters:
p
-include_segment
- Whether to include the previous segment
-
addVertex
public void addVertex(org.jogamp.vecmath.Point2f p, boolean include_segment, boolean render_vertex)Adds a vertex.include
determines whether the segment i-1, i is included in this polygon- Parameters:
p
-include_segment
- Whether to include the previous segmentrender_vertex
- Whether this vertex should be rendered
-
removeVertex
public void removeVertex(int idx)Removes the vertex at idx- Parameters:
idx
-
-
contains
public boolean contains(org.jogamp.vecmath.Point2f pt) -
getCenterOfGravity
- Parameters:
thisPoly
-- Returns:
- a Point2f object that is the center of gravity for this polygon
-
clone
public java.lang.Object clone() -
getProximityPoint
public org.jogamp.vecmath.Point2f getProximityPoint(org.jogamp.vecmath.Point2f thisPt)- Overrides:
getProximityPoint
in classShape2D
-
getVertices
public java.util.ArrayList<org.jogamp.vecmath.Point2f> getVertices()- Specified by:
getVertices
in classShape2D
-
setVertices
public void setVertices(java.util.ArrayList<org.jogamp.vecmath.Point2f> vertices)- Specified by:
setVertices
in classShape2D
-
getProximity
public float getProximity(org.jogamp.vecmath.Point2f thisPt)- Overrides:
getProximity
in classShape2D
-
writeXML
public void writeXML(int tab, java.io.Writer writer, InterfaceProgressBar progress_bar) throws java.io.IOException- Throws:
java.io.IOException
-
handleXMLElementEnd
public void handleXMLElementEnd(java.lang.String localName)Description copied from interface:XMLObject
Handles the end of an XML element.- Specified by:
handleXMLElementEnd
in interfaceXMLObject
- Overrides:
handleXMLElementEnd
in classShape2D
- Parameters:
localName
- Local name of the element
-
handleXMLElementStart
public void handleXMLElementStart(java.lang.String localName, org.xml.sax.Attributes attributes, XMLObject.XMLType type)Description copied from interface:XMLObject
Handles the start of an XML element.- Specified by:
handleXMLElementStart
in interfaceXMLObject
- Overrides:
handleXMLElementStart
in classShape2D
- Parameters:
localName
- Local name of the elementattributes
- Set of element attributestype
- TheXMLType
of this element
-
handleXMLString
public void handleXMLString(java.lang.String s)Description copied from interface:XMLObject
Handles a string within an XML element.- Specified by:
handleXMLString
in interfaceXMLObject
- Overrides:
handleXMLString
in classShape2D
- Parameters:
s
- String to handle
-