Transformpublic class Transform extends Object implements org.w3c.dom.svg.SVGMatrix
Fields Summary |
---|
float | m0The (0, 0) component of this 3x3 transformation matrix. | float | m1The (1, 0) component of this 3x3 transformation matrix. | float | m2The (0, 1) component of this 3x3 transformation matrix. | float | m3The (1, 1) component of this 3x3 transformation matrix. | float | m4The (0, 2) component of this 3x3 transformation matrix. | float | m5The (1, 2) component of this 3x3 transformation matrix. |
Constructors Summary |
---|
public Transform(float m0, float m1, float m2, float m3, float m4, float m5)Constructs an Transform with a given set of
components, representing the transform:
x' = m0*x + m2*y + m4
y' = m1*x + m3*y + m5
or, representing the matrix:
[ m0 m2 m4 ]
[ m1 m3 m5 ]
[ 0 0 1 ]
setTransform(m0, m1, m2, m3, m4, m5);
| public Transform(org.w3c.dom.svg.SVGMatrix transform)Constructs an Transform representing the same
transform as the given Transform . Future changes
to the object supplied as the transform parameter
will not affect the newly constructed Transform .
If transform is null, the matrix is initialized
to be the identity matrix.
setTransform(transform);
|
Methods Summary |
---|
public boolean | equals(java.lang.Object obj)
if (obj == null || !(obj instanceof Transform)) {
return false;
}
if (obj == this) {
return true;
}
Transform t = (Transform) obj;
return t.m0 == m0
&&
t.m1 == m1
&&
t.m2 == m2
&&
t.m3 == m3
&&
t.m4 == m4
&&
t.m5 == m5;
| public boolean | equals(float[][] m)
return m[0][0] == m0
&&
m[1][0] == m1
&&
m[2][0] == m2
&&
m[3][0] == m3
&&
m[4][0] == m4
&&
m[5][0] == m5;
| public float | getComponent(int index)The components of the matrix denoted a to f in the API are :
[ a c e ]
[ b d f ]
[ 0 0 1 ]
switch (index) {
case 0:
return m0;
case 1:
return m1;
case 2:
return m2;
case 3:
return m3;
case 4:
return m4;
case 5:
return m5;
default:
throw new DOMException
(DOMException.INDEX_SIZE_ERR,
Messages.formatMessage
(Messages.ERROR_OUT_OF_BOUND_PARAMETER_VALUE,
new String[] {"SVGMatrix",
"getComponent",
"index",
"" + index}));
}
| public org.w3c.dom.svg.SVGMatrix | inverse(org.w3c.dom.svg.SVGMatrix txf)Inverses this transform and stores the resulting transform into
the input transform.
Transform svm = (Transform) txf;
float det = m0 * m3 - m2 * m1;
if (MathSupport.abs(det) <= Float.MIN_VALUE) {
throw new SVGException(SVGException.SVG_MATRIX_NOT_INVERTABLE,
this.toString());
}
if (svm == null) {
svm = new Transform(1, 0, 0, 1, 0, 0);
}
if (isIdentity()) {
svm.setTransform(1, 0, 0, 1, 0, 0);
return svm;
}
svm.m0 = m3 / det;
svm.m2 = -m2 / det;
svm.m4 = (m2 * m5 - m3 * m4) / det;
svm.m1 = -m1 / det;
svm.m3 = m0 / det;
svm.m5 = (m1 * m4 - m0 * m5) / det;
return svm;
| public org.w3c.dom.svg.SVGMatrix | inverse()Returns the inverse matrix.
Transform svm = new Transform(1, 0, 0, 1, 0, 0);
inverse(svm);
return svm;
| public boolean | isIdentity()Returns true if the current SVGMatrix
is equivalent to the identity matrix, false
otherwise.
return (m0 == 1f
&&
m2 == 0f
&&
m4 == 0f
&&
m1 == 0f
&&
m3 == 1f
&&
m5 == 0f);
| public boolean | isInvertible()Returns true if the matrix is invertible.
return (m0 * m3 - m1 * m2) != 0;
| public org.w3c.dom.svg.SVGMatrix | mMultiply(org.w3c.dom.svg.SVGMatrix secondMatrix)
if (secondMatrix == null) {
throw new NullPointerException();
}
Transform sm = (Transform) secondMatrix;
float t0 = sm.m0;
float t1 = sm.m1;
float t2 = sm.m2;
float t3 = sm.m3;
float t4 = sm.m4;
float t5 = sm.m5;
float mM0 = m0;
float mM1 = m2;
m0 = t0 * mM0 + t1 * mM1;
m2 = t2 * mM0 + t3 * mM1;
m4 += t4 * mM0 + t5 * mM1;
mM0 = m1;
mM1 = m3;
m1 = t0 * mM0 + t1 * mM1;
m3 = t2 * mM0 + t3 * mM1;
m5 += t4 * mM0 + t5 * mM1;
return this;
| public org.w3c.dom.svg.SVGMatrix | mRotate(float angle)
final float angl = MathSupport.toRadians(angle);
final float trigTOLERANCE = 1E-7f;
final float sin = MathSupport.sin(angl);
final float cos = MathSupport.cos(angl);
if (MathSupport.abs(sin) < trigTOLERANCE) { // angle = 0 or 180 deg.
if (cos < 0f) { // angle = 180 deg.
m0 = -m0;
m3 = -m3;
m2 = -m2;
m1 = -m1;
}
return this;
}
if (MathSupport.abs(cos) < trigTOLERANCE) { // angle = 90 or 270 deg.
if (sin < 0f) { // angle = 270 deg
float mM0 = m0;
m0 = -m2;
m2 = mM0;
mM0 = m1;
m1 = -m3;
m3 = mM0;
} else { // angle = 90 deg
float mM0 = m0;
m0 = m2;
m2 = -mM0;
mM0 = m1;
m1 = m3;
m3 = -mM0;
}
return this;
}
float mM0, mM1;
mM0 = m0;
mM1 = m2;
m0 = cos * mM0 + sin * mM1;
m2 = -sin * mM0 + cos * mM1;
mM0 = m1;
mM1 = m3;
m1 = cos * mM0 + sin * mM1;
m3 = -sin * mM0 + cos * mM1;
return this;
| public org.w3c.dom.svg.SVGMatrix | mScale(float scaleFactor)
m0 *= scaleFactor;
m2 *= scaleFactor;
m1 *= scaleFactor;
m3 *= scaleFactor;
return this;
| public org.w3c.dom.svg.SVGMatrix | mScale(float scaleFactorX, float scaleFactorY)Post-multiplies a scale transformation on the current matrix and
returns the resulting matrix.
[ scaleFactorX 0 0 ]
[ 0 scaleFactorY 0 ]
[ 0 0 1 ]
m0 *= scaleFactorX;
m2 *= scaleFactorY;
m1 *= scaleFactorX;
m3 *= scaleFactorY;
return this;
| public org.w3c.dom.svg.SVGMatrix | mTranslate(float x, float y)
m4 = x * m0 + y * m2 + m4;
m5 = x * m1 + y * m3 + m5;
return this;
| public void | setTransform(float m0, float m1, float m2, float m3, float m4, float m5)Sets the transform to the matrix defined by the input parameters:
[ m0 m2 m4 ]
[ m1 m3 m5 ]
[ 0 0 1 ]
this.m0 = m0;
this.m1 = m1;
this.m2 = m2;
this.m3 = m3;
this.m4 = m4;
this.m5 = m5;
| public void | setTransform(org.w3c.dom.svg.SVGMatrix transform)Sets the transform to the value defined by the input matrix.
Transform txf = (Transform) transform;
if (txf == null) {
m0 = 1; // create IDENTITY transformation
m1 = 0;
m2 = 0;
m3 = 1;
m4 = 0;
m5 = 0;
return;
}
this.m0 = txf.m0;
this.m1 = txf.m1;
this.m2 = txf.m2;
this.m3 = txf.m3;
this.m4 = txf.m4;
this.m5 = txf.m5;
| public void | transformPoint(float[] pt, float[] opt)Transforms a point's coordinates.
opt[0] = pt[0] * m0 + pt[1] * m2 + m4;
opt[1] = pt[0] * m1 + pt[1] * m3 + m5;
|
|