use of org.opengis.geometry.Envelope in project sis by apache.
the class SpecializableTransformTest method create.
/**
* Creates a transform to test.
*
* @throws IllegalArgumentException if {@link SpecializableTransform} constructor rejects a parameter.
*/
private static SpecializableTransform create(final boolean is2D) {
final Map<Envelope, MathTransform> specializations = new HashMap<>(4);
assertNull(specializations.put(new Envelope2D(null, -5, -4, 10, 7), translation(0.1)));
assertNull(specializations.put(new Envelope2D(null, -3, -1, 5, 2), translation(0.2)));
final MathTransform global = translation(0);
if (is2D) {
return new SpecializableTransform2D(global, specializations);
}
return new SpecializableTransform(global, specializations);
}
use of org.opengis.geometry.Envelope in project sis by apache.
the class AbstractEnvelopeTest method testCrossingAntiMeridianTwice.
/**
* Tests a the anti-meridian case with a larger empty space
* on the left side.
*
* {@preformat text
* ───┐ ┌───────── ───┐ ┌─────
* │ │ ┌────┐ or ───┼──┐ │ ┌──
* │ │ └────┘ ───┼──┘ │ └──
* ───┘ └───────── ───┘ └─────
* }
*/
@Test
public void testCrossingAntiMeridianTwice() {
final DirectPosition2D inside = new DirectPosition2D(18, 32);
final DirectPosition2D outside = new DirectPosition2D(3, 32);
final Envelope2D contained = (Envelope2D) create(RECTANGLE, 14, 16, 35, 40);
final Envelope2D intersect = (Envelope2D) create(RECTANGLE, -2, 16, 35, 40);
final Envelope2D disjoint = (Envelope2D) create(RECTANGLE, -2, 10, 35, 40);
final Envelope2D spanning = (Envelope2D) create(RECTANGLE, 16, -8, 35, 40);
for (int type = 0; type < LAST; type++) {
final String label = "Type " + type;
final Envelope envelope = create(type, 12, -364, 30, 50);
final DirectPosition lower = envelope.getLowerCorner();
final DirectPosition upper = envelope.getUpperCorner();
assertEquals(label, 30, envelope.getMinimum(1), STRICT);
assertEquals(label, 50, envelope.getMaximum(1), STRICT);
assertEquals(label, 40, envelope.getMedian(1), STRICT);
assertEquals(label, 20, envelope.getSpan(1), STRICT);
assertEquals(label, 12, lower.getOrdinate(0), STRICT);
assertEquals(label, -180, envelope.getMinimum(0), STRICT);
assertEquals(label, -364, upper.getOrdinate(0), STRICT);
assertEquals(label, +180, envelope.getMaximum(0), STRICT);
// Note the alternance with the previous test methods.
assertEquals(label, 4, envelope.getMedian(0), STRICT);
// testCrossingAntiMeridian() + 360°.
assertEquals(label, NaN, envelope.getSpan(0), STRICT);
if (envelope instanceof AbstractEnvelope) {
final AbstractEnvelope ext = (AbstractEnvelope) envelope;
assertTrue(label, ext.contains(inside));
assertFalse(label, ext.contains(outside));
assertFalse(label, ext.contains(intersect, false));
assertTrue(label, ext.intersects(intersect, false));
assertFalse(label, ext.contains(spanning, false));
assertTrue(label, ext.intersects(spanning, false));
assertDisjoint(ext, disjoint);
assertContains(ext, contained);
break;
}
if (envelope instanceof Rectangle2D) {
final Rectangle2D ext = (Rectangle2D) envelope;
assertTrue(label, ext.contains(inside));
assertFalse(label, ext.contains(outside));
assertFalse(label, ext.contains(intersect));
assertTrue(label, ext.intersects(intersect));
assertFalse(label, ext.contains(spanning));
assertTrue(label, ext.intersects(spanning));
assertDisjoint(ext, disjoint);
assertContains(ext, contained);
break;
}
verifyInvariants(type, envelope);
}
}
use of org.opengis.geometry.Envelope in project sis by apache.
the class AbstractEnvelopeTest method testCrossingAntiMeridian.
/**
* Tests a case crossing the anti-meridian.
*
* {@preformat text
* ─────┐ ┌───────── ─────┐ ┌─────
* │ │ ┌────┐ or ──┐ │ │ ┌──
* │ │ └────┘ ──┘ │ │ └──
* ─────┘ └───────── ─────┘ └─────
* }
*/
@Test
public void testCrossingAntiMeridian() {
final DirectPosition2D inside = new DirectPosition2D(18, 32);
final DirectPosition2D outside = new DirectPosition2D(3, 32);
final Envelope2D contained = (Envelope2D) create(RECTANGLE, 14, 16, 35, 40);
final Envelope2D intersect = (Envelope2D) create(RECTANGLE, -2, 16, 35, 40);
final Envelope2D disjoint = (Envelope2D) create(RECTANGLE, -2, 10, 35, 40);
final Envelope2D spanning = (Envelope2D) create(RECTANGLE, 16, -8, 35, 40);
for (int type = 0; type < LAST; type++) {
final String label = "Type " + type;
final Envelope envelope = create(type, 12, -4, 30, 50);
final DirectPosition lower = envelope.getLowerCorner();
final DirectPosition upper = envelope.getUpperCorner();
assertEquals(label, 30, envelope.getMinimum(1), STRICT);
assertEquals(label, 50, envelope.getMaximum(1), STRICT);
assertEquals(label, 40, envelope.getMedian(1), STRICT);
assertEquals(label, 20, envelope.getSpan(1), STRICT);
assertEquals(label, 12, lower.getOrdinate(0), STRICT);
assertEquals(label, -180, envelope.getMinimum(0), STRICT);
assertEquals(label, -4, upper.getOrdinate(0), STRICT);
assertEquals(label, +180, envelope.getMaximum(0), STRICT);
assertEquals(label, -176, envelope.getMedian(0), STRICT);
// 360° - testSimpleEnvelope()
assertEquals(label, 344, envelope.getSpan(0), STRICT);
switch(type) {
default:
{
final AbstractEnvelope ext = (AbstractEnvelope) envelope;
assertTrue(label, ext.contains(inside));
assertFalse(label, ext.contains(outside));
assertFalse(label, ext.contains(intersect, false));
assertTrue(label, ext.intersects(intersect, false));
assertDisjoint(ext, disjoint);
assertContains(ext, contained);
assertContains(ext, spanning);
break;
}
case RECTANGLE:
{
final Rectangle2D ext = (Rectangle2D) envelope;
assertTrue(label, ext.contains(inside));
assertFalse(label, ext.contains(outside));
assertFalse(label, ext.contains(intersect));
assertTrue(label, ext.intersects(intersect));
assertDisjoint(ext, disjoint);
assertContains(ext, contained);
assertContains(ext, spanning);
break;
}
}
verifyInvariants(type, envelope);
}
}
use of org.opengis.geometry.Envelope in project sis by apache.
the class AbstractEnvelopeTest method testRange0.
/**
* Tests an empty envelope from -0 to 0°
*/
@Test
public void testRange0() {
final DirectPosition2D wasInside = new DirectPosition2D(18, 32);
final DirectPosition2D outside = new DirectPosition2D(3, 32);
final Envelope2D wasContained = (Envelope2D) create(RECTANGLE, 14, 16, 35, 40);
final Envelope2D intersect = (Envelope2D) create(RECTANGLE, -2, 16, 35, 40);
final Envelope2D spanning = (Envelope2D) create(RECTANGLE, 16, -8, 35, 40);
for (int type = 0; type < LAST; type++) {
final String label = "Type " + type;
final Envelope envelope = create(type, -0.0, 0.0, 30, 50);
assertEquals(label, 30, envelope.getMinimum(1), STRICT);
assertEquals(label, 50, envelope.getMaximum(1), STRICT);
assertEquals(label, 40, envelope.getMedian(1), STRICT);
assertEquals(label, 20, envelope.getSpan(1), STRICT);
assertEquals(label, -0.0, envelope.getMinimum(0), STRICT);
assertEquals(label, 0.0, envelope.getMaximum(0), STRICT);
assertEquals(label, 0, envelope.getMedian(0), STRICT);
assertEquals(label, 0, envelope.getSpan(0), STRICT);
switch(type) {
default:
{
final AbstractEnvelope ext = (AbstractEnvelope) envelope;
assertFalse(label, ext.contains(wasInside));
assertFalse(label, ext.contains(outside));
assertFalse(label, ext.contains(intersect, false));
assertTrue(label, ext.intersects(intersect, false));
assertFalse(label, ext.contains(spanning, false));
assertFalse(label, ext.intersects(spanning, false));
assertFalse(label, ext.intersects(spanning, false));
assertDisjoint(ext, wasContained);
break;
}
case RECTANGLE:
{
final Rectangle2D ext = (Rectangle2D) envelope;
assertFalse(label, ext.contains(wasInside));
assertFalse(label, ext.contains(outside));
assertFalse(label, ext.contains(intersect));
assertTrue(label, ext.intersects(intersect));
assertFalse(label, ext.contains(spanning));
assertFalse(label, ext.intersects(spanning));
assertFalse(label, ext.intersects(spanning));
assertDisjoint(ext, wasContained);
break;
}
}
verifyInvariants(type, envelope);
}
}
use of org.opengis.geometry.Envelope in project sis by apache.
the class AbstractEnvelopeTest method testSimpleEnvelope.
/**
* Tests the simple case (no anti-meridian crossing).
*
* {@preformat text
* ┌─────────────┐
* │ ┌───────┐ │
* │ └───────┘ │
* └─────────────┘
* }
*/
@Test
public void testSimpleEnvelope() {
final DirectPosition2D inside = new DirectPosition2D(3, 32);
final DirectPosition2D outside = new DirectPosition2D(-5, 32);
final Envelope2D contained = (Envelope2D) create(RECTANGLE, -2, 10, 35, 40);
final Envelope2D intersect = (Envelope2D) create(RECTANGLE, -2, 16, 35, 40);
final Envelope2D disjoint = (Envelope2D) create(RECTANGLE, 14, 16, 35, 40);
for (int type = 0; type < LAST; type++) {
final String label = "Type " + type;
final Envelope envelope = create(type, -4, 12, 30, 50);
assertEquals(label, 30, envelope.getMinimum(1), STRICT);
assertEquals(label, 50, envelope.getMaximum(1), STRICT);
assertEquals(label, 40, envelope.getMedian(1), STRICT);
assertEquals(label, 20, envelope.getSpan(1), STRICT);
assertEquals(label, -4, envelope.getMinimum(0), STRICT);
assertEquals(label, 12, envelope.getMaximum(0), STRICT);
assertEquals(label, 4, envelope.getMedian(0), STRICT);
assertEquals(label, 16, envelope.getSpan(0), STRICT);
switch(type) {
default:
{
final AbstractEnvelope ext = (AbstractEnvelope) envelope;
assertTrue(label, ext.contains(inside));
assertFalse(label, ext.contains(outside));
assertFalse(label, ext.contains(intersect, false));
assertTrue(label, ext.intersects(intersect, false));
assertDisjoint(ext, disjoint);
assertContains(ext, contained);
break;
}
case RECTANGLE:
{
final Rectangle2D ext = (Rectangle2D) envelope;
assertTrue(label, ext.contains(inside));
assertFalse(label, ext.contains(outside));
assertFalse(label, ext.contains(intersect));
assertTrue(label, ext.intersects(intersect));
assertDisjoint(ext, disjoint);
assertContains(ext, contained);
break;
}
}
verifyInvariants(type, envelope);
}
}
Aggregations