Welcome to mirror list, hosted at ThFree Co, Russian Federation.

segments_intersect_test.cpp « geometry_tests « geometry - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d10369864f7bef86aa1a699f1ad9b994be1670d4 (plain)
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
#include "testing/testing.hpp"

#include "geometry/robust_orientation.hpp"


typedef m2::PointD P;

bool SegmentsIntersect(P a, P b, P c, P d)
{
  bool const res = m2::robust::SegmentsIntersect(a, b, c, d);
  TEST_EQUAL(res, m2::robust::SegmentsIntersect(a, b, d, c), (a, b, c, d));
  TEST_EQUAL(res, m2::robust::SegmentsIntersect(b, a, c, d), (a, b, c, d));
  TEST_EQUAL(res, m2::robust::SegmentsIntersect(b, a, d, c), (a, b, c, d));
  TEST_EQUAL(res, m2::robust::SegmentsIntersect(c, d, a, b), (a, b, c, d));
  TEST_EQUAL(res, m2::robust::SegmentsIntersect(c, d, b, a), (a, b, c, d));
  TEST_EQUAL(res, m2::robust::SegmentsIntersect(d, c, a, b), (a, b, c, d));
  TEST_EQUAL(res, m2::robust::SegmentsIntersect(d, c, b, a), (a, b, c, d));
  return res;
}

UNIT_TEST(SegmentsIntersect_Collinear)
{
  TEST(!SegmentsIntersect(P(0, 0), P(1, 1), P(2, 3), P(3, 3)), ("Far away"));
  TEST(SegmentsIntersect(P(0, 0), P(1, 1), P(1, 1), P(3, 3)), ("Border intersection"));
  TEST(SegmentsIntersect(P(0, 0), P(2, 2), P(1, 1), P(3, 3)), ("Normal intersection"));
  TEST(SegmentsIntersect(P(0, 0), P(2, 2), P(0, 0), P(3, 3)), ("Border inclusion"));
  TEST(SegmentsIntersect(P(1, 1), P(2, 2), P(0, 0), P(3, 3)), ("Normal inclusion"));
}

UNIT_TEST(SegmentsIntersect_NoIntersection)
{
  TEST(!SegmentsIntersect(P(0, 1), P(2, 5), P(7, 7), P(15, 7)), ("Far away"));
  TEST(!SegmentsIntersect(P(0, 0), P(2, 4), P(1, 1), P(4, 3)), ("Rect intersect, segments don't"));
  TEST(!SegmentsIntersect(P(0, 0), P(8, 8), P(1, 2), P(4, 8)), ("Only one cross product is 0"));
}

UNIT_TEST(SegmentsIntersect_Intersect)
{
  TEST(SegmentsIntersect(P(0, 0), P(2, 4), P(0, 3), P(4, 0)), ("Normal"));
  TEST(SegmentsIntersect(P(1, 2), P(3, 4), P(1, 2), P(5, 1)), ("Fan"));
  TEST(SegmentsIntersect(P(1, 2), P(3, 4), P(1, 2), P(3, -2)), ("Fan"));
  TEST(SegmentsIntersect(P(0, 0), P(2, 2), P(0, 4), P(4, 0)), ("Border"));
}