Class AwtMutableConvexPolygon
-
- All Implemented Interfaces:
-
it.unibo.alchemist.model.geometry.AwtShapeCompatible
,it.unibo.alchemist.model.geometry.ConvexPolygon
,it.unibo.alchemist.model.geometry.ConvexShape
,it.unibo.alchemist.model.geometry.MutableConvexPolygon
,it.unibo.alchemist.model.geometry.Shape
,java.io.Serializable
public class AwtMutableConvexPolygon extends AbstractConvexPolygon implements MutableConvexPolygon
MutableConvexPolygon partly delegated to AwtEuclidean2DShape and java.awt.geom. Each modification operation on this object has a time complexity of O(n), where n is the number of vertices/edges. Collinear points are allowed.
-
-
Constructor Summary
Constructors Constructor Description AwtMutableConvexPolygon(List<Euclidean2DPosition> vertices)
-
Method Summary
Modifier and Type Method Description Double
getDiameter()
Euclidean2DPosition
getCentroid()
List<Euclidean2DPosition>
vertices()
Segment2DImpl<Euclidean2DPosition>
getEdge(Integer index)
List<Segment2D<Euclidean2DPosition>>
edges()
Boolean
addVertex(Integer index, Double x, Double y)
Adds a vertex to the polygon. Boolean
removeVertex(Integer index)
Removes a vertex from the polygon. Boolean
moveVertex(Integer index, Double newX, Double newY)
Moves a vertex of the polygon to a new absolute position. Boolean
replaceEdge(Integer index, Segment2D<Euclidean2DPosition> newEdge)
Replaces an edge of the polygon. Boolean
contains(Euclidean2DPosition vector)
Delegated to AwtEuclidean2DShape (adopts the definition of insideness used by java.awt.Shapes). Boolean
intersects(Shape shape)
Delegated to java.awt.geom.Area, this is accurate and does not consider adjacent shapes to be intersecting. Boolean
intersects(Shape<Euclidean2DPosition, Euclidean2DTransformation> other)
Delegated to AwtEuclidean2DShape unless other is AwtShapeCompatible, in which case intersects is used so as to guarantee maximum accuracy. Shape<Euclidean2DPosition, Euclidean2DTransformation>
transformed(Function1<Euclidean2DTransformation, Unit> transformation)
final Shape
asAwtShape()
Boolean
equals(Object other)
Integer
hashCode()
-
Methods inherited from class it.unibo.alchemist.model.geometry.Shape
getRadius
-
Methods inherited from class it.unibo.alchemist.model.geometry.AbstractConvexPolygon
closestEdgeTo, contains, containsBoundaryExcluded, containsBoundaryIncluded, intersects, isAdjacentTo, liesOnBoundary, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
Constructor Detail
-
AwtMutableConvexPolygon
AwtMutableConvexPolygon(List<Euclidean2DPosition> vertices)
-
-
Method Detail
-
getDiameter
Double getDiameter()
-
getCentroid
Euclidean2DPosition getCentroid()
-
vertices
List<Euclidean2DPosition> vertices()
-
getEdge
Segment2DImpl<Euclidean2DPosition> getEdge(Integer index)
- Parameters:
index
- indicates which edge to get: edge i connects vertices i and i+1 (with respect to the ordering of vertices used in vertices)
-
edges
List<Segment2D<Euclidean2DPosition>> edges()
-
addVertex
Boolean addVertex(Integer index, Double x, Double y)
Adds a vertex to the polygon.
- Parameters:
index
- the index in the list of vertices where to put the new vertexx
- x coordinatey
- y coordinate
-
removeVertex
Boolean removeVertex(Integer index)
Removes a vertex from the polygon.
- Parameters:
index
- the index of the vertex to be removed in the list of vertices
-
moveVertex
Boolean moveVertex(Integer index, Double newX, Double newY)
Moves a vertex of the polygon to a new absolute position.
- Parameters:
index
- the index of the vertex to movenewX
- new absolute x coordinatenewY
- new absolute y coordinate
-
replaceEdge
Boolean replaceEdge(Integer index, Segment2D<Euclidean2DPosition> newEdge)
Replaces an edge of the polygon.
- Parameters:
index
- the index of the edge to replace (edge i connects vertices i and i+1)newEdge
- the new edge
-
contains
Boolean contains(Euclidean2DPosition vector)
Delegated to AwtEuclidean2DShape (adopts the definition of insideness used by java.awt.Shapes).
- Parameters:
vector
- the vector (= point)
-
intersects
Boolean intersects(Shape shape)
Delegated to java.awt.geom.Area, this is accurate and does not consider adjacent shapes to be intersecting.
- Parameters:
shape
- the shape
-
intersects
Boolean intersects(Shape<Euclidean2DPosition, Euclidean2DTransformation> other)
Delegated to AwtEuclidean2DShape unless other is AwtShapeCompatible, in which case intersects is used so as to guarantee maximum accuracy.
-
transformed
Shape<Euclidean2DPosition, Euclidean2DTransformation> transformed(Function1<Euclidean2DTransformation, Unit> transformation)
-
asAwtShape
final Shape asAwtShape()
- Returns:
a copy of itself in form of a java.awt.Shape.
-
-
-
-