Package mgui.geometry

Class Polygon2D

java.lang.Object
mgui.geometry.Shape2D
mgui.geometry.Polygon2D
All Implemented Interfaces:
java.lang.Cloneable, Shape, XMLObject

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
  • 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 length 2*n. Every two sequential elements in the array represents a coordinate.

      All shape classes which implement coordinates must implement this method.

      Specified by:
      getCoords in interface Shape
      Overrides:
      getCoords in class Shape2D
    • setCoords

      public void setCoords​(float[] coords)
      Description copied from class: Shape2D
      Sets the coordinates of this shape from coords. Every two sequential elements in the array represents a coordinate.

      All shape classes which implement coordinates must implement this method.

      Specified by:
      setCoords in interface Shape
      Overrides:
      setCoords in class Shape2D
      Parameters:
      coords - An array of length 2*n
    • getCenterPt

      public org.jogamp.vecmath.Point2f getCenterPt()
      Overrides:
      getCenterPt in class Shape2D
    • getVertex

      public org.jogamp.vecmath.Point2f getVertex​(int i)
      Specified by:
      getVertex in class Shape2D
    • 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.
      Specified by:
      getSize in interface Shape
      Overrides:
      getSize in class Shape2D
      Returns:
      the number of vertices
    • 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 segment
      render_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)
      Overrides:
      contains in class Shape2D
    • getCenterOfGravity

      public static org.jogamp.vecmath.Point2f getCenterOfGravity​(Polygon2D thisPoly)
      Parameters:
      thisPoly -
      Returns:
      a Point2f object that is the center of gravity for this polygon
    • clone

      public java.lang.Object clone()
      Overrides:
      clone in class Shape2D
    • getProximityPoint

      public org.jogamp.vecmath.Point2f getProximityPoint​(org.jogamp.vecmath.Point2f thisPt)
      Overrides:
      getProximityPoint in class Shape2D
    • getVertices

      public java.util.ArrayList<org.jogamp.vecmath.Point2f> getVertices()
      Specified by:
      getVertices in class Shape2D
    • setVertices

      public void setVertices​(java.util.ArrayList<org.jogamp.vecmath.Point2f> vertices)
      Specified by:
      setVertices in class Shape2D
    • getProximity

      public float getProximity​(org.jogamp.vecmath.Point2f thisPt)
      Overrides:
      getProximity in class Shape2D
    • 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 interface XMLObject
      Overrides:
      handleXMLElementEnd in class Shape2D
      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 interface XMLObject
      Overrides:
      handleXMLElementStart in class Shape2D
      Parameters:
      localName - Local name of the element
      attributes - Set of element attributes
      type - The XMLType 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 interface XMLObject
      Overrides:
      handleXMLString in class Shape2D
      Parameters:
      s - String to handle