3 <script src="../../lib/OpenLayers.js"></script>
4 <script type="text/javascript">
7 function test_MultiLineString_constructor (t) {
9 mline = new OpenLayers.Geometry.MultiLineString();
10 t.ok( mline instanceof OpenLayers.Geometry.MultiLineString, "new OpenLayers.Geometry.MultiLineString returns mline object" );
11 t.eq( mline.CLASS_NAME, "OpenLayers.Geometry.MultiLineString", "mline.CLASS_NAME is set correctly");
12 t.eq( mline.components, [], "line.components is set correctly");
15 function test_MultiLineString_constructor (t) {
17 line = new OpenLayers.Geometry.LineString();
18 mline = new OpenLayers.Geometry.MultiLineString(line);
19 t.ok( mline instanceof OpenLayers.Geometry.MultiLineString, "new OpenLayers.Geometry.MultiLineString returns mline object" );
20 t.eq( mline.CLASS_NAME, "OpenLayers.Geometry.MultiLineString", "mline.CLASS_NAME is set correctly");
21 t.eq( mline.components.length, 1, "mline.components.length is set correctly");
24 function test_split(t) {
25 var wkt = OpenLayers.Geometry.fromWKT;
28 msg: "no intersection",
29 g1: "MULTILINESTRING((0 0, 0 1), (2 2, 3 3))",
30 g2: "MULTILINESTRING((1 0, 1 1), (2 2, 3 2))",
33 msg: "intersection at midpoint",
34 g1: "MULTILINESTRING((0 0, 1 1))",
35 g2: "MULTILINESTRING((1 0, 0 1))",
36 exp: ["MULTILINESTRING((1 0, 0.5 0.5))", "MULTILINESTRING((0.5 0.5, 0 1))"]
38 msg: "intersection at midpoint (reverse source/target)",
39 g1: "MULTILINESTRING((1 0, 0 1))",
40 g2: "MULTILINESTRING((0 0, 1 1))",
41 exp: ["MULTILINESTRING((0 0, 0.5 0.5))", "MULTILINESTRING((0.5 0.5, 1 1))"]
43 msg: "intersection at endpoint",
44 g1: "MULTILINESTRING((0 0, 1 1))",
45 g2: "MULTILINESTRING((1 0, 1 1))",
48 msg: "midpoint intersection, no options",
49 g1: "MULTILINESTRING((0 0, 2 2))",
50 g2: "MULTILINESTRING((0 2, 2 0))",
51 exp: ["MULTILINESTRING((0 2, 1 1))", "MULTILINESTRING((1 1, 2 0))"]
53 msg: "midpoint intersection, edge false",
55 g1: "MULTILINESTRING((0 0, 2 2))",
56 g2: "MULTILINESTRING((0 2, 2 0))",
59 msg: "midpoint intersection, mutual",
61 g1: "MULTILINESTRING((0 0, 2 2))",
62 g2: "MULTILINESTRING((0 2, 2 0))",
63 exp: [["MULTILINESTRING((0 0, 1 1))", "MULTILINESTRING((1 1, 2 2))"], ["MULTILINESTRING((0 2, 1 1))", "MULTILINESTRING((1 1, 2 0))"]]
65 msg: "close intersection, no tolerance",
66 g1: "MULTILINESTRING((0 0, 0.9 0.9))",
67 g2: "MULTILINESTRING((0 2, 2 0))",
70 msg: "close intersection, within tolerance",
71 opt: {tolerance: 0.2},
72 g1: "MULTILINESTRING((0 0, 0.9 0.9))",
73 g2: "MULTILINESTRING((0 2, 2 0))",
74 exp: ["MULTILINESTRING((0 2, 0.9 0.9))", "MULTILINESTRING((0.9 0.9, 2 0))"]
76 msg: "multi source, single target",
77 g1: "MULTILINESTRING((0 0, 2 2))",
78 g2: "LINESTRING(0 2, 2 0)",
79 exp: ["LINESTRING(0 2, 1 1)", "LINESTRING(1 1, 2 0)"]
81 msg: "multi source, single target, mutual split",
83 g1: "MULTILINESTRING((0 0, 2 2))",
84 g2: "LINESTRING(0 2, 2 0)",
85 exp: [["MULTILINESTRING((0 0, 1 1))", "MULTILINESTRING((1 1, 2 2))"], ["LINESTRING(0 2, 1 1)", "LINESTRING(1 1, 2 0)"]]
87 msg: "single source, multi target",
88 g1: "LINESTRING(0 2, 2 0)",
89 g2: "MULTILINESTRING((0 0, 2 2))",
90 exp: ["MULTILINESTRING((0 0, 1 1))", "MULTILINESTRING((1 1, 2 2))"]
92 msg: "partial target split",
93 g1: "MULTILINESTRING((2 0, 0 2))",
94 g2: "MULTILINESTRING((0 0, 2 2), (3 3, 4 4))",
95 exp: ["MULTILINESTRING((0 0, 1 1))", "MULTILINESTRING((1 1, 2 2), (3 3, 4 4))"]
97 msg: "partial target split, mutual true",
99 g1: "MULTILINESTRING((2 0, 0 2))",
100 g2: "MULTILINESTRING((0 0, 2 2), (3 3, 4 4))",
101 exp: [["MULTILINESTRING((2 0, 1 1))", "MULTILINESTRING((1 1, 0 2))"], ["MULTILINESTRING((0 0, 1 1))", "MULTILINESTRING((1 1, 2 2), (3 3, 4 4))"]]
103 msg: "partial source split, mutual true",
105 g1: "MULTILINESTRING((0 0, 2 2), (3 3, 4 4))",
106 g2: "MULTILINESTRING((2 0, 0 2))",
107 exp: [["MULTILINESTRING((0 0, 1 1))", "MULTILINESTRING((1 1, 2 2), (3 3, 4 4))"], ["MULTILINESTRING((2 0, 1 1))", "MULTILINESTRING((1 1, 0 2))"]]
109 msg: "partial target split with source endpoint",
110 g1: "MULTILINESTRING((1 0, 1 1))",
111 g2: "MULTILINESTRING((0 0, 2 2), (3 3, 4 4))",
112 exp: ["MULTILINESTRING((0 0, 1 1))", "MULTILINESTRING((1 1, 2 2), (3 3, 4 4))"]
114 msg: "partial target split with source endpoint, mutual true",
116 g1: "MULTILINESTRING((5 5, 6 6), (1 0, 1 1))",
117 g2: "MULTILINESTRING((0 0, 2 2), (3 3, 4 4))",
118 exp: [[], ["MULTILINESTRING((0 0, 1 1))", "MULTILINESTRING((1 1, 2 2), (3 3, 4 4))"]]
120 msg: "partial source split with target endpoint",
121 g1: "MULTILINESTRING((0 0, 2 2), (3 3, 4 4))",
122 g2: "MULTILINESTRING((1 0, 1 1))",
125 msg: "partial source split with target endpoint, mutual true",
127 g1: "MULTILINESTRING((0 0, 2 2), (3 3, 4 4), (5 5, 6 6))",
128 g2: "MULTILINESTRING((1 0, 1 1))",
129 exp: [["MULTILINESTRING((0 0, 1 1))", "MULTILINESTRING((1 1, 2 2), (3 3, 4 4), (5 5, 6 6))"], []]
131 msg: "partial target and source split",
132 g1: "MULTILINESTRING((0 5, 2 5), (4 5, 6 5), (8 5, 10 5))",
133 g2: "MULTILINESTRING((5 0, 5 2), (5 4, 5 6), (5 8, 5 10))",
134 exp: ["MULTILINESTRING((5 0, 5 2), (5 4, 5 5))", "MULTILINESTRING((5 5, 5 6), (5 8, 5 10))"]
136 msg: "partial target and source split, mutual true",
138 g1: "MULTILINESTRING((0 5, 2 5), (4 5, 6 5), (8 5, 10 5))",
139 g2: "MULTILINESTRING((5 0, 5 2), (5 4, 5 6), (5 8, 5 10))",
140 exp: [["MULTILINESTRING((0 5, 2 5), (4 5, 5 5))", "MULTILINESTRING((5 5, 6 5), (8 5, 10 5))"],
141 ["MULTILINESTRING((5 0, 5 2), (5 4, 5 5))", "MULTILINESTRING((5 5, 5 6), (5 8, 5 10))"]]
143 msg: "partial target and source split with source endpoint, mutual true",
145 g1: "MULTILINESTRING((0 5, 2 5), (4 5, 6 5), (8 5, 10 5))",
146 g2: "MULTILINESTRING((4 0, 4 2), (4 4, 4 6), (4 8, 4 10))",
147 exp: [[], ["MULTILINESTRING((4 0, 4 2), (4 4, 4 5))", "MULTILINESTRING((4 5, 4 6), (4 8, 4 10))"]]
149 msg: "partial target and source split with target endpoint, mutual true",
151 g1: "MULTILINESTRING((4 0, 4 2), (4 4, 4 6), (4 8, 4 10))",
152 g2: "MULTILINESTRING((0 5, 2 5), (4 5, 6 5), (8 5, 10 5))",
153 exp: [["MULTILINESTRING((4 0, 4 2), (4 4, 4 5))", "MULTILINESTRING((4 5, 4 6), (4 8, 4 10))"], []]
155 msg: "partial target and source split with source vertex, mutual true",
157 g1: "MULTILINESTRING((0 5, 2 5), (4 5, 5 5, 6 5), (8 5, 10 5))",
158 g2: "MULTILINESTRING((5 0, 5 2), (5 4, 5 6), (5 8, 5 10))",
159 exp: [["MULTILINESTRING((0 5, 2 5), (4 5, 5 5))", "MULTILINESTRING((5 5, 6 5), (8 5, 10 5))"], ["MULTILINESTRING((5 0, 5 2), (5 4, 5 5))", "MULTILINESTRING((5 5, 5 6), (5 8, 5 10))"]]
161 msg: "partial target and source split with target vertex, mutual true",
163 g1: "MULTILINESTRING((5 0, 5 2), (5 4, 5 6), (5 8, 5 10))",
164 g2: "MULTILINESTRING((0 5, 2 5), (4 5, 5 5, 6 5), (8 5, 10 5))",
165 exp: [["MULTILINESTRING((5 0, 5 2), (5 4, 5 5))", "MULTILINESTRING((5 5, 5 6), (5 8, 5 10))"], ["MULTILINESTRING((0 5, 2 5), (4 5, 5 5))", "MULTILINESTRING((5 5, 6 5), (8 5, 10 5))"]]
169 t.plan(cases.length);
170 var c, parts, part, midparts;
171 for(var i=0; i<cases.length; ++i) {
175 var got = g1.split(g2, c.opt);
177 if(got instanceof Array) {
179 for(var j=0; j<got.length; ++j) {
181 if(part instanceof Array) {
183 for(var k=0; k<part.length; ++k) {
184 midparts.push(part[k].toString());
186 parts.push("[" + midparts.join(", ") + "]");
188 parts.push(got[j].toString());
191 got = parts.join(", ");
193 if(exp instanceof Array) {
195 for(var j=0; j<exp.length; ++j) {
197 if(part instanceof Array) {
199 for(var k=0; k<part.length; ++k) {
200 midparts.push(wkt(part[k]).toString());
202 parts.push("[" + midparts.join(", ") + "]");
204 parts.push(wkt(exp[j]).toString());
207 exp = parts.join(", ");
209 t.eq(got, exp, "case " + i + ": " + c.msg);
214 function test_getVertices(t) {
218 new OpenLayers.Geometry.Point(10, 20),
219 new OpenLayers.Geometry.Point(20, 30),
220 new OpenLayers.Geometry.Point(30, 40),
221 new OpenLayers.Geometry.Point(40, 50)
224 var multi = new OpenLayers.Geometry.MultiLineString([
225 new OpenLayers.Geometry.LineString(points),
226 new OpenLayers.Geometry.LineString(points)
229 var verts = multi.getVertices();
230 t.ok(verts instanceof Array, "got back an array");
231 t.eq(verts.length, 2 * points.length, "of correct length length");
232 t.geom_eq(verts[0], points[0], "0: correct geometry");
233 t.geom_eq(verts[1], points[1], "1: correct geometry");
234 t.geom_eq(verts[2], points[2], "2: correct geometry");
235 t.geom_eq(verts[3], points[3], "3: correct geometry");
236 t.geom_eq(verts[4], points[0], "4: correct geometry");
237 t.geom_eq(verts[5], points[1], "5: correct geometry");
238 t.geom_eq(verts[6], points[2], "6: correct geometry");
239 t.geom_eq(verts[7], points[3], "7: correct geometry");
242 var nodes = multi.getVertices(true);
243 t.ok(nodes instanceof Array, "[nodes only] got back an array");
244 t.eq(nodes.length, 4, "[nodes only] of correct length length");
245 t.geom_eq(nodes[0], points[0], "[nodes only] 0: correct geometry");
246 t.geom_eq(nodes[1], points[3], "[nodes only] 1: correct geometry");
247 t.geom_eq(nodes[2], points[0], "[nodes only] 2: correct geometry");
248 t.geom_eq(nodes[3], points[3], "[nodes only] 3: correct geometry");
251 var nodes = multi.getVertices(false);
252 t.ok(nodes instanceof Array, "[no nodes] got back an array");
253 t.eq(nodes.length, 4, "[no nodes] of correct length length");
254 t.geom_eq(nodes[0], points[1], "[no nodes] 0: correct geometry");
255 t.geom_eq(nodes[1], points[2], "[no nodes] 1: correct geometry");
256 t.geom_eq(nodes[2], points[1], "[no nodes] 2: correct geometry");
257 t.geom_eq(nodes[3], points[2], "[no nodes] 3: correct geometry");