mirror of
https://github.com/boostorg/geometry.git
synced 2025-05-11 13:34:10 +00:00
[buffer] Remove helper functions now not used/need anymore
This commit is contained in:
parent
0f930efb21
commit
d06c25bc5f
@ -1,129 +0,0 @@
|
||||
// Boost.Geometry (aka GGL, Generic Geometry Library)
|
||||
|
||||
// Copyright (c) 2011-2014 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)
|
||||
|
||||
#ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_INTERSECTION_SIDE_HPP
|
||||
#define BOOST_GEOMETRY_ALGORITHMS_DETAIL_INTERSECTION_SIDE_HPP
|
||||
|
||||
#include <boost/geometry/algorithms/detail/recalculate.hpp>
|
||||
#include <boost/geometry/algorithms/detail/assign_indexed_point.hpp>
|
||||
#include <boost/geometry/geometries/segment.hpp>
|
||||
#include <boost/geometry/strategies/intersection_result.hpp>
|
||||
#include <boost/geometry/strategies/side.hpp>
|
||||
#include <boost/geometry/strategies/cartesian/cart_intersect.hpp>
|
||||
#include <boost/geometry/policies/robustness/segment_ratio_type.hpp>
|
||||
#include <boost/geometry/policies/relate/intersection_ratios.hpp>
|
||||
|
||||
namespace boost { namespace geometry
|
||||
{
|
||||
|
||||
namespace detail { namespace intersection_side
|
||||
{
|
||||
|
||||
|
||||
//! Calculates the side (left=1,right=-1,collinear=0) of the intersection point
|
||||
//! of p/q (if any) with respect to segment s.
|
||||
//! This is not done by calculating IP p/q and calling side, because that is
|
||||
//! (even if robust_policy is used) not robust: the IP can be rounded off.
|
||||
//! So it is done by investigating the sides of the segments, and calculating
|
||||
//! the segment_ratios of the IP and check which side it is.
|
||||
//! Return value is conform geometry::side
|
||||
//! Currently all points are of same type
|
||||
//! Even if there is no IP at all, a side is returned. IP is not calculated on
|
||||
//! itself
|
||||
template <typename Point, typename RobustPolicy>
|
||||
inline int intersection_side(Point const& pi, Point const& pj,
|
||||
Point const& qi, Point const& qj,
|
||||
Point const& si, Point const& sj,
|
||||
RobustPolicy const& robust_policy)
|
||||
{
|
||||
typedef typename geometry::robust_point_type
|
||||
<
|
||||
Point,
|
||||
RobustPolicy
|
||||
>::type robust_point_type;
|
||||
typedef typename geometry::segment_ratio_type
|
||||
<
|
||||
Point,
|
||||
RobustPolicy
|
||||
>::type segment_ratio_type;
|
||||
|
||||
robust_point_type pi_rob, pj_rob, qi_rob, qj_rob, si_rob, sj_rob;
|
||||
geometry::recalculate(pi_rob, pi, robust_policy);
|
||||
geometry::recalculate(pj_rob, pj, robust_policy);
|
||||
geometry::recalculate(qi_rob, qi, robust_policy);
|
||||
geometry::recalculate(qj_rob, qj, robust_policy);
|
||||
geometry::recalculate(si_rob, si, robust_policy);
|
||||
geometry::recalculate(sj_rob, sj, robust_policy);
|
||||
|
||||
typedef typename geometry::strategy::side::services::default_strategy
|
||||
<
|
||||
typename geometry::cs_tag<robust_point_type>::type
|
||||
>::type side_strategy;
|
||||
|
||||
int const side_pi = side_strategy::apply(pi_rob, si_rob, sj_rob);
|
||||
int const side_pj = side_strategy::apply(pj_rob, si_rob, sj_rob);
|
||||
if (side_pi == side_pj)
|
||||
{
|
||||
return side_pi;
|
||||
}
|
||||
|
||||
int const side_qi = side_strategy::apply(qi_rob, si_rob, sj_rob);
|
||||
int const side_qj = side_strategy::apply(qj_rob, si_rob, sj_rob);
|
||||
if (side_qi == side_qj)
|
||||
{
|
||||
// Same here, see comment above
|
||||
return side_qi;
|
||||
}
|
||||
|
||||
typedef model::referring_segment<const Point> segment_type;
|
||||
|
||||
segment_type p(pi, pj);
|
||||
segment_type q(qi, qj);
|
||||
segment_type s(si, sj);
|
||||
|
||||
// No segment lies on the left or right or completely collinear
|
||||
// Relate segments p // q and p // s, don't calculate IP's but just return
|
||||
// the ratios. Both ratios called "robust_ra" are measured on p and can be
|
||||
// related.
|
||||
fraction_type<segment_ratio_type> ratio_p_wrt_q
|
||||
= strategy::intersection::relate_cartesian_segments
|
||||
<
|
||||
policies::relate::segments_intersection_ratios
|
||||
<
|
||||
fraction_type<segment_ratio_type>
|
||||
>
|
||||
>::apply(p, q, robust_policy, pi_rob, pj_rob, qi_rob, qj_rob);
|
||||
|
||||
fraction_type<segment_ratio_type> ratio_p_wrt_s
|
||||
= strategy::intersection::relate_cartesian_segments
|
||||
<
|
||||
policies::relate::segments_intersection_ratios
|
||||
<
|
||||
fraction_type<segment_ratio_type>
|
||||
>
|
||||
>::apply(p, s, robust_policy, pi_rob, pj_rob, si_rob, sj_rob);
|
||||
|
||||
return
|
||||
|
||||
// Closer to the segment start point of p -> side of pi
|
||||
ratio_p_wrt_q.robust_ra < ratio_p_wrt_s.robust_ra ? side_pi
|
||||
|
||||
// Ratios are equal, IP must be exactly on the segment
|
||||
: ratio_p_wrt_q.robust_ra == ratio_p_wrt_s.robust_ra ? 0
|
||||
|
||||
// ratio p wrt q is larger than ratio p wrt s
|
||||
// So: close to the segment end point of p -> side of pj
|
||||
: side_pj;
|
||||
}
|
||||
|
||||
|
||||
}} // namespace detail::intersection_side
|
||||
|
||||
}} // namespace boost::geometry
|
||||
|
||||
#endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_INTERSECTION_SIDE_HPP
|
@ -1,168 +0,0 @@
|
||||
// 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)
|
||||
|
||||
#ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_BUFFER_SIDE_ON_CONVEX_RANGE_HPP
|
||||
#define BOOST_GEOMETRY_ALGORITHMS_DETAIL_BUFFER_SIDE_ON_CONVEX_RANGE_HPP
|
||||
|
||||
#include <boost/range.hpp>
|
||||
#include <boost/geometry/algorithms/detail/overlay/segment_identifier.hpp>
|
||||
#include <boost/geometry/algorithms/detail/intersection_side.hpp>
|
||||
|
||||
namespace boost { namespace geometry
|
||||
{
|
||||
|
||||
#ifndef DOXYGEN_NO_DETAIL
|
||||
namespace detail { namespace buffer
|
||||
{
|
||||
|
||||
template <int D>
|
||||
struct collinear_point_on_segment_check
|
||||
{
|
||||
template <typename T>
|
||||
static inline bool apply_sorted(T const& subject, T const& c1, T const& c2)
|
||||
{
|
||||
return subject >= c1 && subject <= c2;
|
||||
}
|
||||
|
||||
template <typename P0, typename P1, typename P2>
|
||||
static inline bool apply(P0 const& subject, P1 const& p1, P2 const& p2)
|
||||
{
|
||||
typedef typename geometry::coordinate_type<P0>::type coordinate_type;
|
||||
coordinate_type const cs = geometry::get<D>(subject);
|
||||
coordinate_type const c1 = geometry::get<D>(p1);
|
||||
coordinate_type const c2 = geometry::get<D>(p2);
|
||||
return c1 > c2
|
||||
? apply_sorted(cs, c2, c1)
|
||||
: apply_sorted(cs, c1, c2)
|
||||
;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// Checks is subject-point is on the segment, provided that it is already determined that it was collinear
|
||||
template <typename P0, typename P1, typename P2>
|
||||
inline bool collinear_point_on_segment(P0 const& subject, P1 const& p1, P2 const& p2)
|
||||
{
|
||||
return collinear_point_on_segment_check<0>::apply(subject, p1, p2)
|
||||
&& collinear_point_on_segment_check<1>::apply(subject, p1, p2);
|
||||
}
|
||||
|
||||
|
||||
template <typename SideStrategy, typename Point, typename Iterator>
|
||||
static inline int side_on_convex_range(Point const& subject,
|
||||
Iterator first, Iterator last,
|
||||
/* by value: */ segment_identifier seg_id,
|
||||
segment_identifier& on_segment_seg_id)
|
||||
{
|
||||
bool has_collinear = false;
|
||||
Iterator it = first;
|
||||
|
||||
if (it == last)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
Point previous = *it;
|
||||
|
||||
for (++it; it != last; ++it, seg_id.segment_index++)
|
||||
{
|
||||
Point current = *it;
|
||||
int const side = SideStrategy::apply(subject, previous, current);
|
||||
switch(side)
|
||||
{
|
||||
case 1 :
|
||||
return 1;
|
||||
case 0 :
|
||||
// Check if it is REALLY on the segment.
|
||||
// If not, it is either on the left (because polygon is convex)
|
||||
// or it is still on one of the other segments (if segments are collinear)
|
||||
if (collinear_point_on_segment(subject, previous, current))
|
||||
{
|
||||
on_segment_seg_id = seg_id;
|
||||
return 0;
|
||||
}
|
||||
has_collinear = true;
|
||||
break;
|
||||
}
|
||||
previous = current;
|
||||
}
|
||||
return has_collinear ? 1 : -1;
|
||||
}
|
||||
|
||||
template <typename SideStrategy, typename Point, typename Range>
|
||||
inline int side_on_convex_range(Point const& subject, Range const& range)
|
||||
{
|
||||
segment_identifier dummy;
|
||||
return side_on_convex_range<SideStrategy>(subject,
|
||||
boost::begin(range), boost::end(range),
|
||||
dummy, dummy);
|
||||
}
|
||||
|
||||
template <typename SideStrategy, typename Point, typename Iterator, typename RobustPolicy>
|
||||
static inline int intersection_side_on_convex_range(Point const& subject,
|
||||
Point const& pi, Point const& pj,
|
||||
Point const& qi, Point const& qj,
|
||||
Iterator first, Iterator last,
|
||||
/* by value: */ segment_identifier seg_id,
|
||||
segment_identifier& on_segment_seg_id,
|
||||
RobustPolicy const& robust_policy)
|
||||
{
|
||||
bool has_collinear = false;
|
||||
Iterator it = first;
|
||||
|
||||
if (it == last)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
Point previous = *it;
|
||||
|
||||
for (++it; it != last; ++it, seg_id.segment_index++)
|
||||
{
|
||||
Point current = *it;
|
||||
int const side = detail::intersection_side::intersection_side(pi, pj, qi, qj, previous, current, robust_policy);
|
||||
switch(side)
|
||||
{
|
||||
case 1 :
|
||||
return 1;
|
||||
case 0 :
|
||||
// Check if it is REALLY on the segment.
|
||||
// If not, it is either on the left (because polygon is convex)
|
||||
// or it is still on one of the other segments (if segments are collinear)
|
||||
if (collinear_point_on_segment(subject, previous, current))
|
||||
{
|
||||
on_segment_seg_id = seg_id;
|
||||
return 0;
|
||||
}
|
||||
has_collinear = true;
|
||||
break;
|
||||
}
|
||||
previous = current;
|
||||
}
|
||||
return has_collinear ? 1 : -1;
|
||||
}
|
||||
|
||||
template <typename SideStrategy, typename Point, typename Range, typename RobustPolicy>
|
||||
inline int intersection_side_on_convex_range(Point const& subject,
|
||||
Point const& pi, Point const& pj,
|
||||
Point const& qi, Point const& qj,
|
||||
Range const& range,
|
||||
RobustPolicy const& robust_policy)
|
||||
{
|
||||
segment_identifier dummy;
|
||||
return intersection_side_on_convex_range<SideStrategy>(subject, pi, pj, qi, qj,
|
||||
boost::begin(range), boost::end(range),
|
||||
dummy, dummy, robust_policy);
|
||||
}
|
||||
|
||||
}} // namespace detail::buffer
|
||||
#endif // DOXYGEN_NO_DETAIL
|
||||
|
||||
}} // namespace boost::geometry
|
||||
|
||||
#endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_BUFFER_SIDE_ON_CONVEX_RANGE_HPP
|
@ -10,7 +10,6 @@
|
||||
|
||||
test-suite boost-geometry-algorithms-detail
|
||||
:
|
||||
[ run intersection_side.cpp ]
|
||||
[ run partition.cpp ]
|
||||
;
|
||||
|
||||
|
@ -1,197 +0,0 @@
|
||||
// Boost.Geometry (aka GGL, Generic Geometry Library)
|
||||
//
|
||||
// Copyright (c) 2007-2014 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)
|
||||
|
||||
#define BOOST_GEOMETRY_DEFINE_STREAM_OPERATOR_SEGMENT_RATIO
|
||||
|
||||
#include <geometry_test_common.hpp>
|
||||
|
||||
#include <boost/geometry/geometries/point_xy.hpp>
|
||||
|
||||
#include <boost/geometry/strategies/cartesian/cart_intersect.hpp>
|
||||
#include <boost/geometry/strategies/intersection_result.hpp>
|
||||
#include <boost/geometry/policies/relate/intersection_points.hpp>
|
||||
#include <boost/geometry/policies/relate/intersection_ratios.hpp>
|
||||
#include <boost/geometry/policies/robustness/no_rescale_policy.hpp>
|
||||
#include <boost/geometry/algorithms/detail/intersection_side.hpp>
|
||||
#include <boost/geometry/algorithms/make.hpp>
|
||||
|
||||
#if defined(TEST_WITH_SVG)
|
||||
# include <boost/geometry/io/svg/svg_mapper.hpp>
|
||||
#endif
|
||||
|
||||
|
||||
template <typename Point, typename T>
|
||||
void test_one(std::string const& caseid,
|
||||
T pi_x, T pi_y, T pj_x, T pj_y, // line p to intersect
|
||||
T qi_x, T qi_y, T qj_x, T qj_y, // line q to intersect
|
||||
T si_x, T si_y, T sj_x, T sj_y, // subject line to find side on of IP p/q
|
||||
int expected_side)
|
||||
{
|
||||
typedef bg::detail::no_rescale_policy robust_policy_type;
|
||||
robust_policy_type robust_policy;
|
||||
|
||||
Point pi = bg::make<Point>(pi_x, pi_y);
|
||||
Point pj = bg::make<Point>(pj_x, pj_y);
|
||||
Point qi = bg::make<Point>(qi_x, qi_y);
|
||||
Point qj = bg::make<Point>(qj_x, qj_y);
|
||||
Point si = bg::make<Point>(si_x, si_y);
|
||||
Point sj = bg::make<Point>(sj_x, sj_y);
|
||||
|
||||
typedef bg::model::referring_segment<const Point> segment_type;
|
||||
|
||||
segment_type p(pi, pj);
|
||||
segment_type q(qi, qj);
|
||||
segment_type s(si, sj);
|
||||
|
||||
int detected_side = bg::detail::intersection_side::intersection_side(pi, pj,
|
||||
qi, qj, si, sj, robust_policy);
|
||||
|
||||
BOOST_CHECK_EQUAL(expected_side, detected_side);
|
||||
|
||||
#if defined(TEST_WITH_SVG)
|
||||
{
|
||||
std::ostringstream filename;
|
||||
filename << "intersection_side_" << caseid
|
||||
<< "_" << string_from_type<typename bg::coordinate_type<Point>::type>::name()
|
||||
<< ".svg";
|
||||
|
||||
std::ofstream svg(filename.str().c_str());
|
||||
|
||||
bg::svg_mapper<Point> mapper(svg, 500, 500);
|
||||
mapper.add(p);
|
||||
mapper.add(q);
|
||||
mapper.add(s);
|
||||
|
||||
mapper.map(p, "opacity:0.7;stroke:rgb(0,192,0);stroke-width:3");
|
||||
mapper.map(q, "opacity:0.7;stroke:rgb(0,0,255);stroke-width:3");
|
||||
mapper.map(s, "opacity:0.7;stroke:rgb(255,0,0);stroke-width:2");
|
||||
|
||||
std::string style = ";font-family='Verdana';font-weight:bold";
|
||||
std::string align = ";text-anchor:end;text-align:end";
|
||||
int offset = 8;
|
||||
|
||||
mapper.text(pi, "pi", "fill:rgb(0,192,0)" + style, offset, offset);
|
||||
mapper.text(pj, "pj", "fill:rgb(0,192,0)" + style, offset, offset);
|
||||
|
||||
mapper.text(qi, "qi", "fill:rgb(0,0,255)" + style + align, -offset, offset);
|
||||
mapper.text(qj, "qj", "fill:rgb(0,0,255)" + style + align, -offset, offset);
|
||||
|
||||
mapper.text(si, "si", "fill:rgb(255,0,0)" + style + align, -offset, offset);
|
||||
mapper.text(sj, "sj", "fill:rgb(255,0,0)" + style + align, -offset, offset);
|
||||
|
||||
// Map the intersection point on the SVG
|
||||
{
|
||||
typedef typename bg::segment_ratio_type
|
||||
<
|
||||
Point,
|
||||
robust_policy_type
|
||||
>::type segment_ratio_type;
|
||||
|
||||
// Get the intersection point (or two points)
|
||||
bg::segment_intersection_points<Point, segment_ratio_type> is
|
||||
= bg::strategy::intersection::relate_cartesian_segments
|
||||
<
|
||||
bg::policies::relate::segments_intersection_points
|
||||
<
|
||||
bg::segment_intersection_points<Point, segment_ratio_type>
|
||||
>
|
||||
>::apply(p, q, robust_policy);
|
||||
|
||||
bg::fraction_type<segment_ratio_type> rs
|
||||
= bg::strategy::intersection::relate_cartesian_segments
|
||||
<
|
||||
bg::policies::relate::segments_intersection_ratios
|
||||
<
|
||||
bg::fraction_type<segment_ratio_type>
|
||||
>
|
||||
>::apply(p, q, robust_policy);
|
||||
|
||||
for (int i = 0; i < is.count; i++)
|
||||
{
|
||||
mapper.map(is.intersections[i], "opacity:0.8;stroke:rgb(255,128,0);stroke-width:3", 3);
|
||||
std::ostringstream out;
|
||||
out << detected_side << " " << is.fractions[i].robust_ra << " / " << is.fractions[i].robust_rb
|
||||
<< std::endl
|
||||
<< rs.robust_ra << " / " << rs.robust_rb;
|
||||
mapper.text(is.intersections[i], out.str(), "fill:rgb(255,128,0)" + style + align, -2 * offset, offset);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
||||
template <typename P>
|
||||
void test_all()
|
||||
{
|
||||
test_one<P, double>("simplex_left",
|
||||
0, 0, 4, 4, // p
|
||||
-1, 4, 3, 0, // q
|
||||
2, 0, 2, 4, // subject
|
||||
1);
|
||||
test_one<P, double>("simplex_right",
|
||||
0, 0, 4, 4, // p
|
||||
1, 4, 5, 0, // q
|
||||
2, 0, 2, 4, // subject
|
||||
-1);
|
||||
test_one<P, double>("simplex_collinear",
|
||||
0, 0, 4, 4, // p
|
||||
0, 4, 4, 0, // q
|
||||
2, 0, 2, 4, // subject
|
||||
0);
|
||||
|
||||
test_one<P, double>("p_left",
|
||||
0, 0, 0, 4, // p
|
||||
1, 4, 5, 0, // q
|
||||
2, 0, 2, 4, // subject
|
||||
1);
|
||||
|
||||
test_one<P, double>("p_right",
|
||||
4, 0, 4, 4, // p
|
||||
1, 4, 5, 0, // q
|
||||
2, 0, 2, 4, // subject
|
||||
-1);
|
||||
test_one<P, double>("p_left",
|
||||
1, 0, 1, 4, // p
|
||||
1, 4, 5, 0, // q
|
||||
2, 0, 2, 4, // subject
|
||||
1);
|
||||
|
||||
test_one<P, double>("p_collinear",
|
||||
2, -1, 2, 5, // p
|
||||
1, 4, 5, 0, // q
|
||||
2, 0, 2, 4, // subject
|
||||
0);
|
||||
|
||||
test_one<P, double>("q_left",
|
||||
0, 0, 4, 4, // p
|
||||
1, 4, 1, 0, // q
|
||||
2, 0, 2, 4, // subject
|
||||
1);
|
||||
|
||||
test_one<P, double>("q_right",
|
||||
0, 0, 4, 4, // p
|
||||
3, 4, 3, 0, // q
|
||||
2, 0, 2, 4, // subject
|
||||
-1);
|
||||
|
||||
test_one<P, double>("q_collinear",
|
||||
0, 0, 4, 4, // p
|
||||
2, 1, 2, 3, // q
|
||||
2, 0, 2, 4, // subject
|
||||
0);
|
||||
}
|
||||
|
||||
|
||||
int test_main( int , char* [] )
|
||||
{
|
||||
test_all<bg::model::d2::point_xy<double> >();
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user