|
1 | 1 | /* |
2 | | - * Copyright (c) 2009-2022 jMonkeyEngine |
| 2 | + * Copyright (c) 2009-2023 jMonkeyEngine |
3 | 3 | * All rights reserved. |
4 | 4 | * |
5 | 5 | * Redistribution and use in source and binary forms, with or without |
@@ -2460,6 +2460,75 @@ public void multLocal(Quaternion rotation) { |
2460 | 2460 | multLocal(matrix4f); |
2461 | 2461 | } |
2462 | 2462 |
|
| 2463 | + /** |
| 2464 | + * Tests for approximate equality with the specified matrix, using the |
| 2465 | + * specified tolerance. If {@code other} is null, false is returned. Either |
| 2466 | + * way, the current instance is unaffected. |
| 2467 | + * |
| 2468 | + * @param other the matrix to compare (unaffected) or null for none |
| 2469 | + * @param epsilon the tolerance for each element |
| 2470 | + * @return true if all 16 elements are within tolerance, otherwise false |
| 2471 | + */ |
| 2472 | + public boolean isSimilar(Matrix4f other, float epsilon) { |
| 2473 | + if (other == null) { |
| 2474 | + return false; |
| 2475 | + } |
| 2476 | + |
| 2477 | + if (Float.compare(Math.abs(other.m00 - m00), epsilon) > 0) { |
| 2478 | + return false; |
| 2479 | + } |
| 2480 | + if (Float.compare(Math.abs(other.m01 - m01), epsilon) > 0) { |
| 2481 | + return false; |
| 2482 | + } |
| 2483 | + if (Float.compare(Math.abs(other.m02 - m02), epsilon) > 0) { |
| 2484 | + return false; |
| 2485 | + } |
| 2486 | + if (Float.compare(Math.abs(other.m03 - m03), epsilon) > 0) { |
| 2487 | + return false; |
| 2488 | + } |
| 2489 | + |
| 2490 | + if (Float.compare(Math.abs(other.m10 - m10), epsilon) > 0) { |
| 2491 | + return false; |
| 2492 | + } |
| 2493 | + if (Float.compare(Math.abs(other.m11 - m11), epsilon) > 0) { |
| 2494 | + return false; |
| 2495 | + } |
| 2496 | + if (Float.compare(Math.abs(other.m12 - m12), epsilon) > 0) { |
| 2497 | + return false; |
| 2498 | + } |
| 2499 | + if (Float.compare(Math.abs(other.m13 - m13), epsilon) > 0) { |
| 2500 | + return false; |
| 2501 | + } |
| 2502 | + |
| 2503 | + if (Float.compare(Math.abs(other.m20 - m20), epsilon) > 0) { |
| 2504 | + return false; |
| 2505 | + } |
| 2506 | + if (Float.compare(Math.abs(other.m21 - m21), epsilon) > 0) { |
| 2507 | + return false; |
| 2508 | + } |
| 2509 | + if (Float.compare(Math.abs(other.m22 - m22), epsilon) > 0) { |
| 2510 | + return false; |
| 2511 | + } |
| 2512 | + if (Float.compare(Math.abs(other.m23 - m23), epsilon) > 0) { |
| 2513 | + return false; |
| 2514 | + } |
| 2515 | + |
| 2516 | + if (Float.compare(Math.abs(other.m30 - m30), epsilon) > 0) { |
| 2517 | + return false; |
| 2518 | + } |
| 2519 | + if (Float.compare(Math.abs(other.m31 - m31), epsilon) > 0) { |
| 2520 | + return false; |
| 2521 | + } |
| 2522 | + if (Float.compare(Math.abs(other.m32 - m32), epsilon) > 0) { |
| 2523 | + return false; |
| 2524 | + } |
| 2525 | + if (Float.compare(Math.abs(other.m33 - m33), epsilon) > 0) { |
| 2526 | + return false; |
| 2527 | + } |
| 2528 | + |
| 2529 | + return true; |
| 2530 | + } |
| 2531 | + |
2463 | 2532 | /** |
2464 | 2533 | * Creates a copy. The current instance is unaffected. |
2465 | 2534 | * |
|
0 commit comments