Skip to content

Commit 2407d0b

Browse files
mbasmanovastolstov
authored andcommitted
Fix Envelope#intersect when other is empty (#168)
Thanks!
1 parent 27adbbb commit 2407d0b

2 files changed

Lines changed: 52 additions & 1 deletion

File tree

src/main/java/com/esri/core/geometry/Envelope2D.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,8 +321,10 @@ public boolean isIntersecting(double xmin_, double ymin_, double xmax_, double y
321321
* envelope to empty state and returns False.
322322
*/
323323
public boolean intersect(Envelope2D other) {
324-
if (isEmpty() || other.isEmpty())
324+
if (isEmpty() || other.isEmpty()) {
325+
setEmpty();
325326
return false;
327+
}
326328

327329
if (other.xmin > xmin)
328330
xmin = other.xmin;
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
package com.esri.core.geometry;
15+
16+
import org.junit.Test;
17+
18+
import static org.junit.Assert.assertEquals;
19+
import static org.junit.Assert.assertFalse;
20+
import static org.junit.Assert.assertTrue;
21+
22+
public class TestEnvelope
23+
{
24+
@Test
25+
public void testIntersect()
26+
{
27+
assertIntersection(new Envelope(0, 0, 5, 5), new Envelope(0, 0, 5, 5), new Envelope(0, 0, 5, 5));
28+
assertIntersection(new Envelope(0, 0, 5, 5), new Envelope(1, 1, 6, 6), new Envelope(1, 1, 5, 5));
29+
assertIntersection(new Envelope(1, 2, 3, 4), new Envelope(0, 0, 2, 3), new Envelope(1, 2, 2, 3));
30+
31+
assertNoIntersection(new Envelope(), new Envelope());
32+
assertNoIntersection(new Envelope(0, 0, 5, 5), new Envelope());
33+
assertNoIntersection(new Envelope(), new Envelope(0, 0, 5, 5));
34+
}
35+
36+
private static void assertIntersection(Envelope envelope, Envelope other, Envelope intersection)
37+
{
38+
boolean intersects = envelope.intersect(other);
39+
assertTrue(intersects);
40+
assertEquals(envelope, intersection);
41+
}
42+
43+
private static void assertNoIntersection(Envelope envelope, Envelope other)
44+
{
45+
boolean intersects = envelope.intersect(other);
46+
assertFalse(intersects);
47+
assertTrue(envelope.isEmpty());
48+
}
49+
}

0 commit comments

Comments
 (0)