|
21 | 21 |
|
22 | 22 | public class TestEnvelope |
23 | 23 | { |
| 24 | + @Test |
| 25 | + /**The function returns the x and y coordinates of the center of the envelope. |
| 26 | + * If the envelope is empty the point is set to empty otherwise the point is set to the center of the envelope. |
| 27 | + */ |
| 28 | + public void testGetCeneter(){ |
| 29 | + //xmin,ymin,xmax,ymax of envelope |
| 30 | + Envelope env1 = new Envelope(1,1, 2, 4); |
| 31 | + Envelope env2 = new Envelope(); |
| 32 | + Point p = new Point(); |
| 33 | + Point p1 = new Point(1,2); |
| 34 | + |
| 35 | + /**Tests if the point is correctly set to the center of the envelope, */ |
| 36 | + env1.getCenter(p); |
| 37 | + assertTrue(p.getX() == 1.5); |
| 38 | + |
| 39 | + /** Tests if the point is empty because of the envelope is empty */ |
| 40 | + env2.getCenter(p1); |
| 41 | + assertTrue(p1.isEmpty()); |
| 42 | + } |
| 43 | + @Test |
| 44 | + /* Merge takes a Point as input and increas the bouandary of the envelope to contain the point. |
| 45 | + *If the point is empty the envelope remains the same or if the envelope is empty the coordinates |
| 46 | + *of the point is assigned to the envelope */ |
| 47 | + public void testMerge(){ |
| 48 | + |
| 49 | + /* To increase the covarege the branch where the envelope is empty can be tested |
| 50 | + * And that the envelope and the point is not empty */ |
| 51 | + Envelope env1 = new Envelope(1,1, 2, 4); |
| 52 | + Envelope env2 = new Envelope(1,1, 2, 4); |
| 53 | + Envelope env3 = new Envelope(1,1, 2, 4); |
| 54 | + Point p = new Point(100,4); |
| 55 | + |
| 56 | + /*This should be false since env1 should change depending on point p */ |
| 57 | + env1.merge(p); |
| 58 | + assertFalse(env1.equals(env2)); |
| 59 | + |
| 60 | + /* This assert should be true since the point is empty and therefore env2 should not change */ |
| 61 | + Point p1 = new Point(); |
| 62 | + env2.merge(p1); |
| 63 | + assertTrue(env2.equals(env3)); |
| 64 | + } |
| 65 | + |
| 66 | + |
| 67 | + @Test |
| 68 | + /** TESTEST ENVELOPE2D ** |
| 69 | + * ClipLine modify a line to be inside a envelope if possible */ |
| 70 | + public void TestClipLine(){ |
| 71 | + |
| 72 | + //checking if segPrama is 0 and the segment is outside of the clipping window |
| 73 | + //covers first return |
| 74 | + Envelope2D env0 = new Envelope2D(1, 1, 4, 4); |
| 75 | + // Reaches the branch where the delta is 0 |
| 76 | + Point2D p1 = new Point2D(2,2); |
| 77 | + Point2D p2 = new Point2D(2,2); |
| 78 | + |
| 79 | + int lineExtension = 0; |
| 80 | + double[] segParams = {3,4}; |
| 81 | + //reaches the branch where boundaryDistances is not 0 |
| 82 | + double[] boundaryDistances = {2.0, 3.0}; |
| 83 | + |
| 84 | + int a = env0.clipLine(p1, p2, lineExtension, segParams, boundaryDistances); |
| 85 | + //should be true since the points are inside the envelope |
| 86 | + assertTrue(a == 4); |
| 87 | + |
| 88 | + // Changes p3 to fit the envelop, the line is on the edge of the envelope |
| 89 | + Envelope2D env1 = new Envelope2D(1, 1, 4, 4); |
| 90 | + Point2D p3 = new Point2D(1,10); |
| 91 | + Point2D p4 = new Point2D(1,1); |
| 92 | + |
| 93 | + int b = env1.clipLine(p3, p4, lineExtension, segParams, boundaryDistances); |
| 94 | + assertTrue(b == 1); |
| 95 | + // the second point is outside and therefore changed |
| 96 | + Envelope2D env2 = new Envelope2D(1, 1, 4, 4); |
| 97 | + Point2D p5 = new Point2D(2,2); |
| 98 | + Point2D p6 = new Point2D(1,10); |
| 99 | + |
| 100 | + int c = env2.clipLine(p5, p6, lineExtension, segParams, boundaryDistances); |
| 101 | + assertTrue(c == 2); |
| 102 | + |
| 103 | + //Both points is outside the envelope and therefore no line is possible to clip, and this should return 0 |
| 104 | + Envelope2D env3 = new Envelope2D(1, 1, 4, 4); |
| 105 | + Point2D p7 = new Point2D(11,10); |
| 106 | + Point2D p8 = new Point2D(5,5); |
| 107 | + |
| 108 | + int d = env3.clipLine(p7, p8, lineExtension, segParams, boundaryDistances); |
| 109 | + assertTrue(d == 0); |
| 110 | + } |
| 111 | + |
| 112 | + @Test |
| 113 | + public void testSqrDistances(){ |
| 114 | + //the point is on the envelope, which means that the distance is 0 |
| 115 | + Envelope2D env0 = new Envelope2D(1, 1, 4, 4); |
| 116 | + Point2D p0 = new Point2D(4,4); |
| 117 | + assertTrue(env0.sqrDistance(p0) == 0.0); |
| 118 | + |
| 119 | + Envelope2D env1 = new Envelope2D(1, 1, 4, 4); |
| 120 | + Point2D p1 = new Point2D(1,0); |
| 121 | + |
| 122 | + assertTrue(env0.sqrDistance(p1) == 1.0); |
| 123 | + |
| 124 | + } |
24 | 125 | @Test |
25 | 126 | public void testIntersect() { |
26 | 127 | assertIntersection(new Envelope(0, 0, 5, 5), new Envelope(0, 0, 5, 5), new Envelope(0, 0, 5, 5)); |
|
0 commit comments