Package com.treemap.swing.originalfastvoronoi.j2d

# Class PolygonSimple

java.lang.Object
com.treemap.swing.originalfastvoronoi.j2d.PolygonSimple

All Implemented Interfaces:
  `com.macrofocus.geom.Shape`, `Cloneable`

public class PolygonSimple extends Object implements com.macrofocus.geom.Shape, Cloneable
Implements a simple polygon with one continous region, by using two double arrays.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected double`
  `area`
  `protected com.macrofocus.geom.Rectangle2D.Double`
  `bounds`
  `protected Point2D`
  `centroid`
  centroid of the polygon is stored for faster access, once it is computed
  `int`
  `length`
  y-coordinates
  `protected PolygonSimple`
  `oldPolygon`
  Stores the orginal polygon result, without shrinking
  `protected Random`
  `seed`
  Used for generation of a random point in a polygon.
  `protected double[]`
  `x`
  `protected double[]`
  `y`
  x-coordinates

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `PolygonSimple()`
  `PolygonSimple(double[] xPoints, double[] yPoints)`
  `PolygonSimple(double[] xPoints, double[] yPoints, int length)`
  `PolygonSimple(int numberPoints)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `add(double x, double y)`
  Adds a point to the polygon.
  `void`
  `add(Point2D p)`
  `add(double, double)`
  `PolygonSimple`
  `clone()`
  `boolean`
  `contains(double inX, double inY)`
  tests whether the given point is contained in the polygon (linear time).
  `boolean`
  `contains(double x, double y, double w, double h)`
  tests whether each corner point of the given rectangle is contained in the polygon.
  `boolean`
  `contains(com.macrofocus.geom.Point2D p)`
  `boolean`
  `contains(Point2D p)`
  `contains(double, double)`
  `PolygonSimple`
  `convexClip(PolygonSimple poly)`
  Uses the linear time algorithm of O'Rourke to compute the intersection of two convex polygons.
  `double`
  `getArea()`
  Returns the area of the polygon.
  `com.macrofocus.geom.Rectangle2D`
  `getBounds2D()`
  Returns the bounding rectangle of this polygon.
  `Point2D`
  `getCentroid()`
  Computes the centroid of a polygon.
  `com.macrofocus.geom.PathIterator`
  `getFlattenPathIterator(double flatness)`
  `Point2D`
  `getInnerPoint()`
  Returns a random point in the polygon.
  `Point2D`
  `getIntersectionWithPolygon(Double inx, Double iny, Double outx, Double outy)`
  Computes the intersection point iff (inx,iny) is within the polygon and (outx,outy) is outside of the polygon.
  `double`
  `getMinDistanceToBorder(double x, double y)`
  For the given point, the minimal distance to the segments of the polygon is computed.
  `int`
  `getNumPoints()`
  Return the number of points in this polygon.
  `PolygonSimple`
  `getOriginalPolygon()`
  If the polygon is modified by e.g.
  `com.macrofocus.geom.PathIterator`
  `getPathIterator()`
  `com.macrofocus.geom.PathIterator`
  `getPathIterator(com.macrofocus.geom.AffineTransform at)`
  Returns the path iterator for the shape(rather slow compared to using the point arrays directly).
  `com.macrofocus.geom.PathIterator`
  `getPathIterator(com.macrofocus.geom.AffineTransform at, double flatness)`
  `getPathIterator(AffineTransform)`
  `Point2D`
  `getRelativePosition(Point2D vector)`
  We get a vector which describes where the point should be relative to the center.
  `double[]`
  `getXPoints()`
  Array with x-values of the polygon points.
  `double[]`
  `getYPoints()`
  Array with y-values of the polygon points.
  `boolean`
  `intersects(com.macrofocus.geom.Rectangle2D r)`
  tests whether the given rectangle will intersect to the bounds of the polygon.
  `void`
  `PolygonSimple(PolygonSimple simple)`
  Replaces the pointers of the coordinate arrays to show to the given coordinate arrays.
  `void`
  `scale(double scalingFactor)`
  Scales all points by multiplying with the scalingFactor
  `void`
  `shrinkForBorder(double percentage)`
  Default percentage can be 0.96
  `String`
  `toString()`
  `void`
  `translate(double tx, double ty)`
  Translates all points of the polygon by adding the values

  ### Methods inherited from class java.lang.Object

  `equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

  ### Methods inherited from interface com.macrofocus.geom.Shape

  `getBounds`

- ## Field Details

  - ### seed

    protected Random seed
    Used for generation of a random point in a polygon.

  - ### centroid

    protected Point2D centroid
    centroid of the polygon is stored for faster access, once it is computed

  - ### area

    protected double area

  - ### bounds

    protected com.macrofocus.geom.Rectangle2D.Double bounds

  - ### oldPolygon

    protected PolygonSimple oldPolygon
    Stores the orginal polygon result, without shrinking

  - ### x

    protected double[] x

  - ### y

    protected double[] y
    x-coordinates

  - ### length

    public int length
    y-coordinates

- ## Constructor Details

  - ### PolygonSimple

    public PolygonSimple()

  - ### PolygonSimple

    public PolygonSimple(int numberPoints)
    Parameters:
      `numberPoints` - initial array size, default initial array size is 16.

  - ### PolygonSimple

    public PolygonSimple(double[] xPoints, double[] yPoints, int length)
    Parameters:
      `xPoints` - x-coordinate of the polygon points
      `yPoints` - y-coordinate of the polygon points
      `length` - number of elements which should be considered from the given arrays

  - ### PolygonSimple

    public PolygonSimple(double[] xPoints, double[] yPoints)
    Parameters:
      `xPoints` - x-coordinate of the polygon points
      `yPoints` - y-coordinate of the polygon points

- ## Method Details

  - ### PolygonSimple

    public void PolygonSimple(PolygonSimple simple)
    Replaces the pointers of the coordinate arrays to show to the given coordinate arrays.

  - ### contains

    public boolean contains(double inX, double inY)
    tests whether the given point is contained in the polygon (linear time).

  - ### contains

    public boolean contains(Point2D p)
    `contains(double, double)`

  - ### contains

    public boolean contains(com.macrofocus.geom.Point2D p)
    Specified by:
      `contains` in interface `com.macrofocus.geom.Shape`

  - ### contains

    public boolean contains(double x, double y, double w, double h)
    tests whether each corner point of the given rectangle is contained in the polygon.

  - ### getPathIterator

    public com.macrofocus.geom.PathIterator getPathIterator(com.macrofocus.geom.AffineTransform at)
    Returns the path iterator for the shape(rather slow compared to using the point arrays directly).
    Specified by:
      `getPathIterator` in interface `com.macrofocus.geom.Shape`

  - ### getPathIterator

    public com.macrofocus.geom.PathIterator getPathIterator()
    Specified by:
      `getPathIterator` in interface `com.macrofocus.geom.Shape`

  - ### getFlattenPathIterator

    public com.macrofocus.geom.PathIterator getFlattenPathIterator(double flatness)
    Specified by:
      `getFlattenPathIterator` in interface `com.macrofocus.geom.Shape`

  - ### getPathIterator

    public com.macrofocus.geom.PathIterator getPathIterator(com.macrofocus.geom.AffineTransform at, double flatness)
    `getPathIterator(AffineTransform)`

  - ### intersects

    public boolean intersects(com.macrofocus.geom.Rectangle2D r)
    tests whether the given rectangle will intersect to the bounds of the polygon.
    Specified by:
      `intersects` in interface `com.macrofocus.geom.Shape`

  - ### getBounds2D

    public com.macrofocus.geom.Rectangle2D getBounds2D()
    Returns the bounding rectangle of this polygon.
    Specified by:
      `getBounds2D` in interface `com.macrofocus.geom.Shape`

  - ### getNumPoints

    public int getNumPoints()
    Return the number of points in this polygon.
    Returns:
      integer number of points

  - ### add

    public void add(double x, double y)
    Adds a point to the polygon. Extends the corresponding array if necessary.

  - ### scale

    public void scale(double scalingFactor)
    Scales all points by multiplying with the scalingFactor
    Parameters:
      `scalingFactor` -

  - ### translate

    public void translate(double tx, double ty)
    Translates all points of the polygon by adding the values
    Parameters:
      `tx` - translation on x
      `ty` - translation on y

  - ### add

    public void add(Point2D p)
    `add(double, double)`

  - ### convexClip

    public PolygonSimple convexClip(PolygonSimple poly)
    Uses the linear time algorithm of O'Rourke to compute the intersection of two convex polygons.
    Parameters:
      `poly` -
    Returns:

  - ### getArea

    public double getArea()
    Returns the area of the polygon.

  - ### getMinDistanceToBorder

    public double getMinDistanceToBorder(double x, double y)
    For the given point, the minimal distance to the segments of the polygon is computed.
    Parameters:
      `x` -
      `y` -
    Returns:

  - ### getCentroid

    public Point2D getCentroid()
    Computes the centroid of a polygon.
    Returns:
      centroid point

  - ### clone

    public PolygonSimple clone()
    Overrides:
      `clone` in class `Object`

  - ### shrinkForBorder

    public void shrinkForBorder(double percentage)
    Default percentage can be 0.96
    Parameters:
      `percentage` -

  - ### getRelativePosition

    public Point2D getRelativePosition(Point2D vector)
    We get a vector which describes where the point should be relative to the center. We change the length of the vector so that the point fits in the polygon. (reimplementation needed here)
    Returns:
      Point which is contained by this polygon and has same direction as the given vector point

  - ### getInnerPoint

    public Point2D getInnerPoint()
    Returns a random point in the polygon.
    Returns:

  - ### getIntersectionWithPolygon

    public Point2D getIntersectionWithPolygon(Double inx, Double iny, Double outx, Double outy)
    Computes the intersection point iff (inx,iny) is within the polygon and (outx,outy) is outside of the polygon. Returns null if the is no intersection or the line crosses the complete polygon.
    Parameters:
      `inx` - x-coordinate of the presumably inner point
      `iny` - y-coordiante of the presumably inner point
      `outx` - x-coordinate of the presumably outer point
      `outy` - y-coordinate of the presumably outer point
    Returns:
      Intersection Point

  - ### getXPoints

    public double[] getXPoints()
    Array with x-values of the polygon points.
    Returns:

  - ### getYPoints

    public double[] getYPoints()
    Array with y-values of the polygon points.
    Returns:

  - ### getOriginalPolygon

    public PolygonSimple getOriginalPolygon()
    If the polygon is modified by e.g. shrinking, this method returns the original polygon. If the polyogn was not modified, it can return null.
    Returns:

  - ### toString

    public String toString()
    Overrides:
      `toString` in class `Object`