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_vertexjava.util.ArrayList<java.lang.Boolean>segmentsjava.util.ArrayList<org.jogamp.vecmath.Point2f>vertices -
Constructor Summary
-
Method Summary
Modifier and Type Method Description voidaddVertex(org.jogamp.vecmath.Point2f p)Adds a vertex.voidaddVertex(org.jogamp.vecmath.Point2f p, boolean include_segment)Adds a vertex.voidaddVertex(org.jogamp.vecmath.Point2f p, boolean include_segment, boolean render_vertex)Adds a vertex.java.lang.Objectclone()booleancontains(org.jogamp.vecmath.Point2f pt)static org.jogamp.vecmath.Point2fgetCenterOfGravity(Polygon2D thisPoly)org.jogamp.vecmath.Point2fgetCenterPt()float[]getCoords()Returns the coordinates of this shape as an array of length2*n.org.jogamp.vecmath.Point2fgetFirstVertex()org.jogamp.vecmath.Point2fgetLastVertex()org.jogamp.vecmath.Point2fgetNextVertex(int i)org.jogamp.vecmath.Point2fgetPrevVertex(int i)floatgetProximity(org.jogamp.vecmath.Point2f thisPt)org.jogamp.vecmath.Point2fgetProximityPoint(org.jogamp.vecmath.Point2f thisPt)intgetSize()Returns the number of vertices in this shape.org.jogamp.vecmath.Point2fgetVertex(int i)java.util.ArrayList<org.jogamp.vecmath.Point2f>getVertices()voidhandleXMLElementEnd(java.lang.String localName)Handles the end of an XML element.voidhandleXMLElementStart(java.lang.String localName, org.xml.sax.Attributes attributes, XMLObject.XMLType type)Handles the start of an XML element.voidhandleXMLString(java.lang.String s)Handles a string within an XML element.voidremoveVertex(int idx)Removes the vertex at idxvoidsetCoords(float[] coords)Sets the coordinates of this shape fromcoords.voidsetRenderVertices(java.util.ArrayList<java.lang.Boolean> render)voidsetVertices(java.util.ArrayList<org.jogamp.vecmath.Point2f> vertices)voidwriteXML(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, writeXMLMethods 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:Shape2DReturns 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:Shape2DSets 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:
getCenterPtin 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:Shape2DReturns 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.includedetermines 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.includedetermines 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:
getProximityPointin classShape2D
-
getVertices
public java.util.ArrayList<org.jogamp.vecmath.Point2f> getVertices()- Specified by:
getVerticesin classShape2D
-
setVertices
public void setVertices(java.util.ArrayList<org.jogamp.vecmath.Point2f> vertices)- Specified by:
setVerticesin classShape2D
-
getProximity
public float getProximity(org.jogamp.vecmath.Point2f thisPt)- Overrides:
getProximityin 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:XMLObjectHandles the end of an XML element.- Specified by:
handleXMLElementEndin interfaceXMLObject- Overrides:
handleXMLElementEndin 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:XMLObjectHandles the start of an XML element.- Specified by:
handleXMLElementStartin interfaceXMLObject- Overrides:
handleXMLElementStartin classShape2D- Parameters:
localName- Local name of the elementattributes- Set of element attributestype- TheXMLTypeof this element
-
handleXMLString
public void handleXMLString(java.lang.String s)Description copied from interface:XMLObjectHandles a string within an XML element.- Specified by:
handleXMLStringin interfaceXMLObject- Overrides:
handleXMLStringin classShape2D- Parameters:
s- String to handle
-