PageRenderTime 22ms CodeModel.GetById 10ms app.highlight 9ms RepoModel.GetById 2ms app.codeStats 0ms

/Src/Dependencies/Boost/libs/geometry/test/algorithms/disjoint.cpp

http://hadesmem.googlecode.com/
C++ | 132 lines | 74 code | 31 blank | 27 comment | 1 complexity | be14838447c1732ac2af7456c3835d71 MD5 | raw file
  1// Boost.Geometry (aka GGL, Generic Geometry Library)
  2// Unit Test
  3
  4// Copyright (c) 2007-2011 Barend Gehrels, Amsterdam, the Netherlands.
  5// Copyright (c) 2008-2011 Bruno Lalande, Paris, France.
  6// Copyright (c) 2009-2011 Mateusz Loskot, London, UK.
  7
  8// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
  9// (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
 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#include <iostream>
 16#include <string>
 17
 18
 19#include <geometry_test_common.hpp>
 20
 21#include <boost/geometry/algorithms/disjoint.hpp>
 22#include <boost/geometry/geometries/geometries.hpp>
 23#include <boost/geometry/geometries/point_xy.hpp>
 24#include <boost/geometry/domains/gis/io/wkt/read_wkt.hpp>
 25#include <boost/geometry/strategies/strategies.hpp>
 26
 27#include <test_common/test_point.hpp>
 28
 29#include <algorithms/test_relate.hpp>
 30
 31
 32template <typename G1, typename G2>
 33void test_disjoint(std::string const& id,
 34            std::string const& wkt1,
 35            std::string const& wkt2, bool expected)
 36{
 37    G1 g1;
 38    bg::read_wkt(wkt1, g1);
 39
 40    G2 g2;
 41    bg::read_wkt(wkt2, g2);
 42
 43    bool detected = bg::disjoint(g1, g2);
 44    BOOST_CHECK_MESSAGE(detected == expected,
 45        "disjoint: " << id
 46        << " -> Expected: " << expected
 47        << " detected: " << detected);
 48}
 49
 50
 51
 52template <typename P>
 53void test_all()
 54{
 55    typedef bg::model::box<P> box;
 56
 57    test_disjoint<P, P>("pp1", "point(1 1)", "point(1 1)", false);
 58    test_disjoint<P, P>("pp2", "point(1 1)", "point(1.001 1)", true);
 59
 60    // left-right
 61    test_disjoint<box, box>("bb1", "box(1 1, 2 2)", "box(3 1, 4 2)", true);
 62    test_disjoint<box, box>("bb2", "box(1 1, 2 2)", "box(2 1, 3 2)", false);
 63    test_disjoint<box, box>("bb3", "box(1 1, 2 2)", "box(2 2, 3 3)", false);
 64    test_disjoint<box, box>("bb4", "box(1 1, 2 2)", "box(2.001 2, 3 3)", true);
 65
 66    // up-down
 67    test_disjoint<box, box>("bb5", "box(1 1, 2 2)", "box(1 3, 2 4)", true);
 68    test_disjoint<box, box>("bb6", "box(1 1, 2 2)", "box(1 2, 2 3)", false);
 69    // right-left
 70    test_disjoint<box, box>("bb7", "box(1 1, 2 2)", "box(0 1, 1 2)", false);
 71    test_disjoint<box, box>("bb8", "box(1 1, 2 2)", "box(0 1, 1 2)", false);
 72
 73    // point-box
 74    test_disjoint<P, box>("pb1", "point(1 1)", "box(0 0, 2 2)", false);
 75    test_disjoint<P, box>("pb2", "point(2 2)", "box(0 0, 2 2)", false);
 76    test_disjoint<P, box>("pb3", "point(2.0001 2)", "box(1 1, 2 2)", true);
 77    test_disjoint<P, box>("pb4", "point(0.9999 2)", "box(1 1, 2 2)", true);
 78
 79    // box-point (to test reverse compiling)
 80    test_disjoint<box, P>("bp1", "box(1 1, 2 2)", "point(2 2)", false);
 81
 82    // Test triangles for polygons/rings, boxes
 83    // Note that intersections are tested elsewhere, they don't need
 84    // thorough test at this place
 85    typedef bg::model::polygon<P> polygon;
 86    typedef bg::model::ring<P> ring;
 87
 88    // Four times same test with other types
 89    test_disjoint<polygon, polygon>("disjoint_simplex_pp", disjoint_simplex[0], disjoint_simplex[1], true);
 90    test_disjoint<ring, polygon>("disjoint_simplex_rp", disjoint_simplex[0], disjoint_simplex[1], true);
 91    test_disjoint<ring, ring>("disjoint_simplex_rr", disjoint_simplex[0], disjoint_simplex[1], true);
 92    test_disjoint<polygon, ring>("disjoint_simplex_pr", disjoint_simplex[0], disjoint_simplex[1], true);
 93
 94    // Testing touch
 95    test_disjoint<polygon, polygon>("touch_simplex_pp", touch_simplex[0], touch_simplex[1], false);
 96
 97    // Testing overlap (and test compiling with box)
 98    test_disjoint<polygon, polygon>("overlaps_box_pp", overlaps_box[0], overlaps_box[1], false);
 99    test_disjoint<box, polygon>("overlaps_box_bp", overlaps_box[0], overlaps_box[1], false);
100    test_disjoint<box, ring>("overlaps_box_br", overlaps_box[0], overlaps_box[1], false);
101    test_disjoint<polygon, box>("overlaps_box_pb", overlaps_box[1], overlaps_box[0], false);
102    test_disjoint<ring, box>("overlaps_box_rb", overlaps_box[1], overlaps_box[0], false);
103
104    // Test if within(a,b) returns false for disjoint
105    test_disjoint<ring, ring>("within_simplex_rr1", within_simplex[0], within_simplex[1], false);
106    test_disjoint<ring, ring>("within_simplex_rr2", within_simplex[1], within_simplex[0], false);
107
108    // Linear
109    typedef bg::model::linestring<P> ls;
110    typedef bg::model::segment<P> segment;
111    test_disjoint<ls, ls>("ls/ls 1", "linestring(0 0,1 1)", "linestring(1 0,0 1)", false);
112    test_disjoint<ls, ls>("ls/ls 2", "linestring(0 0,1 1)", "linestring(1 0,2 1)", true);
113    test_disjoint<segment, segment>("s/s 1", "linestring(0 0,1 1)", "linestring(1 0,0 1)", false);
114    test_disjoint<segment, segment>("s/s 2", "linestring(0 0,1 1)", "linestring(1 0,2 1)", true);
115    // TODO test_disjoint<segment, ls>("s/ls 1", "linestring(0 0,1 1)", "linestring(1 0,0 1)", false);
116    // TODO test_disjoint<segment, ls>("s/ls 2", "linestring(0 0,1 1)", "linestring(1 0,2 1)", true);
117    // TODO test_disjoint<ls, segment>("ls/s 1", "linestring(0 0,1 1)", "linestring(1 0,0 1)", false);
118    // TODO test_disjoint<ls, segment>("ls/s 2", "linestring(0 0,1 1)", "linestring(1 0,2 1)", true);
119
120}
121
122int test_main(int, char* [])
123{
124    test_all<bg::model::d2::point_xy<float> >();
125    test_all<bg::model::d2::point_xy<double> >();
126
127#ifdef HAVE_TTMATH
128    test_all<bg::model::d2::point_xy<ttmath_big> >();
129#endif
130
131    return 0;
132}