Skip to content

Commit

Permalink
GEOMETRY-117 - AffineTransformMatrix2D should support shear transform
Browse files Browse the repository at this point in the history
  • Loading branch information
Christoph Läubrich committed Mar 24, 2021
1 parent 8c82ce9 commit 4711392
Showing 1 changed file with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,31 @@ public Vector2D apply(final Vector2D pt) {
return Vector2D.of(resultX, resultY);
}

public double transformX(final double x) {
if (m01 != 0.0) {
throw new IllegalStateException(
"maxtrix contains y-shear value, you need to call the two argument variant of this function");
}
return m00 * x + m02;
}

public double transformX(final double x, double y) {
return LinearCombination.value(m00, x, m01, y) + m02;
}

public double transformY(double y) {
if (m10 != 0.0) {
throw new IllegalStateException(
"maxtrix contains x-shear value, you need to call the two argument variant of this function");
}
return m11 * y + m12;
}

public double transformY(final double x, double y) {

return LinearCombination.value(m10, x, m11, y) + m12;
}

/** {@inheritDoc}
*
* <p>The transformed vector is computed by creating a 3-element column vector from the
Expand Down Expand Up @@ -224,6 +249,20 @@ public AffineTransformMatrix2D translate(final double x, final double y) {
);
}

/**
* Apply a shear to the current instance, returning the result as a new transform.
* @param shx shear in x-direction
* @param shy shear in y direction
* @return a new transform containing the result of applying a shear to
* the current instance
*/
public AffineTransformMatrix2D shear(double shx, double shy) {
return multiply(AffineTransformMatrix2D.of(
1.0, shx, 0.0,
shy, 1.0, 0.0
), this);
}

/** Apply a scale operation to the current instance, returning the result as a new transform.
* @param factor the scale factor to apply to all axes
* @return a new transform containing the result of applying a scale operation to
Expand Down

0 comments on commit 4711392

Please sign in to comment.