diff options
author | Anas Nashif <anas.nashif@intel.com> | 2013-08-26 08:15:55 -0400 |
---|---|---|
committer | Anas Nashif <anas.nashif@intel.com> | 2013-08-26 08:15:55 -0400 |
commit | bb4dd8289b351fae6b55e303f189127a394a1edd (patch) | |
tree | 77c9c35a31b1459dd7988c2448e797d142530c41 /libs/geometry/test/algorithms/touches.cpp | |
parent | 1a78a62555be32868418fe52f8e330c9d0f95d5a (diff) | |
download | boost-bb4dd8289b351fae6b55e303f189127a394a1edd.tar.gz boost-bb4dd8289b351fae6b55e303f189127a394a1edd.tar.bz2 boost-bb4dd8289b351fae6b55e303f189127a394a1edd.zip |
Imported Upstream version 1.51.0upstream/1.51.0
Diffstat (limited to 'libs/geometry/test/algorithms/touches.cpp')
-rw-r--r-- | libs/geometry/test/algorithms/touches.cpp | 154 |
1 files changed, 154 insertions, 0 deletions
diff --git a/libs/geometry/test/algorithms/touches.cpp b/libs/geometry/test/algorithms/touches.cpp new file mode 100644 index 0000000000..84430d527e --- /dev/null +++ b/libs/geometry/test/algorithms/touches.cpp @@ -0,0 +1,154 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// +// Copyright (c) 2012 Barend Gehrels, Amsterdam, the Netherlands. +// Use, modification and distribution is subject to the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <algorithms/test_touches.hpp> + + +#include <boost/geometry/geometries/geometries.hpp> +#include <boost/geometry/geometries/point_xy.hpp> + + + +template <typename P> +void test_all() +{ + typedef bg::model::polygon<P> polygon; + + // Just a normal polygon + test_self_touches<polygon>("POLYGON((0 0,0 4,1.5 2.5,2.5 1.5,4 0,0 0))", false); + + // Self intersecting + test_self_touches<polygon>("POLYGON((1 2,1 1,2 1,2 2.25,3 2.25,3 0,0 0,0 3,3 3,2.75 2,1 2))", false); + + // Self touching at a point + test_self_touches<polygon>("POLYGON((0 0,0 3,2 3,2 2,1 2,1 1,2 1,2 2,3 2,3 0,0 0))", true); + + // Self touching at a segment + test_self_touches<polygon>("POLYGON((0 0,0 3,2 3,2 2,1 2,1 1,2 1,2 2.5,3 2.5,3 0,0 0))", true); + + // Touching at corner + test_touches<polygon, polygon> + ( + "POLYGON((0 0,0 100,100 100,100 0,0 0))", + "POLYGON((100 100,100 200,200 200, 200 100,100 100))", + true + ); + + // Intersecting at corner + test_touches<polygon, polygon> + ( + "POLYGON((0 0,0 100,101 101,100 0,0 0))", + "POLYGON((100 100,100 200,200 200, 200 100,100 100))", + false + ); + + // Touching at side (interior of a segment) + test_touches<polygon, polygon> + ( + "POLYGON((0 0,0 100,100 100,100 0,0 0))", + "POLYGON((200 0,100 50,200 100,200 0))", + true + ); + + // Touching at side (partly collinear) + test_touches<polygon, polygon> + ( + "POLYGON((0 0,0 100,100 100,100 0,0 0))", + "POLYGON((200 20,100 20,100 80,200 80,200 20))", + true + ); + + // Completely equal + test_touches<polygon, polygon> + ( + "POLYGON((0 0,0 100,100 100,100 0,0 0))", + "POLYGON((0 0,0 100,100 100,100 0,0 0))", + false + ); + + // Spatially equal + test_touches<polygon, polygon> + ( + "POLYGON((0 0,0 100,100 100,100 0,0 0))", + "POLYGON((0 0,0 100,100 100,100 80,100 20,100 0,0 0))", + false + ); + + // Spatially equal (without equal segments) + test_touches<polygon, polygon> + ( + "POLYGON((0 0,0 100,100 100,100 0,0 0))", + "POLYGON((0 0,0 50,0 100,50 100,100 100,100 50,100 0,50 0,0 0))", + false + ); + + + // Touching at side (opposite equal) + test_touches<polygon, polygon> + ( + "POLYGON((0 0,0 100,100 100,100 0,0 0))", + "POLYGON((200 0,100 0,100 100,200 100,200 0))", + true + ); + + // Touching at side (opposite equal - but with real "equal" turning point) + test_touches<polygon, polygon> + ( + "POLYGON((0 0,0 100,100 100,100 80,100 20,100 0,0 0))", + "POLYGON((200 0,100 0,100 20,100 80,100 100,200 100,200 0))", + true + ); + // First partly collinear to side, than overlapping + test_touches<polygon, polygon> + ( + "POLYGON((0 0,0 100,100 100,100 0,0 0))", + "POLYGON((200 20,100 20,100 50,50 50,50 80,100 80,200 80,200 20))", + false + ); + + // Touching interior (= no touch) + test_touches<polygon, polygon> + ( + "POLYGON((0 0,0 100,100 100,100 0,0 0))", + "POLYGON((20 20,20 80,100 50,20 20))", + false + ); + + // Fitting in hole + test_touches<polygon, polygon> + ( + "POLYGON((0 0,0 100,100 100,100 0,0 0),(40 40,60 40,60 60,40 60,40 40))", + "POLYGON((40 40,40 60,60 60,60 40,40 40))", + true + ); + +} + + + + +int test_main( int , char* [] ) +{ + test_all<bg::model::d2::point_xy<double> >(); + + +#if defined(HAVE_TTMATH) + test_all<bg::model::d2::point_xy<ttmath_big> >(); +#endif + + return 0; +} + +/* +with viewy as +( +select geometry::STGeomFromText('POLYGON((0 0,0 100,100 100,100 0,0 0))',0) as p + , geometry::STGeomFromText('POLYGON((200 0,100 50,200 100,200 0))',0) as q +) +-- select p from viewy union all select q from viewy +select p.STTouches(q) from viewy +*/
\ No newline at end of file |