Class Parallelogram.Builder
- java.lang.Object
-
- org.apache.commons.geometry.euclidean.twod.shape.Parallelogram.Builder
-
- Enclosing class:
- Parallelogram
public static final class Parallelogram.Builder extends java.lang.Object
Class designed to aid construction ofParallelogram
instances. Parallelograms are constructed by transforming the vertices of a unit square centered at the origin with a transform built from the values configured here. The transformations applied are scaling, rotation, and translation, in that order. When applied in this order, the scale factors determine the width and height of the parallelogram, the rotation determines the orientation, and the translation determines the position of the center point.
-
-
Field Summary
Fields Modifier and Type Field Description private Vector2D
position
Amount to translate the parallelogram.private org.apache.commons.numbers.core.Precision.DoubleEquivalence
precision
Precision context used to construct boundaries.private Rotation2D
rotation
The rotation of the parallelogram.private Vector2D
scale
Amount to scale the parallelogram.
-
Constructor Summary
Constructors Modifier Constructor Description private
Builder(org.apache.commons.numbers.core.Precision.DoubleEquivalence precision)
Construct a new instance configured with the given precision context.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Parallelogram
build()
Build a new parallelogram instance with the values configured in this builder.Parallelogram.Builder
setPosition(Vector2D pos)
Set the center position of the created parallelogram.Parallelogram.Builder
setRotation(Rotation2D rot)
Set the rotation of the created parallelogram.Parallelogram.Builder
setScale(double scaleFactor)
Set the scaling for the created parallelogram.Parallelogram.Builder
setScale(double x, double y)
Set the scaling for the created parallelogram.Parallelogram.Builder
setScale(Vector2D scaleFactors)
Set the scaling for the created parallelogram.Parallelogram.Builder
setXDirection(Vector2D xDirection)
Set the rotation of the created parallelogram such that the relative x-axis of the shape points in the given direction.Parallelogram.Builder
setYDirection(Vector2D yDirection)
Set the rotation of the created parallelogram such that the relative y-axis of the shape points in the given direction.
-
-
-
Field Detail
-
scale
private Vector2D scale
Amount to scale the parallelogram.
-
rotation
private Rotation2D rotation
The rotation of the parallelogram.
-
position
private Vector2D position
Amount to translate the parallelogram.
-
precision
private final org.apache.commons.numbers.core.Precision.DoubleEquivalence precision
Precision context used to construct boundaries.
-
-
Method Detail
-
setPosition
public Parallelogram.Builder setPosition(Vector2D pos)
Set the center position of the created parallelogram.- Parameters:
pos
- center position of the created parallelogram- Returns:
- this instance
-
setScale
public Parallelogram.Builder setScale(Vector2D scaleFactors)
Set the scaling for the created parallelogram. The scale values determine the lengths of the respective sides in the created parallelogram.- Parameters:
scaleFactors
- scale factors- Returns:
- this instance
-
setScale
public Parallelogram.Builder setScale(double x, double y)
Set the scaling for the created parallelogram. The scale values determine the lengths of the respective sides in the created parallelogram.- Parameters:
x
- x scale factory
- y scale factor- Returns:
- this instance
-
setScale
public Parallelogram.Builder setScale(double scaleFactor)
Set the scaling for the created parallelogram. The given scale factor is applied to both the x and y directions.- Parameters:
scaleFactor
- scale factor for x and y directions- Returns:
- this instance
-
setRotation
public Parallelogram.Builder setRotation(Rotation2D rot)
Set the rotation of the created parallelogram.- Parameters:
rot
- the rotation of the created parallelogram- Returns:
- this instance
-
setXDirection
public Parallelogram.Builder setXDirection(Vector2D xDirection)
Set the rotation of the created parallelogram such that the relative x-axis of the shape points in the given direction.- Parameters:
xDirection
- the direction of the relative x-axis- Returns:
- this instance
- Throws:
java.lang.IllegalArgumentException
- if the given vector cannot be normalized- See Also:
setRotation(Rotation2D)
-
setYDirection
public Parallelogram.Builder setYDirection(Vector2D yDirection)
Set the rotation of the created parallelogram such that the relative y-axis of the shape points in the given direction.- Parameters:
yDirection
- the direction of the relative y-axis- Returns:
- this instance
- Throws:
java.lang.IllegalArgumentException
- if the given vector cannot be normalized- See Also:
setRotation(Rotation2D)
-
build
public Parallelogram build()
Build a new parallelogram instance with the values configured in this builder.- Returns:
- a new parallelogram instance
- Throws:
java.lang.IllegalArgumentException
- if the length of any side of the parallelogram is zero, as determined by the configured precision context- See Also:
Parallelogram.fromTransformedUnitSquare(Transform, Precision.DoubleEquivalence)
-
-