|
| 1 | +/* |
| 2 | + * Copyright (c) 2024 jMonkeyEngine |
| 3 | + * All rights reserved. |
| 4 | + * |
| 5 | + * Redistribution and use in source and binary forms, with or without |
| 6 | + * modification, are permitted provided that the following conditions are |
| 7 | + * met: |
| 8 | + * |
| 9 | + * * Redistributions of source code must retain the above copyright |
| 10 | + * notice, this list of conditions and the following disclaimer. |
| 11 | + * |
| 12 | + * * Redistributions in binary form must reproduce the above copyright |
| 13 | + * notice, this list of conditions and the following disclaimer in the |
| 14 | + * documentation and/or other materials provided with the distribution. |
| 15 | + * |
| 16 | + * * Neither the name of 'jMonkeyEngine' nor the names of its contributors |
| 17 | + * may be used to endorse or promote products derived from this software |
| 18 | + * without specific prior written permission. |
| 19 | + * |
| 20 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 21 | + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
| 22 | + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 23 | + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
| 24 | + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 25 | + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 26 | + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 27 | + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 28 | + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 29 | + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 30 | + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 31 | + */ |
| 32 | +package com.jme3.bounding; |
| 33 | + |
| 34 | +import com.jme3.math.Vector3f; |
| 35 | +import org.junit.Assert; |
| 36 | +import org.junit.Test; |
| 37 | + |
| 38 | +/** |
| 39 | + * Test cases for the BoundingBox class. |
| 40 | + * |
| 41 | + * @author Stephen Gold |
| 42 | + */ |
| 43 | +public class TestBoundingBox { |
| 44 | + /** |
| 45 | + * Verify that equals() behaves as expected. |
| 46 | + */ |
| 47 | + @Test |
| 48 | + public void testEquals() { |
| 49 | + BoundingBox bb1 = new BoundingBox(new Vector3f(3f, 4f, 5f), 0f, 1f, 2f); |
| 50 | + BoundingBox bb2 |
| 51 | + = new BoundingBox(new Vector3f(3f, 4f, 5f), -0f, 1f, 2f); |
| 52 | + |
| 53 | + BoundingBox bb3 = new BoundingBox(new Vector3f(3f, 0f, 2f), 9f, 8f, 7f); |
| 54 | + BoundingBox bb4 |
| 55 | + = new BoundingBox(new Vector3f(3f, -0f, 2f), 9f, 8f, 7f); |
| 56 | + |
| 57 | + BoundingBox bb5 = new BoundingBox(new Vector3f(4f, 5f, 6f), 9f, 8f, 7f); |
| 58 | + BoundingBox bb6 = (BoundingBox) bb5.clone(); |
| 59 | + bb6.setCheckPlane(1); |
| 60 | + |
| 61 | + // Clones are equal to their base instances: |
| 62 | + Assert.assertEquals(bb1, bb1.clone()); |
| 63 | + Assert.assertEquals(bb2, bb2.clone()); |
| 64 | + Assert.assertEquals(bb3, bb3.clone()); |
| 65 | + Assert.assertEquals(bb4, bb4.clone()); |
| 66 | + Assert.assertEquals(bb5, bb5.clone()); |
| 67 | + Assert.assertEquals(bb6, bb6.clone()); |
| 68 | + |
| 69 | + Assert.assertNotEquals(bb1, bb2); // because their extents differ |
| 70 | + Assert.assertNotEquals(bb3, bb4); // because their centers differ |
| 71 | + Assert.assertEquals(bb5, bb6); // because check planes are ignored |
| 72 | + } |
| 73 | + |
| 74 | + /** |
| 75 | + * Verify that isSimilar() behaves as expected. |
| 76 | + */ |
| 77 | + @Test |
| 78 | + public void testIsSimilar() { |
| 79 | + BoundingBox bb1 = new BoundingBox(new Vector3f(3f, 4f, 5f), 0f, 1f, 2f); |
| 80 | + BoundingBox bb2 |
| 81 | + = new BoundingBox(new Vector3f(3f, 4f, 5f), 0f, 1.1f, 2f); |
| 82 | + |
| 83 | + BoundingBox bb3 = new BoundingBox(new Vector3f(3f, 4f, 2f), 9f, 8f, 7f); |
| 84 | + BoundingBox bb4 |
| 85 | + = new BoundingBox(new Vector3f(3f, 3.9f, 2f), 9f, 8f, 7f); |
| 86 | + |
| 87 | + BoundingBox bb5 = new BoundingBox(new Vector3f(4f, 5f, 6f), 9f, 8f, 7f); |
| 88 | + BoundingBox bb6 = (BoundingBox) bb5.clone(); |
| 89 | + bb6.setCheckPlane(1); |
| 90 | + |
| 91 | + Assert.assertFalse(bb1.isSimilar(bb2, 0.09999f)); |
| 92 | + Assert.assertTrue(bb1.isSimilar(bb2, 0.10001f)); |
| 93 | + |
| 94 | + Assert.assertFalse(bb3.isSimilar(bb4, 0.09999f)); |
| 95 | + Assert.assertTrue(bb3.isSimilar(bb4, 0.10001f)); |
| 96 | + |
| 97 | + Assert.assertTrue(bb5.isSimilar(bb6, 0f)); // check planes are ignored |
| 98 | + } |
| 99 | +} |
0 commit comments