math.geom2d
Class ShapeArray2D<T extends Shape2D>

java.lang.Object
  extended by math.geom2d.ShapeArray2D<T>
All Implemented Interfaces:
java.lang.Cloneable, java.lang.Iterable<T>, GeometricObject2D, Shape2D, ShapeSet2D<T>
Direct Known Subclasses:
DomainArray2D

public class ShapeArray2D<T extends Shape2D>
extends java.lang.Object
implements ShapeSet2D<T>, java.lang.Cloneable

Default Implementation of ShapeSet2D.

Author:
dlegland

Field Summary
 
Fields inherited from interface math.geom2d.Shape2D
ACCURACY
 
Constructor Summary
ShapeArray2D()
           
ShapeArray2D(java.util.Collection<? extends T> shapes)
           
ShapeArray2D(int n)
           
ShapeArray2D(T[] shapes)
           
 
Method Summary
 void add(int index, T shape)
          Inserts the specified shape at the specified position in this set (optional operation).
 boolean add(T shape)
          Adds the shape to the shape set, if it does not already belongs to the set.
 boolean almostEquals(GeometricObject2D obj, double eps)
          Checks if the two objects are similar up to a given threshold value.
 Box2D boundingBox()
          Returns the bounding box of the shape.
 void clear()
          Clears the inner shape collection.
 Shape2D clip(Box2D box)
          Clip the shape with the given box, and returns a new shape.
 ShapeArray2D<? extends Shape2D> clone()
           
 boolean contains(double x, double y)
          Checks if the shape contains the planar point defined by (x,y).
 boolean contains(Point2D p)
          Checks if the shape contains the given point.
 boolean contains(T shape)
          Checks if the shape set contains the given shape.
static
<T extends Shape2D>
ShapeArray2D<T>
create(java.util.Collection<T> shapes)
           
static
<T extends Shape2D>
ShapeArray2D<T>
create(T... shapes)
           
 double distance(double x, double y)
          Returns the distance of the shape to the given point, specified by x and y, or the distance of point to the frontier of the shape in the case of a plain (i.e. fillable) shape.
 double distance(Point2D p)
          Returns the distance of the shape to the given point, or the distance of point to the frontier of the shape in the case of a plain shape.
 void draw(java.awt.Graphics2D g2)
          Draws the shape on the given graphics.
 boolean equals(java.lang.Object obj)
          Returns true if obj is a CurveSet2D with the same number of shapes, and such that each shape belongs to both objects.
 T get(int index)
          Returns the inner shape corresponding to the given index.
 int indexOf(T shape)
          Returns the index of the shape in this set.
 boolean isBounded()
          Returns true if the shape is bounded, that is if we can draw a finite rectangle enclosing the shape.
 boolean isEmpty()
          Returns true if the shape does not contain any point.
 java.util.Iterator<T> iterator()
           
 T remove(int index)
          Removes the shape at the specified position in this set (optional operation).
 boolean remove(T shape)
          Removes the specified shape from the shape set.
 java.util.Collection<T> shapes()
          Returns the collection of shapes
 int size()
          Returns the number of shapes stored in this set.
 ShapeSet2D<? extends Shape2D> transform(AffineTransform2D trans)
          Transforms the shape by an affine transform.
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ShapeArray2D

public ShapeArray2D()

ShapeArray2D

public ShapeArray2D(int n)

ShapeArray2D

public ShapeArray2D(java.util.Collection<? extends T> shapes)

ShapeArray2D

public ShapeArray2D(T[] shapes)
Method Detail

create

public static <T extends Shape2D> ShapeArray2D<T> create(java.util.Collection<T> shapes)

create

public static <T extends Shape2D> ShapeArray2D<T> create(T... shapes)

add

public boolean add(T shape)
Adds the shape to the shape set, if it does not already belongs to the set.

Specified by:
add in interface ShapeSet2D<T extends Shape2D>
Parameters:
shape - the shape to add

add

public void add(int index,
                T shape)
Description copied from interface: ShapeSet2D
Inserts the specified shape at the specified position in this set (optional operation).

Specified by:
add in interface ShapeSet2D<T extends Shape2D>

get

public T get(int index)
Returns the inner shape corresponding to the given index.

Specified by:
get in interface ShapeSet2D<T extends Shape2D>
Parameters:
index - index of the shape
Returns:
the i-th inner curve

remove

public boolean remove(T shape)
Removes the specified shape from the shape set.

Specified by:
remove in interface ShapeSet2D<T extends Shape2D>
Parameters:
shape - the shape to remove

remove

public T remove(int index)
Description copied from interface: ShapeSet2D
Removes the shape at the specified position in this set (optional operation).

Specified by:
remove in interface ShapeSet2D<T extends Shape2D>

contains

public boolean contains(T shape)
Checks if the shape set contains the given shape.

Specified by:
contains in interface ShapeSet2D<T extends Shape2D>

indexOf

public int indexOf(T shape)
Description copied from interface: ShapeSet2D
Returns the index of the shape in this set.

Specified by:
indexOf in interface ShapeSet2D<T extends Shape2D>

clear

public void clear()
Clears the inner shape collection.

Specified by:
clear in interface ShapeSet2D<T extends Shape2D>

size

public int size()
Description copied from interface: ShapeSet2D
Returns the number of shapes stored in this set.

Specified by:
size in interface ShapeSet2D<T extends Shape2D>

shapes

public java.util.Collection<T> shapes()
Returns the collection of shapes

Returns:
the inner collection of shapes

clip

public Shape2D clip(Box2D box)
Description copied from interface: Shape2D
Clip the shape with the given box, and returns a new shape. The box must be bounded.

Specified by:
clip in interface Shape2D
Parameters:
box - the clipping box
Returns:
the clipped shape

contains

public boolean contains(double x,
                        double y)
Description copied from interface: Shape2D
Checks if the shape contains the planar point defined by (x,y).

Specified by:
contains in interface Shape2D

contains

public boolean contains(Point2D p)
Description copied from interface: Shape2D
Checks if the shape contains the given point.

Specified by:
contains in interface Shape2D

draw

public void draw(java.awt.Graphics2D g2)
Description copied from interface: Shape2D
Draws the shape on the given graphics. If the shape is empty, nothing is drawn. If the shape is unbounded, an exception is thrown.

Specified by:
draw in interface Shape2D

boundingBox

public Box2D boundingBox()
Description copied from interface: Shape2D
Returns the bounding box of the shape.

Specified by:
boundingBox in interface Shape2D
Returns:
the bounding box of the shape.

distance

public double distance(Point2D p)
Description copied from interface: Shape2D
Returns the distance of the shape to the given point, or the distance of point to the frontier of the shape in the case of a plain shape.

Specified by:
distance in interface Shape2D

distance

public double distance(double x,
                       double y)
Description copied from interface: Shape2D
Returns the distance of the shape to the given point, specified by x and y, or the distance of point to the frontier of the shape in the case of a plain (i.e. fillable) shape.

Specified by:
distance in interface Shape2D

isBounded

public boolean isBounded()
Description copied from interface: Shape2D
Returns true if the shape is bounded, that is if we can draw a finite rectangle enclosing the shape. For example, a straight line or a parabola are not bounded.

Specified by:
isBounded in interface Shape2D

isEmpty

public boolean isEmpty()
Description copied from interface: Shape2D
Returns true if the shape does not contain any point. This is the case for example for PointSet2D without any point.

Specified by:
isEmpty in interface Shape2D
Returns:
true if the shape does not contain any point.

transform

public ShapeSet2D<? extends Shape2D> transform(AffineTransform2D trans)
Description copied from interface: Shape2D
Transforms the shape by an affine transform. Subclasses may override the type of returned shape.

Specified by:
transform in interface Shape2D
Parameters:
trans - an affine transform
Returns:
the transformed shape

almostEquals

public boolean almostEquals(GeometricObject2D obj,
                            double eps)
Description copied from interface: GeometricObject2D
Checks if the two objects are similar up to a given threshold value. This method can be used to compare the results of geometric computations, that introduce errors due to numerical computations.

Specified by:
almostEquals in interface GeometricObject2D
Parameters:
obj - the object to compare
eps - a threshold value, for example the minimal coordinate difference
Returns:
true if both object have the same value up to the threshold

iterator

public java.util.Iterator<T> iterator()
Specified by:
iterator in interface java.lang.Iterable<T extends Shape2D>

equals

public boolean equals(java.lang.Object obj)
Returns true if obj is a CurveSet2D with the same number of shapes, and such that each shape belongs to both objects.

Overrides:
equals in class java.lang.Object

clone

public ShapeArray2D<? extends Shape2D> clone()
Overrides:
clone in class java.lang.Object