/**
* Copyright (c) 2009-2011, chunquedong(YangJiandong)
*
* This file is part of ChunMap project
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE(Version >=3)
*
* History:
* 2010-05-05 Jed Young Creation
*/
package chunmap.model.relate.relateop;
import static org.junit.Assert.*;
import org.junit.Test;
import chunmap.model.geom.Geometry;
import chunmap.model.geom.LineString;
import chunmap.model.geom.Polygon;
import chunmap.model.geom.WktReader;
import chunmap.model.relate.ComputeIm;
import chunmap.model.relate.IntersectionMatrix;
public class LineString_PolygonTest {
@Test
public void testGetIM() {
WktReader wkt = new WktReader();
Geometry g = wkt.read("POLYGON((1 2,3 1,4 0,3 -2,0 0,1 2))");
Polygon pg = (Polygon) g;
Geometry g2 = wkt.read("LINESTRING(1 1,1 2,2 2,3 2)");
LineString ls = (LineString) g2;
// IntersectionMatrix rt2 = ComputeIm.getInstance().getIM(ls, pg);
LineString_Polygon l2a = new LineString_Polygon(ls, pg);
IntersectionMatrix rt = l2a.getIM();
assertTrue(rt.match(IntersectionMatrix.CrossesPattern));
}
@Test
public void testGetIM2() {
WktReader wkt = new WktReader();
Geometry g = wkt
.read("POLYGON((-5.0 -8.0,10.0 -20.0,20.0 15.0,-10.0 10.0,-5.0 -8.0),(1.0 2.0,3.0 1.0,4.0 0.0,3.0 -2.0,0.0 0.0,1.0 2.0))");
Polygon pg = (Polygon) g;
Geometry g2 = wkt
.read("LINESTRING(1.0 0.5,3.0 0.5,3.5 0.0,3.0 -1.0,1.0 0.0,1.0 0.5)");
LineString ls = (LineString) g2;
// IntersectionMatrix rt = ComputeIm.getInstance().getIM(ls, pg);
LineString_Polygon l2a = new LineString_Polygon(ls, pg);
IntersectionMatrix rt = l2a.getIM();
assertTrue(rt.match(IntersectionMatrix.DisjointPattern));
}
@Test
public void testGetIM3() {
WktReader wkt = new WktReader();
Geometry g = wkt
.read("POLYGON((1.0 0.5,3.0 0.5,3.5 0.0,3.0 -1.0,1.0 0.0,1.0 0.5))");
Polygon pg = (Polygon) g;
Geometry g2 = wkt
.read("LINESTRING(1.0 2.0,3.0 1.0,4.0 0.0,3.0 -2.0,0.0 0.0,1.0 2.0)");
LineString ls = (LineString) g2;
// IntersectionMatrix rt = ComputeIm.getInstance().getIM(ls, pg);
LineString_Polygon l2a = new LineString_Polygon(ls, pg);
IntersectionMatrix rt = l2a.getIM();
assertTrue(rt.match(IntersectionMatrix.DisjointPattern));
}
@Test
public void testGetIM4() {
WktReader wkt = new WktReader();
Geometry g = wkt
.read("POLYGON((1.0 2.0,3.0 1.0,4.0 0.0,3.0 -2.0,0.0 0.0,1.0 2.0))");
Polygon pg = (Polygon) g;
Geometry g2 = wkt
.read("LINESTRING(4.0 0.5,6.0 0.5,6.5 0.0,6.0 -1.0,4.0 0.0,4.0 0.5)");
LineString ls = (LineString) g2;
// IntersectionMatrix rt = ComputeIm.getInstance().getIM(ls, pg);
LineString_Polygon l2a = new LineString_Polygon(ls, pg);
IntersectionMatrix rt = l2a.getIM();
assertTrue(rt.get(IntersectionMatrix.Inner, IntersectionMatrix.Inner) == IntersectionMatrix.EmptyDim);
}
@Test
public void testGetIM5() {
WktReader wkt = new WktReader();
Geometry g = wkt.read("LINESTRING(2.0 2.0,0.0 0.0)");
Geometry g2 = wkt
.read("POLYGON((0.98 0.94,1.0466666666666666 0.94,1.0466666666666666 1.0066666666666666,0.98 1.0066666666666666,0.98 0.94))");
LineString ls = (LineString) g;
Polygon pg = (Polygon) g2;
// IntersectionMatrix rt = ComputeIm.getInstance().getIM(ls, pg);
LineString_Polygon l2a = new LineString_Polygon(ls, pg);
IntersectionMatrix rt = l2a.getIM();
assertTrue(rt.get(IntersectionMatrix.Inner, IntersectionMatrix.Inner) != IntersectionMatrix.EmptyDim);
}
@Test
public void testGetIM6() {
WktReader wkt = new WktReader();
Geometry g = wkt
.read("LINESTRING(1.0 6.0,5.999998414659173 1.0039816335536662,1.0079632645824341 -3.999993658637697,-3.9999857319385903 0.9880551094385923,1.0 6.0)");
Geometry g2 = wkt
.read("POLYGON((-2.639991350383829 -1.7999950537374092,-1.8399918576928131 -1.7999950537374092,-1.8399918576928131 -0.9999955610463935,-2.639991350383829 -0.9999955610463935,-2.639991350383829 -1.7999950537374092))");
LineString ls = (LineString) g;
Polygon pg = (Polygon) g2;
LineString_LinearRing l2a = new LineString_LinearRing(ls, pg.getShell());
IntersectionMatrix rt = l2a.getIM();
assertTrue(rt.get(IntersectionMatrix.Inner, IntersectionMatrix.Inner) != IntersectionMatrix.EmptyDim);
}
@Test
public void testGetIM7() {
WktReader wkt = new WktReader();
Geometry g = wkt
.read("LINESTRING(1.0 6.0,5.999998414659173 1.0039816335536662,1.0079632645824341 -3.999993658637697,-3.9999857319385903 0.9880551094385923,1.0 6.0)");
Geometry g2 = wkt
.read("POLYGON((3.3400048574815147 -2.1999948000829175,4.140004350172529 -2.1999948000829175,4.140004350172529 -1.399995307391901,3.3400048574815147 -1.399995307391901,3.3400048574815147 -2.1999948000829175))");
LineString ls = (LineString) g;
Polygon pg = (Polygon) g2;
// IntersectionMatrix rt = ComputeIm.getInstance().getIM(ls, pg);
LineString_LinearRing l2a = new LineString_LinearRing(ls, pg.getShell());
IntersectionMatrix rt = l2a.getIM();
assertTrue(rt.get(IntersectionMatrix.Inner, IntersectionMatrix.Inner) != IntersectionMatrix.EmptyDim);
}
}