Added a method for extracting the transform matrix.
This commit is contained in:
@@ -114,6 +114,13 @@ public class AffineTransform extends AbstractTransform
|
|||||||
return this.ty;
|
return this.ty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override // from Transform
|
||||||
|
public void transform (double[] matrix) {
|
||||||
|
matrix[0] = m00; matrix[1] = m01;
|
||||||
|
matrix[2] = m10; matrix[3] = m11;
|
||||||
|
matrix[4] = tx; matrix[5] = ty;
|
||||||
|
}
|
||||||
|
|
||||||
@Override // from Transform
|
@Override // from Transform
|
||||||
public Transform setUniformScale (double scale) {
|
public Transform setUniformScale (double scale) {
|
||||||
return setScale(scale, scale);
|
return setScale(scale, scale);
|
||||||
|
|||||||
@@ -42,6 +42,13 @@ public class IdentityTransform extends AbstractTransform
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override // from Transform
|
||||||
|
public void transform (double[] matrix) {
|
||||||
|
matrix[0] = 1; matrix[1] = 0;
|
||||||
|
matrix[2] = 0; matrix[3] = 1;
|
||||||
|
matrix[4] = 0; matrix[5] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
@Override // from Transform
|
@Override // from Transform
|
||||||
public Transform invert () {
|
public Transform invert () {
|
||||||
return this;
|
return this;
|
||||||
|
|||||||
@@ -63,6 +63,14 @@ public class NonUniformTransform extends AbstractTransform
|
|||||||
return ty;
|
return ty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override // from Transform
|
||||||
|
public void transform (double[] matrix) {
|
||||||
|
double sina = Math.sin(rotation), cosa = Math.cos(rotation);
|
||||||
|
matrix[0] = cosa * scaleX; matrix[1] = sina * scaleY;
|
||||||
|
matrix[2] = -sina * scaleX; matrix[3] = cosa * scaleY;
|
||||||
|
matrix[4] = tx; matrix[5] = ty;
|
||||||
|
}
|
||||||
|
|
||||||
@Override // from Transform
|
@Override // from Transform
|
||||||
public Transform setUniformScale (double scale) {
|
public Transform setUniformScale (double scale) {
|
||||||
setScaleX(scale);
|
setScaleX(scale);
|
||||||
|
|||||||
@@ -58,6 +58,14 @@ public class RigidTransform extends AbstractTransform
|
|||||||
return ty;
|
return ty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override // from Transform
|
||||||
|
public void transform (double[] matrix) {
|
||||||
|
double sina = Math.sin(rotation), cosa = Math.cos(rotation);
|
||||||
|
matrix[0] = cosa; matrix[1] = sina;
|
||||||
|
matrix[2] = -sina; matrix[3] = cosa;
|
||||||
|
matrix[4] = tx; matrix[5] = ty;
|
||||||
|
}
|
||||||
|
|
||||||
@Override // from Transform
|
@Override // from Transform
|
||||||
public Transform setRotation (double angle) {
|
public Transform setRotation (double angle) {
|
||||||
this.rotation = angle;
|
this.rotation = angle;
|
||||||
|
|||||||
@@ -39,6 +39,10 @@ public interface Transform
|
|||||||
/** Returns the y-coordinate of the translation component. */
|
/** Returns the y-coordinate of the translation component. */
|
||||||
double ty ();
|
double ty ();
|
||||||
|
|
||||||
|
/** Copies the affine transform matrix into the supplied array.
|
||||||
|
* @param matrix the array which receives {@code m00, m01, m10, m11, tx, ty}. */
|
||||||
|
void transform (double[] matrix);
|
||||||
|
|
||||||
/** Sets the uniform scale of this transform.
|
/** Sets the uniform scale of this transform.
|
||||||
* @return this instance, for chaining.
|
* @return this instance, for chaining.
|
||||||
* @throws IllegalArgumentException if the supplied scale is zero.
|
* @throws IllegalArgumentException if the supplied scale is zero.
|
||||||
|
|||||||
@@ -63,6 +63,14 @@ public class UniformTransform extends AbstractTransform
|
|||||||
return ty;
|
return ty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override // from Transform
|
||||||
|
public void transform (double[] matrix) {
|
||||||
|
double sina = Math.sin(rotation), cosa = Math.cos(rotation);
|
||||||
|
matrix[0] = cosa * scale; matrix[1] = sina * scale;
|
||||||
|
matrix[2] = -sina * scale; matrix[3] = cosa * scale;
|
||||||
|
matrix[4] = tx; matrix[5] = ty;
|
||||||
|
}
|
||||||
|
|
||||||
@Override // from Transform
|
@Override // from Transform
|
||||||
public Transform setUniformScale (double scale) {
|
public Transform setUniformScale (double scale) {
|
||||||
if (scale == 0) throw new IllegalArgumentException("Scale must be non-zero.");
|
if (scale == 0) throw new IllegalArgumentException("Scale must be non-zero.");
|
||||||
|
|||||||
@@ -114,6 +114,13 @@ public class AffineTransform extends AbstractTransform
|
|||||||
return this.ty;
|
return this.ty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override // from Transform
|
||||||
|
public void transform (float[] matrix) {
|
||||||
|
matrix[0] = m00; matrix[1] = m01;
|
||||||
|
matrix[2] = m10; matrix[3] = m11;
|
||||||
|
matrix[4] = tx; matrix[5] = ty;
|
||||||
|
}
|
||||||
|
|
||||||
@Override // from Transform
|
@Override // from Transform
|
||||||
public Transform setUniformScale (float scale) {
|
public Transform setUniformScale (float scale) {
|
||||||
return setScale(scale, scale);
|
return setScale(scale, scale);
|
||||||
|
|||||||
@@ -42,6 +42,13 @@ public class IdentityTransform extends AbstractTransform
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override // from Transform
|
||||||
|
public void transform (float[] matrix) {
|
||||||
|
matrix[0] = 1; matrix[1] = 0;
|
||||||
|
matrix[2] = 0; matrix[3] = 1;
|
||||||
|
matrix[4] = 0; matrix[5] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
@Override // from Transform
|
@Override // from Transform
|
||||||
public Transform invert () {
|
public Transform invert () {
|
||||||
return this;
|
return this;
|
||||||
|
|||||||
@@ -63,6 +63,14 @@ public class NonUniformTransform extends AbstractTransform
|
|||||||
return ty;
|
return ty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override // from Transform
|
||||||
|
public void transform (float[] matrix) {
|
||||||
|
float sina = FloatMath.sin(rotation), cosa = FloatMath.cos(rotation);
|
||||||
|
matrix[0] = cosa * scaleX; matrix[1] = sina * scaleY;
|
||||||
|
matrix[2] = -sina * scaleX; matrix[3] = cosa * scaleY;
|
||||||
|
matrix[4] = tx; matrix[5] = ty;
|
||||||
|
}
|
||||||
|
|
||||||
@Override // from Transform
|
@Override // from Transform
|
||||||
public Transform setUniformScale (float scale) {
|
public Transform setUniformScale (float scale) {
|
||||||
setScaleX(scale);
|
setScaleX(scale);
|
||||||
|
|||||||
@@ -58,6 +58,14 @@ public class RigidTransform extends AbstractTransform
|
|||||||
return ty;
|
return ty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override // from Transform
|
||||||
|
public void transform (float[] matrix) {
|
||||||
|
float sina = FloatMath.sin(rotation), cosa = FloatMath.cos(rotation);
|
||||||
|
matrix[0] = cosa; matrix[1] = sina;
|
||||||
|
matrix[2] = -sina; matrix[3] = cosa;
|
||||||
|
matrix[4] = tx; matrix[5] = ty;
|
||||||
|
}
|
||||||
|
|
||||||
@Override // from Transform
|
@Override // from Transform
|
||||||
public Transform setRotation (float angle) {
|
public Transform setRotation (float angle) {
|
||||||
this.rotation = angle;
|
this.rotation = angle;
|
||||||
|
|||||||
@@ -39,6 +39,10 @@ public interface Transform
|
|||||||
/** Returns the y-coordinate of the translation component. */
|
/** Returns the y-coordinate of the translation component. */
|
||||||
float ty ();
|
float ty ();
|
||||||
|
|
||||||
|
/** Copies the affine transform matrix into the supplied array.
|
||||||
|
* @param matrix the array which receives {@code m00, m01, m10, m11, tx, ty}. */
|
||||||
|
void transform (float[] matrix);
|
||||||
|
|
||||||
/** Sets the uniform scale of this transform.
|
/** Sets the uniform scale of this transform.
|
||||||
* @return this instance, for chaining.
|
* @return this instance, for chaining.
|
||||||
* @throws IllegalArgumentException if the supplied scale is zero.
|
* @throws IllegalArgumentException if the supplied scale is zero.
|
||||||
|
|||||||
@@ -63,6 +63,14 @@ public class UniformTransform extends AbstractTransform
|
|||||||
return ty;
|
return ty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override // from Transform
|
||||||
|
public void transform (float[] matrix) {
|
||||||
|
float sina = FloatMath.sin(rotation), cosa = FloatMath.cos(rotation);
|
||||||
|
matrix[0] = cosa * scale; matrix[1] = sina * scale;
|
||||||
|
matrix[2] = -sina * scale; matrix[3] = cosa * scale;
|
||||||
|
matrix[4] = tx; matrix[5] = ty;
|
||||||
|
}
|
||||||
|
|
||||||
@Override // from Transform
|
@Override // from Transform
|
||||||
public Transform setUniformScale (float scale) {
|
public Transform setUniformScale (float scale) {
|
||||||
if (scale == 0) throw new IllegalArgumentException("Scale must be non-zero.");
|
if (scale == 0) throw new IllegalArgumentException("Scale must be non-zero.");
|
||||||
|
|||||||
Reference in New Issue
Block a user