2
* Copyright (C) 2008 Steve Ratcliffe
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License version 2 as
6
* published by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
14
* Author: Steve Ratcliffe
15
* Create date: 29-Nov-2008
17
package uk.me.parabola.mkgmap.general;
19
import java.util.Arrays;
20
import java.util.List;
22
import uk.me.parabola.imgfmt.app.Area;
23
import uk.me.parabola.imgfmt.app.Coord;
25
import static org.junit.Assert.assertArrayEquals;
26
import static org.junit.Assert.assertEquals;
27
import static org.junit.Assert.assertNull;
28
import static org.junit.Assert.assertTrue;
29
import org.junit.Test;
31
public class LineClipperTest {
34
* This is the example as given on the referenced web page.
35
* We now use integers instead of floats so the 101.425 from the
36
* example is just 101 here.
39
public void testExampleClip() {
40
Area a = new Area(60, 70, 150, 230);
46
List<List<Coord>> listList = LineClipper.clip(a, Arrays.asList(co));
47
assertTrue("list should be empty", !listList.isEmpty());
53
assertArrayEquals("example result", result, listList.get(0).toArray());
57
* Test an original line that enters the area, leaves it and then goes back
58
* into the area. This should give two lines in the result set.
61
public void testListClip() {
63
Area a = new Area(100, 100, 200, 200);
64
List<Coord> l = Arrays.asList(new Coord(20, 30),
71
List<List<Coord>> list = LineClipper.clip(a, l);
73
// There should be exactly two lines
74
assertEquals("should be two lines", 2, list.size());
77
for (List<Coord> lco : list)
78
assertTrue("empty list", !lco.isEmpty());
81
Coord[] firstExpectedLine = {
87
assertArrayEquals(firstExpectedLine, list.get(0).toArray());
88
Coord[] secondExpectedLine = {
92
assertArrayEquals(secondExpectedLine, list.get(1).toArray());
96
* If all the lines are inside, then it should just return null to indicate that.
99
public void testAllInside() {
100
Area a = new Area(100, 100, 200, 200);
101
List<Coord> l = Arrays.asList(
106
List<List<Coord>> list = LineClipper.clip(a, l);
107
assertNull("all lines inside", list);