1 /**********************************************************************
2 *
3 * GEOS - Geometry Engine Open Source
4 * http://geos.osgeo.org
5 *
6 * Copyright (C) 2019 Martin Davis <mtnclimb@gmail.com>
7 * Copyright (C) 2011 Sandro Santilli <strk@kbt.io>
8 *
9 * This is free software; you can redistribute and/or modify it under
10 * the terms of the GNU Lesser General Public Licence as published
11 * by the Free Software Foundation.
12 * See the COPYING file for more information.
13 *
14 **********************************************************************/
15
16 //
17 // Test Suite for geos::algorithm::InteriorPointArea
18
19 #include <tut/tut.hpp>
20 // geos
21 #include <geos/geom/Coordinate.h>
22 #include <geos/algorithm/Intersection.h>
23 #include <geos/io/WKTReader.h>
24 #include <geos/geom/Geometry.h>
25 // std
26 #include <sstream>
27 #include <string>
28 #include <memory>
29
30 namespace tut {
31 //
32 // Test Group
33 //
34
35 // dummy data, not used
36 struct test_intersection_data {
37 typedef geos::geom::Geometry Geometry;
38 typedef geos::geom::Coordinate Coordinate;
39 typedef geos::algorithm::Intersection Intersection;
40
41 geos::io::WKTReader reader;
42 std::unique_ptr<Geometry> geom;
43
44 double MAX_ABS_ERROR = 1e-5;
45
checkIntersectionNulltut::test_intersection_data46 void checkIntersectionNull(double p1x, double p1y, double p2x, double p2y,
47 double q1x, double q1y, double q2x, double q2y) {
48 Coordinate p1(p1x, p1y);
49 Coordinate p2(p2x, p2y);
50 Coordinate q1(q1x, q1y);
51 Coordinate q2(q2x, q2y);
52 Coordinate actual = Intersection::intersection(p1, p2, q1, q2);
53 ensure("checkIntersectionNull", actual.isNull());
54 }
55
checkIntersectiontut::test_intersection_data56 void checkIntersection(double p1x, double p1y, double p2x, double p2y,
57 double q1x, double q1y, double q2x, double q2y,
58 double expectedx, double expectedy) {
59 Coordinate p1(p1x, p1y);
60 Coordinate p2(p2x, p2y);
61 Coordinate q1(q1x, q1y);
62 Coordinate q2(q2x, q2y);
63 Coordinate expected(expectedx, expectedy);
64 Coordinate actual = Intersection::intersection(p1, p2, q1, q2);
65 double dist = actual.distance(expected);
66 // std::cout << "Expected: " << expected << " Actual: " << actual << " Dist = " << dist << std::endl;
67 ensure("checkIntersection", dist <= MAX_ABS_ERROR);
68 }
69
test_intersection_datatut::test_intersection_data70 test_intersection_data()
71 {}
72
73 };
74
75 typedef test_group<test_intersection_data> group;
76 typedef group::object object;
77
78 group test_intersection_data("geos::algorithm::Intersection");
79
80
81 template<>
82 template<>
test()83 void object::test<1>
84 ()
85 {
86 // testSimple
87 checkIntersection(
88 0,0, 10,10,
89 0,10, 10,0,
90 5,5);
91
92 // testCollinear
93 checkIntersectionNull(
94 0,0, 10,10,
95 20,20, 30, 30 );
96
97 // testParallel
98 checkIntersectionNull(
99 0,0, 10,10,
100 10,0, 20,10 );
101
102 // testAlmostCollinear
103 checkIntersection(
104 35613471.6165017, 4257145.306132293, 35613477.7705378, 4257160.528222711,
105 35613477.77505724, 4257160.539653536, 35613479.85607389, 4257165.92369170,
106 35613477.772841461, 4257160.5339209242 );
107
108 // testAlmostCollinearCond
109 checkIntersection(
110 1.6165017, 45.306132293, 7.7705378, 60.528222711,
111 7.77505724, 60.539653536, 9.85607389, 65.92369170,
112 7.772841461, 60.5339209242 );
113
114 }
115
116 } // namespace tut
117
118