21package com.jogamp.math.geom.plane;
25import com.jogamp.graph.geom.Vertex;
26import com.jogamp.math.FloatUtil;
27import com.jogamp.math.Vec2f;
28import com.jogamp.math.Vec3f;
29import com.jogamp.math.geom.AABBox;
33 static final String determinantIsZero =
"Determinant is zero";
49 static final int TYPE_UNKNOWN = -1;
54 static final float ZERO = (float) 1E-10;
69 private transient int type;
85 public AffineTransform(
final float m00,
final float m10,
final float m01,
final float m11,
final float m02,
final float m12) {
86 this.type = TYPE_UNKNOWN;
96 this.type = TYPE_UNKNOWN;
101 if (matrix.length > 4) {
127 if (type != TYPE_UNKNOWN) {
133 if (m00 * m01 + m10 * m11 != 0.0) {
138 if (m02 != 0.0 || m12 != 0.0) {
141 if (m00 == 1.0 && m11 == 1.0 && m01 == 0.0 && m10 == 0.0) {
146 if (m00 * m11 - m01 * m10 < 0.0) {
150 final float dx = m00 * m00 + m10 * m10;
151 final float dy = m01 * m01 + m11 * m11;
159 if ((m00 == 0.0 && m11 == 0.0) ||
160 (m10 == 0.0 && m01 == 0.0 && (m00 < 0.0 || m11 < 0.0)))
164 if (m01 != 0.0 || m10 != 0.0) {
204 if (matrix.length > 4) {
211 return m00 * m11 - m01 * m10;
215 this.type = TYPE_UNKNOWN;
234 m10 = m01 = m02 = m12 = 0.0f;
243 if (mx == 0.0f && my == 0.0f) {
254 m10 = m01 = m02 = m12 = 0.0f;
255 if (scx != 1.0f || scy != 1.0f) {
268 if (shx != 0.0f || shy != 0.0f) {
279 if (Math.abs(cos) < ZERO) {
281 sin = sin > 0.0f ? 1.0f : -1.0f;
283 if (Math.abs(sin) < ZERO) {
285 cos = cos > 0.0f ? 1.0f : -1.0f;
297 m02 = px * (1.0f - m00) + py * m10;
298 m12 = py * (1.0f - m00) - px * m10;
332 tR.m00 * tL.m00 + tR.m10 * tL.m01,
333 tR.m00 * tL.m10 + tR.m10 * tL.m11,
334 tR.m01 * tL.m00 + tR.m11 * tL.m01,
335 tR.m01 * tL.m10 + tR.m11 * tL.m11,
336 tR.m02 * tL.m00 + tR.m12 * tL.m01 + tL.m02,
337 tR.m02 * tL.m10 + tR.m12 * tL.m11 + tL.m12);
355 tR.m00 * m00 + tR.m10 * m01,
356 tR.m00 * m10 + tR.m10 * m11,
357 tR.m01 * m00 + tR.m11 * m01,
358 tR.m01 * m10 + tR.m11 * m11,
359 tR.m02 * m00 + tR.m12 * m01 + m02,
360 tR.m02 * m10 + tR.m12 * m11 + m12);
379 m00 * tL.m00 + m10 * tL.m01,
380 m00 * tL.m10 + m10 * tL.m11,
381 m01 * tL.m00 + m11 * tL.m01,
382 m01 * tL.m10 + m11 * tL.m11,
383 m02 * tL.m00 + m12 * tL.m01 + tL.m02,
384 m02 * tL.m10 + m12 * tL.m11 + tL.m12);
390 if (Math.abs(det) < ZERO) {
398 (m01 * m12 - m11 * m02) / det,
399 (m10 * m02 - m00 * m12) / det
412 dst.
setSize(lo.x() * m00 + lo.y() * m01 + m02, lo.x() * m10 + lo.y() * m11 + m12, lo.z(),
413 hi.x() * m00 + hi.y() * m01 + m02, hi.x() * m10 + hi.y() * m11 + m12, hi.z());
423 final float x = src.
x();
424 final float y = src.
y();
425 dst.
setCoord(x * m00 + y * m01 + m02, x * m10 + y * m11 + m12, src.
z());
430 while (--length >= 0) {
431 final Vertex srcPoint = src[srcOff++];
432 final Vertex dstPoint = dst[dstOff];
433 if (dstPoint ==
null) {
434 throw new IllegalArgumentException(
"dst["+dstOff+
"] is null");
436 final float x = srcPoint.
x();
437 final float y = srcPoint.
y();
438 dstPoint.
setCoord(x * m00 + y * m01 + m02, x * m10 + y * m11 + m12, srcPoint.
z());
439 dst[dstOff++] = dstPoint;
448 public final float[]
transform(
final float[] src,
final float[] dst) {
449 final float x = src[0];
450 final float y = src[1];
451 dst[0] = x * m00 + y * m01 + m02;
452 dst[1] = x * m10 + y * m11 + m12;
456 public final void transform(
final float[] src,
final int srcOff,
final float[] dst,
final int dstOff) {
457 final float x = src[srcOff + 0];
458 final float y = src[srcOff + 1];
459 dst[dstOff + 0] = x * m00 + y * m01 + m02;
460 dst[dstOff + 1] = x * m10 + y * m11 + m12;
463 public final void transform(
final float[] src,
int srcOff,
final float[] dst,
int dstOff,
int length) {
465 if (src == dst && srcOff < dstOff && dstOff < srcOff + length * 2) {
466 srcOff = srcOff + length * 2 - 2;
467 dstOff = dstOff + length * 2 - 2;
470 while (--length >= 0) {
471 final float x = src[srcOff + 0];
472 final float y = src[srcOff + 1];
473 dst[dstOff + 0] = x * m00 + y * m01 + m02;
474 dst[dstOff + 1] = x * m10 + y * m11 + m12;
486 final float x = src.x();
487 final float y = src.y();
488 dst.
setX( x * m00 + y * m01 + m02 );
489 dst.
setY( x * m10 + y * m11 + m12 );
499 final float x = src.x();
500 final float y = src.y();
501 dst.
setX( x * m00 + y * m01 + m02 );
502 dst.
setY( x * m10 + y * m11 + m12 );
514 final float x = src.
x();
515 final float y = src.
y();
516 dst.
setCoord(x * m00 + y * m01, x * m10 + y * m11, src.
z());
520 public final void deltaTransform(
final float[] src,
int srcOff,
final float[] dst,
int dstOff,
int length) {
521 while (--length >= 0) {
522 final float x = src[srcOff++];
523 final float y = src[srcOff++];
524 dst[dstOff++] = x * m00 + y * m01;
525 dst[dstOff++] = x * m10 + y * m11;
538 if (Math.abs(det) < ZERO) {
541 final float x = src.x() - m02;
542 final float y = src.y() - m12;
543 dst.setCoord((x * m11 - y * m01) / det, (y * m00 - x * m10) / det, src.z());
547 public final void inverseTransform(
final float[] src,
int srcOff,
final float[] dst,
int dstOff,
int length)
551 if (Math.abs(det) < ZERO) {
555 while (--length >= 0) {
556 final float x = src[srcOff++] - m02;
557 final float y = src[srcOff++] - m12;
558 dst[dstOff++] = (x * m11 - y * m01) / det;
559 dst[dstOff++] = (y * m00 - x * m10) / det;
566 getClass().getName() +
567 "[[" + m00 +
", " + m01 +
", " + m02 +
"], ["
568 + m10 +
", " + m11 +
", " + m12 +
"]]";
584 public final boolean equals(
final Object obj) {
591 m00 == t.m00 && m01 == t.m01 &&
592 m02 == t.m02 && m10 == t.m10 &&
593 m11 == t.m11 && m12 == t.m12;
599 throw new InternalError(
"hashCode not designed");
A Vertex exposing Vec3f vertex- and texture-coordinates.
final void setCoord(final Vec3f coord)
Basic Float math utility functions.
static float sin(final float a)
static float cos(final float a)
2D Vector based upon two float components.
3D Vector based upon three float components.
Axis Aligned Bounding Box.
final Vec3f getHigh()
Returns the maximum right-top-near (xyz) coordinate.
final Vec3f getLow()
Returns the minimum left-bottom-far (xyz) coordinate.
final AABBox setSize(final float[] low, final float[] high)
Set size of the AABBox specifying the coordinates of the low and high.