net.refractions.udig.tools.edit.support
Class PrimitiveShape

java.lang.Object
  extended by net.refractions.udig.tools.edit.support.PrimitiveShape
All Implemented Interfaces:
java.awt.Shape, java.lang.Iterable<Point>

public class PrimitiveShape
extends java.lang.Object
implements java.lang.Iterable<Point>, java.awt.Shape

Represents the simplest shape. GeomShapes are made up of PrimitiveShapes.

This is not a composite pattern.

Since:
1.1.0
Author:
jones

Constructor Summary
PrimitiveShape(EditGeom owner)
           
PrimitiveShape(PrimitiveShape shape)
           
 
Method Summary
 void assertValid()
           
 boolean contains(double x, double y)
           
 boolean contains(double x, double y, double w, double h)
           
 boolean contains(java.awt.geom.Point2D p)
           
 boolean contains(Point point, boolean treatUnknownGeomsAsPolygon)
          Returns true if the point is contained in the shape or on the edge.
 boolean contains(Point point, boolean treatUnknownGeomsAsPolygon, boolean ignoreVertexRadius)
          Returns true if the point is contained in the shape or on the edge.
 boolean contains(java.awt.geom.Rectangle2D r)
           
 Coordinate[] coordArray()
          Returns an array with all the coordinates in shape.
 java.util.Iterator<Coordinate> coordIterator()
           
 int getAssociatedPointIndex(int coordIndex)
           
 java.awt.Rectangle getBounds()
          Returns the bounding box of the Shape in pixel space.
 java.awt.geom.Rectangle2D getBounds2D()
           
 ClosestEdge getClosestEdge(Point click, boolean treatUnknownAsPolygon)
          Returns a ClosestEdge object that has information about the point that closest to the click paramter and is on an edge of the part.
 Coordinate getCoord(int i)
           
 java.util.List<Coordinate> getCoordsAt(int i)
          Returns all the coordinates that map to the point at location i.
 java.util.List<Coordinate> getCoordsAt(Point point)
           
 EditBlackboard getEditBlackboard()
           
 EditGeom getEditGeom()
           
 Envelope getEnvelope()
           
 int getNumCoords()
           
 int getNumPoints()
           
 java.awt.geom.PathIterator getPathIterator(java.awt.geom.AffineTransform at)
           
 java.awt.geom.PathIterator getPathIterator(java.awt.geom.AffineTransform at, double flatness)
           
 Point getPoint(int i)
           
 boolean hasVertex(Point p)
          returns true if the point is contained in this shape.
 boolean intersects(double x, double y, double w, double h)
           
 boolean intersects(java.awt.geom.Rectangle2D r)
           
 java.util.Iterator<Point> iterator()
           
 boolean overlap(PrimitiveShape shape2, boolean treatUnknownAsPolygon, boolean acceptTouches)
          Currently a simple stupid implementation for detecting if 2 polygons overlap.
 Point overVertex(Point location, int radius)
          Returns the point closest to location.
 Point overVertex(Point location, int radius, boolean ignore)
          Returns the point closest to location.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PrimitiveShape

public PrimitiveShape(EditGeom owner)

PrimitiveShape

public PrimitiveShape(PrimitiveShape shape)
Method Detail

getNumPoints

public int getNumPoints()

getPoint

public Point getPoint(int i)

getNumCoords

public int getNumCoords()

getCoord

public Coordinate getCoord(int i)

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getEditGeom

public EditGeom getEditGeom()
Returns:
Returns the owner.

getEditBlackboard

public EditBlackboard getEditBlackboard()

iterator

public java.util.Iterator<Point> iterator()
Specified by:
iterator in interface java.lang.Iterable<Point>
Returns:
Returns an iterator that iterates over all visible points in shape. Not modifyable

coordIterator

public java.util.Iterator<Coordinate> coordIterator()
Returns:
Returns an iterator that iterates over all visible coordinates in shape. Not modifyible

coordArray

public Coordinate[] coordArray()
Returns an array with all the coordinates in shape.

Returns:
an array with all the coordinates in shape.

hasVertex

public boolean hasVertex(Point p)
returns true if the point is contained in this shape.

Parameters:
p - an arbitrary point
Returns:
Returns true if the point is contained in this shape.

getClosestEdge

public ClosestEdge getClosestEdge(Point click,
                                  boolean treatUnknownAsPolygon)
Returns a ClosestEdge object that has information about the point that closest to the click paramter and is on an edge of the part.

Parameters:
click - the point to use as the reference point
Returns:

getBounds

public java.awt.Rectangle getBounds()
Returns the bounding box of the Shape in pixel space.

Specified by:
getBounds in interface java.awt.Shape
Returns:
the bounding box of the Shape in pixel space.

contains

public boolean contains(Point point,
                        boolean treatUnknownGeomsAsPolygon)
Returns true if the point is contained in the shape or on the edge. It is considered on the edge if it is within PreferenceUtil.getVertexRadius() of the edge.

Parameters:
point - An astrbitrary point
treatUnknownGeomsAsPolygon - if EditGeom.getShapeType() return UNKOWN this parameter is used to determine if this shape should be considered a polygon.
Returns:
true if the point is contained in the shape.

contains

public boolean contains(Point point,
                        boolean treatUnknownGeomsAsPolygon,
                        boolean ignoreVertexRadius)
Returns true if the point is contained in the shape or on the edge.

Parameters:
point - An astrbitrary point
treatUnknownGeomsAsPolygon - if EditGeom.getShapeType() return UNKOWN this parameter is used to determine if this shape should be considered a polygon.
ignoreVertexRadius - if true then the point is only considered to be on the edge if it is directly on the edge. (within 1 pixel of the line).
Returns:
true if the point is contained in the shape.

getBounds2D

public java.awt.geom.Rectangle2D getBounds2D()
Specified by:
getBounds2D in interface java.awt.Shape

contains

public boolean contains(double x,
                        double y)
Specified by:
contains in interface java.awt.Shape

contains

public boolean contains(java.awt.geom.Point2D p)
Specified by:
contains in interface java.awt.Shape

intersects

public boolean intersects(double x,
                          double y,
                          double w,
                          double h)
Specified by:
intersects in interface java.awt.Shape

intersects

public boolean intersects(java.awt.geom.Rectangle2D r)
Specified by:
intersects in interface java.awt.Shape

contains

public boolean contains(double x,
                        double y,
                        double w,
                        double h)
Specified by:
contains in interface java.awt.Shape

contains

public boolean contains(java.awt.geom.Rectangle2D r)
Specified by:
contains in interface java.awt.Shape

getPathIterator

public java.awt.geom.PathIterator getPathIterator(java.awt.geom.AffineTransform at)
Specified by:
getPathIterator in interface java.awt.Shape

getPathIterator

public java.awt.geom.PathIterator getPathIterator(java.awt.geom.AffineTransform at,
                                                  double flatness)
Specified by:
getPathIterator in interface java.awt.Shape

getCoordsAt

public java.util.List<Coordinate> getCoordsAt(int i)
Returns all the coordinates that map to the point at location i.

Parameters:
i - index of a point in the shape
Returns:
Returns all the coordinates that map to the point at location i.

getCoordsAt

public java.util.List<Coordinate> getCoordsAt(Point point)

getAssociatedPointIndex

public int getAssociatedPointIndex(int coordIndex)

assertValid

public void assertValid()

overVertex

public Point overVertex(Point location,
                        int radius)
Returns the point closest to location. The search is a square of height and width radius + 1.

Parameters:
location - the locations to start searching from.
radius - the distance away from location to search.
Returns:
the point closest to location or null if no point exists.

overVertex

public Point overVertex(Point location,
                        int radius,
                        boolean ignore)
Returns the point closest to location. If ignore is true the point at locations will not be returned. The search is a square of height and width radius + 1.

Parameters:
location - the locations to start searching from.
radius - radius the distance away from location to search.
ignore - true if the vertex at location is ignored
Returns:
the point closest to location or null if no point exists.

getEnvelope

public Envelope getEnvelope()

overlap

public boolean overlap(PrimitiveShape shape2,
                       boolean treatUnknownAsPolygon,
                       boolean acceptTouches)
Currently a simple stupid implementation for detecting if 2 polygons overlap. Currently it only check the points not the real coordinates so this method must be used with care. Just iterates through all the edges in one shape and checks if it overlap with an edge in the other shape.
  ------------------
  |   ---------    |
  |   |       |    |
  ----|-------|-----
      |       |
      ---------
 
Above is considered overlapping but below is only if acceptTouches is true:
  ------------------
  |                |
  |                |
  ------------------
      |       |
      ---------
 

Note: If one of the shapes is a point and the other is a line or a point then acceptTouches must be true other or this method will always return false.

Parameters:
shape2 - other shape to test against
acceptTouches - if true then this method will return true if the two shapes simply touch (but don't fully overlap). See above for more details
Returns:
true if the two shapes overlap