diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 18:24:20 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 18:24:20 +0000 |
commit | 483eb2f56657e8e7f419ab1a4fab8dce9ade8609 (patch) | |
tree | e5d88d25d870d5dedacb6bbdbe2a966086a0a5cf /src/boost/libs/geometry/test/arithmetic | |
parent | Initial commit. (diff) | |
download | ceph-483eb2f56657e8e7f419ab1a4fab8dce9ade8609.tar.xz ceph-483eb2f56657e8e7f419ab1a4fab8dce9ade8609.zip |
Adding upstream version 14.2.21.upstream/14.2.21upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/boost/libs/geometry/test/arithmetic')
5 files changed, 506 insertions, 0 deletions
diff --git a/src/boost/libs/geometry/test/arithmetic/Jamfile.v2 b/src/boost/libs/geometry/test/arithmetic/Jamfile.v2 new file mode 100644 index 00000000..232fe79f --- /dev/null +++ b/src/boost/libs/geometry/test/arithmetic/Jamfile.v2 @@ -0,0 +1,19 @@ +# Boost.Geometry +# +# Copyright (c) 2007-2019 Barend Gehrels, Amsterdam, the Netherlands. +# Copyright (c) 2008-2019 Bruno Lalande, Paris, France. +# Copyright (c) 2009-2019 Mateusz Loskot, London, UK. +# Copyright (c) 2015-2019 Adam Wulkiewicz, Lodz, Poland. +# +# 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) + +test-suite boost-geometry-arithmetic + : + [ run general.cpp : : : : arithmetic_general ] + [ run dot_product.cpp : : : : arithmetic_dot_product ] + [ run cross_product.cpp : : : : arithmetic_cross_product ] + [ run infinite_line_functions.cpp : : : : arithmetic_infinite_line_functions ] + [ compile-fail cross_product.cpp : <define>TEST_FAIL_CROSS_PRODUCT : arithmetic_cross_product_cf ] + ; diff --git a/src/boost/libs/geometry/test/arithmetic/cross_product.cpp b/src/boost/libs/geometry/test/arithmetic/cross_product.cpp new file mode 100644 index 00000000..cb1ddf61 --- /dev/null +++ b/src/boost/libs/geometry/test/arithmetic/cross_product.cpp @@ -0,0 +1,87 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// Unit Test + +// Copyright (c) 2009-2012 Mateusz Loskot, London, UK. +// Copyright (c) 2017 Adam Wulkiewicz, Lodz, Poland. + +// 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 <geometry_test_common.hpp> + +#include <boost/core/ignore_unused.hpp> + +#include <boost/geometry/arithmetic/cross_product.hpp> + +#include <boost/geometry/algorithms/assign.hpp> + +#include <boost/geometry/geometries/point.hpp> +#include <boost/geometry/geometries/adapted/c_array.hpp> +#include <boost/geometry/geometries/adapted/boost_tuple.hpp> +#include <test_common/test_point.hpp> + + +template <typename P> +void test_2d() +{ + P p1; + bg::assign_values(p1, 20, 30); + P p2; + bg::assign_values(p2, 45, 70); + P c = bg::cross_product(p1, p2); + + typedef typename bg::coordinate_type<P>::type scalar_type; + BOOST_CHECK_EQUAL(bg::get<0>(c), scalar_type(50)); +} + +template <typename P> +void test_3d() +{ + P p1; + bg::assign_values(p1, 20, 30, 10); + P p2; + bg::assign_values(p2, 45, 70, 20); + P c = bg::cross_product(p1, p2); + + typedef typename bg::coordinate_type<P>::type scalar_type; + BOOST_CHECK_EQUAL(bg::get<0>(c), scalar_type(-100)); + BOOST_CHECK_EQUAL(bg::get<1>(c), scalar_type(50)); + BOOST_CHECK_EQUAL(bg::get<2>(c), scalar_type(50)); +} + +#ifdef TEST_FAIL_CROSS_PRODUCT +template <typename P> +void test_4d() +{ + P p1; + bg::assign_values(p1, 20, 30, 10); + bg::set<3>(p1, 15); + P p2; + bg::assign_values(p2, 45, 70, 20); + bg::set<3>(p2, 35); + P c = bg::cross_product(p1, p2); + boost::ignore_unused(c); +} +#endif + +int test_main(int, char* []) +{ + test_2d<bg::model::point<int, 2, bg::cs::cartesian> >(); + test_2d<bg::model::point<float, 2, bg::cs::cartesian> >(); + test_2d<bg::model::point<double, 2, bg::cs::cartesian> >(); + + test_3d<bg::model::point<int, 3, bg::cs::cartesian> >(); + test_3d<bg::model::point<float, 3, bg::cs::cartesian> >(); + test_3d<bg::model::point<double, 3, bg::cs::cartesian> >(); + +#ifdef TEST_FAIL_CROSS_PRODUCT + test_4d<bg::model::point<int, 4, bg::cs::cartesian> >(); + test_4d<bg::model::point<float, 4, bg::cs::cartesian> >(); + test_4d<bg::model::point<double, 4, bg::cs::cartesian> >(); +#endif + + return 0; +} + diff --git a/src/boost/libs/geometry/test/arithmetic/dot_product.cpp b/src/boost/libs/geometry/test/arithmetic/dot_product.cpp new file mode 100644 index 00000000..2242e3c3 --- /dev/null +++ b/src/boost/libs/geometry/test/arithmetic/dot_product.cpp @@ -0,0 +1,53 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// Unit Test + +// Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. +// Copyright (c) 2008-2012 Bruno Lalande, Paris, France. +// Copyright (c) 2009-2012 Mateusz Loskot, London, UK. + +// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library +// (geolib/GGL), copyright (c) 1995-2010 Geodan, 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 <geometry_test_common.hpp> + +#include <boost/geometry/arithmetic/dot_product.hpp> + + +#include <boost/geometry/algorithms/assign.hpp> + +#include <boost/geometry/geometries/point.hpp> +#include <boost/geometry/geometries/adapted/c_array.hpp> +#include <boost/geometry/geometries/adapted/boost_tuple.hpp> +#include <test_common/test_point.hpp> + +BOOST_GEOMETRY_REGISTER_C_ARRAY_CS(cs::cartesian) +BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian) + + +template <typename P> +void test_all() +{ + P p1; + bg::assign_values(p1, 1, 2, 3); + P p2; + bg::assign_values(p2, 4, 5, 6); + BOOST_CHECK(bg::dot_product(p1, p2) == 1*4 + 2*5 + 3*6); +} + +int test_main(int, char* []) +{ + test_all<int[3]>(); + test_all<float[3]>(); + test_all<double[3]>(); + test_all<test::test_point>(); + test_all<bg::model::point<int, 3, bg::cs::cartesian> >(); + test_all<bg::model::point<float, 3, bg::cs::cartesian> >(); + test_all<bg::model::point<double, 3, bg::cs::cartesian> >(); + + return 0; +} diff --git a/src/boost/libs/geometry/test/arithmetic/general.cpp b/src/boost/libs/geometry/test/arithmetic/general.cpp new file mode 100644 index 00000000..a329a6e5 --- /dev/null +++ b/src/boost/libs/geometry/test/arithmetic/general.cpp @@ -0,0 +1,142 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// Unit Test + +// Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. +// Copyright (c) 2008-2012 Bruno Lalande, Paris, France. +// Copyright (c) 2009-2012 Mateusz Loskot, London, UK. + +// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library +// (geolib/GGL), copyright (c) 1995-2010 Geodan, 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 <geometry_test_common.hpp> + + +#include <boost/geometry/arithmetic/arithmetic.hpp> + +#include <boost/geometry/algorithms/assign.hpp> + +#include <boost/geometry/geometries/point.hpp> +#include <boost/geometry/geometries/adapted/c_array.hpp> +#include <boost/geometry/geometries/adapted/boost_tuple.hpp> +#include <test_common/test_point.hpp> + +BOOST_GEOMETRY_REGISTER_C_ARRAY_CS(cs::cartesian) +BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian) + + +template <typename P, typename P2> +void test_addition() +{ + P p1; + bg::assign_values(p1, 1, 2, 3); + bg::add_value(p1, 10); + BOOST_CHECK(bg::get<0>(p1) == 11); + BOOST_CHECK(bg::get<1>(p1) == 12); + BOOST_CHECK(bg::get<2>(p1) == 13); + + P2 p2(4, 5, 6); + bg::add_point(p1, p2); + BOOST_CHECK(bg::get<0>(p1) == 15); + BOOST_CHECK(bg::get<1>(p1) == 17); + BOOST_CHECK(bg::get<2>(p1) == 19); +} + +template <typename P, typename P2> +void test_subtraction() +{ + P p1; + bg::assign_values(p1, 1, 2, 3); + bg::subtract_value(p1, 10); + BOOST_CHECK(bg::get<0>(p1) == -9); + BOOST_CHECK(bg::get<1>(p1) == -8); + BOOST_CHECK(bg::get<2>(p1) == -7); + + P2 p2(4, 6, 8); + bg::subtract_point(p1, p2); + BOOST_CHECK(bg::get<0>(p1) == -13); + BOOST_CHECK(bg::get<1>(p1) == -14); + BOOST_CHECK(bg::get<2>(p1) == -15); +} + +template <typename P, typename P2> +void test_multiplication() +{ + P p1; + bg::assign_values(p1, 1, 2, 3); + bg::multiply_value(p1, 5); + BOOST_CHECK(bg::get<0>(p1) == 5); + BOOST_CHECK(bg::get<1>(p1) == 10); + BOOST_CHECK(bg::get<2>(p1) == 15); + + P2 p2(4, 5, 6); + bg::multiply_point(p1, p2); + BOOST_CHECK(bg::get<0>(p1) == 20); + BOOST_CHECK(bg::get<1>(p1) == 50); + BOOST_CHECK(bg::get<2>(p1) == 90); +} + +template <typename P, typename P2> +void test_division() +{ + P p1; + bg::assign_values(p1, 50, 100, 150); + bg::divide_value(p1, 5); + BOOST_CHECK(bg::get<0>(p1) == 10); + BOOST_CHECK(bg::get<1>(p1) == 20); + BOOST_CHECK(bg::get<2>(p1) == 30); + + P2 p2(2, 4, 6); + bg::divide_point(p1, p2); + BOOST_CHECK(bg::get<0>(p1) == 5); + BOOST_CHECK(bg::get<1>(p1) == 5); + BOOST_CHECK(bg::get<2>(p1) == 5); +} + +template <typename P, typename P2> +void test_assign() +{ + P p1; + P2 p2(12, 34, 56); + bg::assign_values(p1, 12, 34, 56); + bg::assign_point(p1, p2); + BOOST_CHECK(bg::get<0>(p1) == 12); + BOOST_CHECK(bg::get<1>(p1) == 34); + BOOST_CHECK(bg::get<2>(p1) == 56); + + bg::assign_value(p1, 78); + BOOST_CHECK(bg::get<0>(p1) == 78); + BOOST_CHECK(bg::get<1>(p1) == 78); + BOOST_CHECK(bg::get<2>(p1) == 78); +} + + +template <typename P> +void test_all() +{ + typedef test::test_const_point P2; + + test_addition<P, P2>(); + test_subtraction<P, P2>(); + test_multiplication<P, P2>(); + test_division<P, P2>(); + test_assign<P, P2>(); +} + + +int test_main(int, char* []) +{ + test_all<int[3]>(); + test_all<float[3]>(); + test_all<double[3]>(); + test_all<test::test_point>(); + test_all<bg::model::point<int, 3, bg::cs::cartesian> >(); + test_all<bg::model::point<float, 3, bg::cs::cartesian> >(); + test_all<bg::model::point<double, 3, bg::cs::cartesian> >(); + + return 0; +} diff --git a/src/boost/libs/geometry/test/arithmetic/infinite_line_functions.cpp b/src/boost/libs/geometry/test/arithmetic/infinite_line_functions.cpp new file mode 100755 index 00000000..9c879178 --- /dev/null +++ b/src/boost/libs/geometry/test/arithmetic/infinite_line_functions.cpp @@ -0,0 +1,205 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// Unit Test + +// Copyright (c) 2018-2019 Barend Gehrels, Amsterdam, the Netherlands. + +// This file was modified by Oracle on 2019. +// Modifications copyright (c) 2019, Oracle and/or its affiliates. +// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle + +// 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 <geometry_test_common.hpp> + +#include <boost/geometry/arithmetic/infinite_line_functions.hpp> +#include <boost/geometry/geometries/infinite_line.hpp> +#include <boost/geometry/algorithms/detail/make/make.hpp> +#include <boost/geometry/geometries/point.hpp> +#include <boost/geometry/io/wkt/wkt.hpp> + +namespace +{ + // Boost.Test does not support BOOST_CHECK_CLOSE for integral types + template <typename T> + bool is_small(T const& value) + { + static long double const epsilon = 1.0e-5; + return bg::math::abs(value) < epsilon; + } +} + +template <typename T, typename C> +void verify_point_on_line(bg::model::infinite_line<T> const& line, + C const& x, C const& y) +{ + BOOST_CHECK_MESSAGE(is_small(line.a * x + line.b * y + line.c), + "Point is not located on the line"); +} + +template <typename T> +void test_side_value() +{ + typedef bg::model::infinite_line<T> line_type; + + // Horizontal line going right + line_type line = bg::detail::make::make_infinite_line<T>(0, 0, 10, 0); + + // Point above (= on left side) + T d = bg::arithmetic::side_value(line, 5, 5); + BOOST_CHECK_MESSAGE(d > 0, "point not on left side"); + + // Point below (= on right side) + d = bg::arithmetic::side_value(line, 5, -5); + BOOST_CHECK_MESSAGE(d < 0, "point not on right side"); + + // Diagonal not through origin, from right (down) to left (up) + line = bg::detail::make::make_infinite_line<T>(5, 2, -7, 10); + d = bg::arithmetic::side_value(line, 5, 2); + BOOST_CHECK_MESSAGE(is_small(d), "point not on line"); + d = bg::arithmetic::side_value(line, -7, 10); + BOOST_CHECK_MESSAGE(is_small(d), "point not on line"); + + // vector is (-12, 8), move (-3,2) on the line from (5,2) + d = bg::arithmetic::side_value(line, 2, 4); + BOOST_CHECK_MESSAGE(is_small(d), "point not on line"); + + // Go perpendicular (2,3) from (2,4) up, so right of the line (negative) + d = bg::arithmetic::side_value(line, 4, 7); + BOOST_CHECK_MESSAGE(d < 0, "point not on right side"); + + // Go perpendicular (2,3) from (2,4) down, so left of the line (positive) + d = bg::arithmetic::side_value(line, 0, 1); + BOOST_CHECK_MESSAGE(d > 0, "point not on left side"); +} + + +template <typename T> +void test_get_intersection() +{ + typedef bg::model::infinite_line<T> line_type; + + // Diagonal lines (first is same as in distance measure, + // second is perpendicular and used there for distance measures) + line_type p = bg::detail::make::make_infinite_line<T>(5, 2, -7, 10); + line_type q = bg::detail::make::make_infinite_line<T>(4, 7, 0, 1); + + typedef bg::model::point<T, 2, bg::cs::cartesian> point_type; + point_type ip; + BOOST_CHECK(bg::arithmetic::intersection_point(p, q, ip)); + + BOOST_CHECK_MESSAGE(is_small(bg::get<0>(ip) - 2), "x-coordinate wrong"); + BOOST_CHECK_MESSAGE(is_small(bg::get<1>(ip) - 4), "y-coordinate wrong"); + + verify_point_on_line(p, bg::get<0>(ip), bg::get<1>(ip)); + verify_point_on_line(q, bg::get<0>(ip), bg::get<1>(ip)); +} + +template <typename T> +void test_same_direction() +{ + bg::model::infinite_line<T> p, q; + + // Exactly opposite, diagonal + p = bg::detail::make::make_infinite_line<T>(2, 1, 12, 11); + q = bg::detail::make::make_infinite_line<T>(12, 11, 2, 1); + BOOST_CHECK(! bg::arithmetic::similar_direction(p, q)); + + // Exactly opposite, horizontal + p = bg::detail::make::make_infinite_line<T>(0, 0, 10, 0); + q = bg::detail::make::make_infinite_line<T>(10, 0, 0, 0); + BOOST_CHECK(! bg::arithmetic::similar_direction(p, q)); + + // Exactly opposite, vertical + p = bg::detail::make::make_infinite_line<T>(0, 0, 0, 10); + q = bg::detail::make::make_infinite_line<T>(0, 10, 0, 0); + BOOST_CHECK(! bg::arithmetic::similar_direction(p, q)); + + // Exactly equal, diagonal + p = bg::detail::make::make_infinite_line<T>(0, 0, 10, 10); + q = bg::detail::make::make_infinite_line<T>(0, 0, 10, 10); + BOOST_CHECK(bg::arithmetic::similar_direction(p, q)); + + // Exactly equal, horizontal + p = bg::detail::make::make_infinite_line<T>(0, 0, 10, 0); + q = bg::detail::make::make_infinite_line<T>(0, 0, 10, 0); + BOOST_CHECK(bg::arithmetic::similar_direction(p, q)); + + // Exactly equal, vertical + p = bg::detail::make::make_infinite_line<T>(0, 0, 0, 10); + q = bg::detail::make::make_infinite_line<T>(0, 0, 0, 10); + BOOST_CHECK(bg::arithmetic::similar_direction(p, q)); + + // Coming together, diagonal + p = bg::detail::make::make_infinite_line<T>(0, 0, 10, 10); + q = bg::detail::make::make_infinite_line<T>(20, 20, 10, 10); + BOOST_CHECK(! bg::arithmetic::similar_direction(p, q)); + + // Leaving from common point, diagonal + p = bg::detail::make::make_infinite_line<T>(10, 10, 0, 0); + q = bg::detail::make::make_infinite_line<T>(0, 0, 10, 10); + BOOST_CHECK(! bg::arithmetic::similar_direction(p, q)); + + // Continuing each other, diagonal + p = bg::detail::make::make_infinite_line<T>(0, 0, 10, 10); + q = bg::detail::make::make_infinite_line<T>(10, 10, 20, 20); + BOOST_CHECK(bg::arithmetic::similar_direction(p, q)); + + // (Nearly) perpendicular + p = bg::detail::make::make_infinite_line<T>(0, 0, 10, 10); + q = bg::detail::make::make_infinite_line<T>(0, 0, -10, 10); + BOOST_CHECK(! bg::arithmetic::similar_direction(p, q)); + + // 45 deg + p = bg::detail::make::make_infinite_line<T>(0, 0, 10, 10); + q = bg::detail::make::make_infinite_line<T>(0, 0, 0, 10); + BOOST_CHECK(bg::arithmetic::similar_direction(p, q)); + + // a bit more than 45 deg + p = bg::detail::make::make_infinite_line<T>(0, 0, 10, 10); + q = bg::detail::make::make_infinite_line<T>(0, 0, -1, 10); + BOOST_CHECK(! bg::arithmetic::similar_direction(p, q)); + + // 135 deg + p = bg::detail::make::make_infinite_line<T>(0, 0, 10, 10); + q = bg::detail::make::make_infinite_line<T>(0, 0, -10, 0); + BOOST_CHECK(! bg::arithmetic::similar_direction(p, q)); +} + +template <typename T> +void test_degenerate() +{ + typedef bg::model::infinite_line<T> line_type; + + line_type line = bg::detail::make::make_infinite_line<T>(0, 0, 10, 0); + BOOST_CHECK(! bg::arithmetic::is_degenerate(line)); + + line = bg::detail::make::make_infinite_line<T>(0, 0, 0, 10); + BOOST_CHECK(! bg::arithmetic::is_degenerate(line)); + + line = bg::detail::make::make_infinite_line<T>(0, 0, 10, 10); + BOOST_CHECK(! bg::arithmetic::is_degenerate(line)); + + line = bg::detail::make::make_infinite_line<T>(0, 0, 0, 0); + BOOST_CHECK(bg::arithmetic::is_degenerate(line)); +} + + +template <typename T> +void test_all() +{ + test_side_value<T>(); + test_get_intersection<T>(); + test_same_direction<T>(); + test_degenerate<T>(); +} + +int test_main(int, char* []) +{ + test_all<double>(); + test_all<long double>(); + test_all<float>(); + test_all<int>(); + return 0; +} |