• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2 // Unit Test
3 
4 // Copyright (c) 2010-2012 Barend Gehrels, Amsterdam, the Netherlands.
5 
6 // This file was modified by Oracle on 2014.
7 // Modifications copyright (c) 2014 Oracle and/or its affiliates.
8 
9 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
10 
11 // Use, modification and distribution is subject to the Boost Software License,
12 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
13 // http://www.boost.org/LICENSE_1_0.txt)
14 
15 
16 #include <strategies/test_within.hpp>
17 
18 
19 template <typename Point>
test_all()20 void test_all()
21 {
22     typedef bg::model::polygon<Point> polygon;
23 
24     std::string const box = "POLYGON((0 0,0 2,2 2,2 0,0 0))";
25     std::string const triangle = "POLYGON((0 0,0 4,6 0,0 0))";
26     std::string const with_hole = "POLYGON((0 0,0 3,3 3,3 0,0 0),(1 1,2 1,2 2,1 2,1 1))";
27 
28     bg::strategy::within::crossings_multiply<Point> s;
29 
30 
31     test_geometry<Point, polygon>("b1", "POINT(1 1)", box, s, true);
32     test_geometry<Point, polygon>("b2", "POINT(3 3)", box, s, false);
33 
34     // Test ALL corners (officialy false but some strategies might answer true)
35     test_geometry<Point, polygon>("b3a", "POINT(0 0)", box, s, false);
36     test_geometry<Point, polygon>("b3b", "POINT(0 2)", box, s, false);
37     test_geometry<Point, polygon>("b3c", "POINT(2 2)", box, s, false);
38     test_geometry<Point, polygon>("b3d", "POINT(2 0)", box, s, false);
39 
40     // Test ALL sides (officialy false but some strategies might answer true)
41     test_geometry<Point, polygon>("b4a", "POINT(0 1)", box, s, false);
42     test_geometry<Point, polygon>("b4b", "POINT(1 2)", box, s, true); // different
43     test_geometry<Point, polygon>("b4c", "POINT(2 1)", box, s, false);
44     test_geometry<Point, polygon>("b4d", "POINT(1 0)", box, s, false);
45 
46 
47     test_geometry<Point, polygon>("t1", "POINT(1 1)", triangle, s, true);
48     test_geometry<Point, polygon>("t2", "POINT(3 3)", triangle, s, false);
49 
50     test_geometry<Point, polygon>("t3a", "POINT(0 0)", triangle, s, false);
51     test_geometry<Point, polygon>("t3b", "POINT(0 4)", triangle, s, true); // diff
52     test_geometry<Point, polygon>("t3c", "POINT(5 0)", triangle, s, false);
53 
54     test_geometry<Point, polygon>("t4a", "POINT(0 2)", triangle, s, false);
55     test_geometry<Point, polygon>("t4b", "POINT(3 2)", triangle, s, false);
56     test_geometry<Point, polygon>("t4c", "POINT(2 0)", triangle, s, false);
57 
58 
59     test_geometry<Point, polygon>("h1", "POINT(0.5 0.5)", with_hole, s, true);
60     test_geometry<Point, polygon>("h2a", "POINT(1.5 1.5)", with_hole, s, false);
61     test_geometry<Point, polygon>("h2b", "POINT(5 5)", with_hole, s, false);
62 
63     test_geometry<Point, polygon>("h3a", "POINT(1 1)", with_hole, s, true); // diff
64     test_geometry<Point, polygon>("h3b", "POINT(2 2)", with_hole, s, false);
65     test_geometry<Point, polygon>("h3c", "POINT(0 0)", with_hole, s, false);
66 
67     test_geometry<Point, polygon>("h4a", "POINT(1 1.5)", with_hole, s, false);
68     test_geometry<Point, polygon>("h4b", "POINT(1.5 2)", with_hole, s, false);
69 
70     // Lying ON (one of the sides of) interior ring
71     test_geometry<Point, polygon>("#77-1", "POINT(6 3.5)",
72         "POLYGON((5 3,5 4,4 4,4 5,3 5,3 6,5 6,5 5,7 5,7 6,8 6,8 5,9 5,9 2,8 2,8 1,7 1,7 2,5 2,5 3),(6 3,8 3,8 4,6 4,6 3))",
73         s, false);
74 }
75 
76 
test_main(int,char * [])77 int test_main(int, char* [])
78 {
79     test_all<bg::model::point<float, 2, bg::cs::cartesian> >();
80     test_all<bg::model::point<double, 2, bg::cs::cartesian> >();
81 
82 #if defined(HAVE_TTMATH)
83     test_all<bg::model::point<ttmath_big, 2, bg::cs::cartesian> >();
84 #endif
85 
86     return 0;
87 }
88