1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
|
/**********************************************************************
*
* GEOS - Geometry Engine Open Source
* http://geos.osgeo.org
*
* Copyright (C) 2019 Martin Davis <mtnclimb@gmail.com>
* Copyright (C) 2011 Sandro Santilli <strk@kbt.io>
*
* This is free software; you can redistribute and/or modify it under
* the terms of the GNU Lesser General Public Licence as published
* by the Free Software Foundation.
* See the COPYING file for more information.
*
**********************************************************************/
//
// Test Suite for geos::algorithm::InteriorPointArea
#include <tut/tut.hpp>
// geos
#include <geos/geom/Coordinate.h>
#include <geos/algorithm/Intersection.h>
#include <geos/io/WKTReader.h>
#include <geos/geom/Geometry.h>
// std
#include <memory>
namespace tut {
//
// Test Group
//
// dummy data, not used
struct test_intersection_data {
typedef geos::geom::Geometry Geometry;
typedef geos::geom::Coordinate Coordinate;
typedef geos::algorithm::Intersection Intersection;
geos::io::WKTReader reader;
std::unique_ptr<Geometry> geom;
double MAX_ABS_ERROR = 1e-5;
void checkIntersectionNull(
double p1x, double p1y, double p2x, double p2y,
double q1x, double q1y, double q2x, double q2y)
{
Coordinate p1(p1x, p1y);
Coordinate p2(p2x, p2y);
Coordinate q1(q1x, q1y);
Coordinate q2(q2x, q2y);
auto actual = Intersection::intersection(p1, p2, q1, q2);
ensure("checkIntersectionNull", actual.isNull());
}
void checkIntersection(
double p1x, double p1y, double p2x, double p2y,
double q1x, double q1y, double q2x, double q2y,
double expectedx, double expectedy)
{
Coordinate p1(p1x, p1y);
Coordinate p2(p2x, p2y);
Coordinate q1(q1x, q1y);
Coordinate q2(q2x, q2y);
Coordinate expected(expectedx, expectedy);
auto actual = Intersection::intersection(p1, p2, q1, q2);
double dist = actual.distance(expected);
// std::cout << "Expected: " << expected << " Actual: " << actual << " Dist = " << dist << std::endl;
ensure("checkIntersection", dist <= MAX_ABS_ERROR);
}
void checkIntersectionLineSegment(
double p1x, double p1y, double p2x, double p2y,
double q1x, double q1y, double q2x, double q2y,
double expectedx, double expectedy)
{
Coordinate p1(p1x, p1y);
Coordinate p2(p2x, p2y);
Coordinate q1(q1x, q1y);
Coordinate q2(q2x, q2y);
Coordinate actual(Intersection::intersectionLineSegment(p1, p2, q1, q2));
Coordinate expected(expectedx, expectedy);
double dist = actual.distance(expected);
ensure("checkIntersectionLineSegment", dist <= MAX_ABS_ERROR);
}
void checkIntersectionLineSegmentNull(
double p1x, double p1y, double p2x, double p2y,
double q1x, double q1y, double q2x, double q2y)
{
Coordinate p1(p1x, p1y);
Coordinate p2(p2x, p2y);
Coordinate q1(q1x, q1y);
Coordinate q2(q2x, q2y);
Coordinate actual(Intersection::intersectionLineSegment(p1, p2, q1, q2));
ensure("checkIntersectionLineSegmentNull", actual.isNull());
}
test_intersection_data()
{}
};
typedef test_group<test_intersection_data> group;
typedef group::object object;
group test_intersection_data("geos::algorithm::Intersection");
// testSimple
template<>
template<>
void object::test<1>()
{
checkIntersection(0,0, 10,10, 0,10, 10,0, 5,5);
}
// testCollinear
template<>
template<>
void object::test<2>()
{
checkIntersectionNull(0,0, 10,10, 20,20, 30, 30 );
}
// testParallel
template<>
template<>
void object::test<3>()
{
checkIntersectionNull(
0,0, 10,10,
10,0, 20,10 );
}
// testAlmostCollinear
template<>
template<>
void object::test<4>()
{
checkIntersection(
35613471.6165017, 4257145.306132293, 35613477.7705378, 4257160.528222711,
35613477.77505724, 4257160.539653536, 35613479.85607389, 4257165.92369170,
35613477.772841461, 4257160.5339209242 );
}
// testAlmostCollinearCond
template<>
template<>
void object::test<5>()
{
checkIntersection(
1.6165017, 45.306132293, 7.7705378, 60.528222711,
7.77505724, 60.539653536, 9.85607389, 65.92369170,
7.772841461, 60.5339209242 );
}
// testLineSegCross
template<>
template<>
void object::test<6>()
{
checkIntersectionLineSegment( 0, 0, 0, 1, -1, 9, 1, 9, 0, 9 );
checkIntersectionLineSegment( 0, 0, 0, 1, -1, 2, 1, 4, 0, 3 );
}
// testLineSegTouch
template<>
template<>
void object::test<7>()
{
checkIntersectionLineSegment( 0, 0, 0, 1, -1, 9, 0, 9, 0, 9 );
checkIntersectionLineSegment( 0, 0, 0, 1, 0, 2, 1, 4, 0, 2 );
}
// testLineSegCollinear
template<>
template<>
void object::test<8>()
{
checkIntersectionLineSegment( 0, 0, 0, 1, 0, 9, 0, 8, 0, 9 );
}
// testLineSegNone
template<>
template<>
void object::test<9>()
{
checkIntersectionLineSegmentNull( 0, 0, 0, 1, 2, 9, 1, 9 );
checkIntersectionLineSegmentNull( 0, 0, 0, 1, -2, 9, -1, 9 );
checkIntersectionLineSegmentNull( 0, 0, 0, 1, 2, 9, 1, 9 );
}
} // namespace tut
|