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 Object
Class designed to aid construction of Parallelogram 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 Details

    • 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.
  • Constructor Details

    • Builder

      private Builder(org.apache.commons.numbers.core.Precision.DoubleEquivalence precision)
      Construct a new instance configured with the given precision context.
      Parameters:
      precision - precision context used to create boundaries
  • Method Details

    • 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 factor
      y - 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:
      IllegalArgumentException - if the given vector cannot be normalized
      See Also:
    • 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:
      IllegalArgumentException - if the given vector cannot be normalized
      See Also:
    • build

      public Parallelogram build()
      Build a new parallelogram instance with the values configured in this builder.
      Returns:
      a new parallelogram instance
      Throws:
      IllegalArgumentException - if the length of any side of the parallelogram is zero, as determined by the configured precision context
      See Also: