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 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356
|
//
// Ported from JTS
// junit/algorithm/RobustLineIntersectorZTest.java
// 1ecc94caa9e188beb63bfb95089e7dd6869bab20
#include <tut/tut.hpp>
#include <utility.h>
// geos
#include <geos/algorithm/LineIntersector.h>
#include <geos/geom/Coordinate.h>
#include <geos/geom/LineSegment.h>
// std
#include <utility>
using namespace geos::geom;
typedef geos::algorithm::LineIntersector RobustLineIntersector;
namespace tut {
//
// Test Group
//
struct test_robustlineintersectorz_data {
template<typename C>
using Segment = std::pair<C, C>;
using XY = CoordinateXY;
using XYZ = Coordinate;
using XYM = CoordinateXYM;
using XYZM = CoordinateXYZM;
template<typename C1, typename C2>
void checkIntersection(const Segment<C1>& line1,
const Segment<C2>& line2,
const CoordinateXYZM& p1,
const CoordinateXYZM& p2 = CoordinateXYZM::getNull())
{
checkIntersectionDir(line1, line2, p1, p2);
checkIntersectionDir(line2, line1, p1, p2);
Segment<C1> line1Rev(line1.second, line1.first);
Segment<C2> line2Rev(line2.second, line2.first);
checkIntersectionDir(line1Rev, line2Rev, p1, p2);
checkIntersectionDir(line2Rev, line1Rev, p1, p2);
}
template<typename C1, typename C2>
void checkIntersectionDir(
const Segment<C1>& line1,
const Segment<C2>& line2,
const CoordinateXYZM& p1,
const CoordinateXYZM& p2)
{
RobustLineIntersector li;
li.computeIntersection(
line1.first, line1.second,
line2.first, line2.second);
auto actual1 = li.getIntersection(0);
auto actual2 = li.getIntersection(1);
if (p2.isNull()) {
ensure_equals(li.getIntersectionNum(), 1u);
} else {
ensure_equals(li.getIntersectionNum(), 2u);
// normalize actual results
if (actual1.compareTo(actual2) > 0) {
actual1 = li.getIntersection(1);
actual2 = li.getIntersection(0);
}
}
ensure_equals_xyzm( actual1, p1 );
if (!p2.isNull())
ensure_equals_xyzm( actual2, p2 );
}
static CoordinateXYZM xyz(double x, double y, double z) {
return CoordinateXYZM(Coordinate(x, y, z));
}
static CoordinateXYZM xy(double x, double y) {
return CoordinateXYZM(CoordinateXY(x, y));
}
static CoordinateXYZM xym(double x, double y, double m) {
return CoordinateXYZM(CoordinateXYM(x, y, m));
}
static CoordinateXYZM xyzm(double x, double y, double z, double m) {
return CoordinateXYZM(x, y, z, m);
}
template<typename C=Coordinate>
static Segment<C> line(const C& p0, const C& p1) {
return Segment<C>(p0, p1);
}
};
typedef test_group<test_robustlineintersectorz_data> group;
typedef group::object object;
group test_robustlineintersectorz_group(
"geos::algorithm::RobustLineIntersectorZ");
//
// Test Cases
//
// 1 - testInterior
template<>
template<>
void object::test<1>
()
{
checkIntersection(
line<XYZ>({1, 1, 1}, {3, 3, 3}),
line<XYZ>({1, 3, 10}, {3, 1, 30}),
xyz(2, 2, 11));
}
// 2 - testInterior2D
template<>
template<>
void object::test<2>
()
{
checkIntersection(
line<XY>({1, 1}, {3, 3}),
line<XY>({1, 3}, {3, 1}),
xy(2, 2));
}
// testInterior3D2D
template<>
template<>
void object::test<3>
()
{
checkIntersection(
line<XYZ>({1, 1, 1}, {3, 3, 3}),
line<XY>({1, 3}, {3, 1}),
xyz(2, 2, 2));
}
// testInterior2D3D
template<>
template<>
void object::test<4>
()
{
checkIntersection(
line<XY>({1, 1}, {3, 3}),
line<XYZ>({1, 3, 10}, {3, 1, 30}),
xyz(2, 2, 20));
}
// testInterior2D3DPart
// result is average of line1 interpolated and line2 p0 Z
template<>
template<>
void object::test<5>
()
{
checkIntersection(
line<XYZ>({1, 1, 1}, {3, 3, 3}),
line<XYZ>({1, 3, 10}, {3, 1, geos::DoubleNotANumber}),
xyz(2, 2, 6));
}
// testEndpoint
template<>
template<>
void object::test<6>
()
{
checkIntersection(
line<XYZ>({1, 1, 1}, {3, 3, 3}),
line<XYZ>({3, 3, 3}, {3, 1, 30}),
xyz(3, 3, 3));
}
// testEndpoint2D
template<>
template<>
void object::test<7>
()
{
checkIntersection(
line<XY>({1, 1}, {3, 3}),
line<XY>({3, 3}, {3, 1}),
xyz(3, 3, geos::DoubleNotANumber));
}
// testEndpoint2D3D
template<>
template<>
void object::test<8>
()
{
// result Z is from 3D point
checkIntersection(
line<XYZ>({1, 1, 1}, {3, 3, 3}),
line<XY>({3, 3}, {3, 1}),
xyz(3, 3, 3));
}
// testInteriorEndpoint
template<>
template<>
void object::test<9>
()
{
// result Z is from 3D point
checkIntersection(
line<XYZ>({1, 1, 1}, {3, 3, 3}),
line<XYZ>({2, 2, 10}, {3, 1, 30}),
xyz(2, 2, 10));
}
// testInteriorEndpoint3D2D
template<>
template<>
void object::test<10>
()
{
// result Z is interpolated
checkIntersection(
line<XYZ>({1, 1, 1}, {3, 3, 3}),
line<XY>({2, 2}, {3, 1}),
xyz(2, 2, 2));
}
// testInteriorEndpoint2D3D
// result Z is from 3D point
template<>
template<>
void object::test<11>
()
{
checkIntersection(
line<XY>({1, 1}, {3, 3}),
line<XYZ>({2, 2, 10}, {3, 1, 20}),
xyz(2, 2, 10));
}
// testCollinearEqual
template<>
template<>
void object::test<12>
()
{
checkIntersection(
line<XYZ>({1, 1, 1}, {3, 3, 3}),
line<XYZ>({1, 1, 1}, {3, 3, 3}),
xyz(1, 1, 1), xyz( 3, 3, 3));
}
// testCollinearEqual3D2D
template<>
template<>
void object::test<13>
()
{
checkIntersection(
line<XYZ>({1, 1, 1}, {3, 3, 3}),
line<XY>({1, 1}, {3, 3}),
xyz(1, 1, 1), xyz( 3, 3, 3));
}
// testCollinearEndpoint
template<>
template<>
void object::test<14>
()
{
checkIntersection(
line<XYZ>({1, 1, 1}, {3, 3, 3}),
line<XYZ>({3, 3, 3}, {5, 5, 5}),
xyz(3, 3, 3));
}
// testCollinearEndpoint3D2D
// result Z is from 3D point
template<>
template<>
void object::test<15>
()
{
checkIntersection(
line<XYZ>({1, 1, 1}, {3, 3, 3}),
line<XY>({3, 3}, {5, 5}),
xyz(3, 3, 3));
}
// testCollinearContained
template<>
template<>
void object::test<16>
()
{
checkIntersection(
line<XYZ>({1, 1, 1}, {5, 5, 5}),
line<XYZ>({3, 3, 3}, {4, 4, 4}),
xyz(3, 3, 3),
xyz(4, 4, 4));
}
// testCollinearContained3D2D
template<>
template<>
void object::test<17>
()
{
// result Z is interpolated
checkIntersection(
line<XYZ>({1, 1, 1}, {5, 5, 5}),
line<XY>({3, 3}, {4, 4}),
xyz(3, 3, 3),
xyz(4, 4, 4));
}
// Interior XYM-XYM
template<>
template<>
void object::test<18>
()
{
checkIntersection(
line<XYM>({1, 1, 1}, {3, 3, 3}),
line<XYM>({1, 3, 10}, {3, 1, 30}),
xym(2, 2, 11));
}
// Interior XYZM-XYZM
template<>
template<>
void object::test<19>
()
{
checkIntersection(
line<XYZM>({1, 1, 1, -1}, {3, 3, 3, -3}),
line<XYZM>({1, 3, 10, -10}, {3, 1, 30, -30}),
xyzm(2, 2, 11, -11));
}
} // namespace tut
|