math.geom2d.point
Class PointArray2D
- java.lang.Object
-
- math.geom2d.point.PointArray2D
-
- All Implemented Interfaces:
- java.lang.Cloneable, java.lang.Iterable<Point2D>, CirculinearShape2D, GeometricObject2D, PointSet2D, PointShape2D, Shape2D, ShapeSet2D<Point2D>
public class PointArray2D extends java.lang.Object implements PointSet2D, CirculinearShape2D, java.lang.Cloneable
Represent the union of a finite number of Point2D.
-
-
Constructor Summary
Constructors Constructor and Description PointArray2D()Creates a new PointArray2D without any points.PointArray2D(java.util.Collection<? extends Point2D> points)Points must be a collection of java.awt.Point.PointArray2D(int n)Creates a new empty PointArray2D, but preallocates the memory for storing a given amount of points.PointArray2D(Point2D... points)Instances of Point2D are directly added, other Point are converted to Point2D with the same location.PointArray2D(PointSet2D set)Copy constructor
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method and Description voidadd(int index, Point2D point)Inserts the specified shape at the specified position in this set (optional operation).booleanadd(Point2D point)Add a new point to the set of point.voidaddAll(java.util.Collection<? extends Point2D> points)Add a series of pointsvoidaddAll(Point2D[] points)Add a series of pointsbooleanalmostEquals(GeometricObject2D obj, double eps)Checks if the two objects are similar up to a given threshold value.Box2DboundingBox()Returns the bounding box of the shape.CirculinearDomain2Dbuffer(double dist)Computes the buffer of the shape, formed by the set of points located at a distance from the shape that is lower or equal to d.voidclear()remove all points of the set.PointArray2Dclip(Box2D box)Returns a new point set containing only points located within the box.PointArray2Dclone()Deprecated.use copy constructor instead (0.11.2)booleancontains(double x, double y)Checks if the shape contains the planar point defined by (x,y).booleancontains(Point2D point)Checks if the shape contains the given point.static <T extends Point2D>
PointArray2Dcreate(java.util.Collection<T> points)static PointArray2Dcreate(int size)Allocate memory for the specified number of points.static <T extends Point2D>
PointArray2Dcreate(T... points)doubledistance(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.doubledistance(Point2D p)Return distance to the closest point of the collectionvoiddraw(java.awt.Graphics2D g2)Draws the point set on the specified Graphics2D, using default radius equal to 1.voiddraw(java.awt.Graphics2D g2, double r)Draws the point set on the specified Graphics2D, by filling a disc with a given radius.booleanequals(java.lang.Object obj)Returns true if the given object is an instance of PointSet2D that contains the same number of points, such that iteration on each set returns equal points.Point2Dget(int index)Returns the shape at a given position.intindexOf(Point2D point)Returns the index of the shape in this set.booleanisBounded()Always return true.booleanisEmpty()Returns true if the point set is empty, i.e.java.util.Iterator<Point2D>iterator()java.util.Collection<Point2D>points()return an iterator on the internal point collection.Point2Dremove(int index)Removes the shape at the specified position in this set (optional operation).booleanremove(Point2D point)Removes the first occurrence of the specified element from this list, if it is present.intsize()Returns the number of points in the set.PointArray2Dtransform(AffineTransform2D trans)Transforms the point set by returning a new point set containing each transformed point.PointArray2Dtransform(CircleInversion2D inv)Transforms the shape by a circle inversion.
-
-
-
Constructor Detail
-
PointArray2D
public PointArray2D()
Creates a new PointArray2D without any points.
-
PointArray2D
public PointArray2D(int n)
Creates a new empty PointArray2D, but preallocates the memory for storing a given amount of points.- Parameters:
n- the expected number of points in the PointArray2D.
-
PointArray2D
public PointArray2D(Point2D... points)
Instances of Point2D are directly added, other Point are converted to Point2D with the same location.
-
PointArray2D
public PointArray2D(PointSet2D set)
Copy constructor
-
PointArray2D
public PointArray2D(java.util.Collection<? extends Point2D> points)
Points must be a collection of java.awt.Point. Instances of Point2D are directly added, other Point are converted to Point2D with the same location.- Parameters:
points-
-
-
Method Detail
-
create
public static <T extends Point2D> PointArray2D create(java.util.Collection<T> points)
-
create
public static <T extends Point2D> PointArray2D create(T... points)
-
create
public static PointArray2D create(int size)
Allocate memory for the specified number of points.
-
add
public boolean add(Point2D point)
Add a new point to the set of point. If point is not an instance of Point2D, a Point2D with same location is added instead of point.- Specified by:
addin interfacePointSet2D- Specified by:
addin interfaceShapeSet2D<Point2D>- Parameters:
point-
-
add
public void add(int index, Point2D point)Description copied from interface:ShapeSet2DInserts the specified shape at the specified position in this set (optional operation).- Specified by:
addin interfaceShapeSet2D<Point2D>
-
addAll
public void addAll(Point2D[] points)
Add a series of points- Parameters:
points- an array of points
-
addAll
public void addAll(java.util.Collection<? extends Point2D> points)
Description copied from interface:PointSet2DAdd a series of points- Specified by:
addAllin interfacePointSet2D- Parameters:
points- an array of points
-
get
public Point2D get(int index)
Description copied from interface:ShapeSet2DReturns the shape at a given position.- Specified by:
getin interfaceShapeSet2D<Point2D>- Parameters:
index- the position of the shape- Returns:
- the shape at the given position
-
remove
public boolean remove(Point2D point)
Description copied from interface:ShapeSet2DRemoves the first occurrence of the specified element from this list, if it is present. If the list does not contain the element, it is unchanged. Returns true if this list contained the specified element (or equivalently, if this list changed as a result of the call).- Specified by:
removein interfaceShapeSet2D<Point2D>
-
remove
public Point2D remove(int index)
Description copied from interface:ShapeSet2DRemoves the shape at the specified position in this set (optional operation).- Specified by:
removein interfaceShapeSet2D<Point2D>
-
indexOf
public int indexOf(Point2D point)
Description copied from interface:ShapeSet2DReturns the index of the shape in this set.- Specified by:
indexOfin interfaceShapeSet2D<Point2D>
-
points
public java.util.Collection<Point2D> points()
return an iterator on the internal point collection.- Specified by:
pointsin interfacePointSet2D- Specified by:
pointsin interfacePointShape2D- Returns:
- the collection of points
-
clear
public void clear()
remove all points of the set.- Specified by:
clearin interfaceShapeSet2D<Point2D>
-
size
public int size()
Returns the number of points in the set.- Specified by:
sizein interfacePointSet2D- Specified by:
sizein interfacePointShape2D- Specified by:
sizein interfaceShapeSet2D<Point2D>- Returns:
- the number of points
-
buffer
public CirculinearDomain2D buffer(double dist)
Description copied from interface:CirculinearShape2DComputes the buffer of the shape, formed by the set of points located at a distance from the shape that is lower or equal to d.- Specified by:
bufferin interfaceCirculinearShape2D- Parameters:
dist- the maximal distance between a point of the buffer and the shape- Returns:
- the buffer of the shape
-
transform
public PointArray2D transform(CircleInversion2D inv)
Description copied from interface:CirculinearShape2DTransforms the shape by a circle inversion. The result is still an instance a CirculinearShape2D.- Specified by:
transformin interfaceCirculinearShape2D- Parameters:
inv- the circle inversion- Returns:
- the transformed shape
-
distance
public double distance(Point2D p)
Return distance to the closest point of the collection
-
distance
public double distance(double x, double y)Description copied from interface:Shape2DReturns 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.
-
isBounded
public boolean isBounded()
Always return true.
-
isEmpty
public boolean isEmpty()
Returns true if the point set is empty, i.e. the number of points is 0.
-
clip
public PointArray2D clip(Box2D box)
Description copied from interface:PointSet2DReturns a new point set containing only points located within the box.- Specified by:
clipin interfacePointSet2D- Specified by:
clipin interfacePointShape2D- Specified by:
clipin interfaceShape2D- Parameters:
box- the clipping box- Returns:
- the clipped shape
-
boundingBox
public Box2D boundingBox()
Description copied from interface:Shape2DReturns the bounding box of the shape.- Specified by:
boundingBoxin interfaceShape2D- Returns:
- the bounding box of the shape.
-
transform
public PointArray2D transform(AffineTransform2D trans)
Description copied from interface:PointSet2DTransforms the point set by returning a new point set containing each transformed point.- Specified by:
transformin interfacePointSet2D- Specified by:
transformin interfacePointShape2D- Specified by:
transformin interfaceShape2D- Parameters:
trans- an affine transform- Returns:
- the transformed shape
-
contains
public boolean contains(double x, double y)Description copied from interface:Shape2DChecks if the shape contains the planar point defined by (x,y).
-
contains
public boolean contains(Point2D point)
Description copied from interface:Shape2DChecks if the shape contains the given point.- Specified by:
containsin interfaceShape2D- Specified by:
containsin interfaceShapeSet2D<Point2D>
-
draw
public void draw(java.awt.Graphics2D g2)
Draws the point set on the specified Graphics2D, using default radius equal to 1.
-
draw
public void draw(java.awt.Graphics2D g2, double r)Draws the point set on the specified Graphics2D, by filling a disc with a given radius.- Parameters:
g2- the graphics to draw the point set
-
iterator
public java.util.Iterator<Point2D> iterator()
- Specified by:
iteratorin interfacejava.lang.Iterable<Point2D>
-
almostEquals
public boolean almostEquals(GeometricObject2D obj, double eps)
Description copied from interface:GeometricObject2DChecks 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:
almostEqualsin interfaceGeometricObject2D- Parameters:
obj- the object to compareeps- a threshold value, for example the minimal coordinate difference- Returns:
- true if both object have the same value up to the threshold
-
equals
public boolean equals(java.lang.Object obj)
Returns true if the given object is an instance of PointSet2D that contains the same number of points, such that iteration on each set returns equal points.- Overrides:
equalsin classjava.lang.Object
-
clone
@Deprecated public PointArray2D clone()
Deprecated. use copy constructor instead (0.11.2)- Overrides:
clonein classjava.lang.Object
-
-
DMelt 3.0 © DataMelt by jWork.ORG