[buffer] pass points instead of segments to line_line_intersection

This commit is contained in:
Barend Gehrels
2014-06-22 22:01:43 +02:00
parent 51121c1e35
commit 86a2adef88
2 changed files with 14 additions and 20 deletions

View File

@@ -43,7 +43,6 @@ struct buffer_range
{
typedef typename point_type<RingOutput>::type output_point_type;
typedef typename coordinate_type<RingOutput>::type coordinate_type;
typedef model::referring_segment<output_point_type const> segment_type;
template
@@ -103,11 +102,9 @@ struct buffer_range
RobustPolicy const& )
{
segment_type previous_segment(prev_perp1, prev_perp2);
segment_type segment(perp1, perp2);
output_point_type intersection_point;
if (line_line_intersection<output_point_type, segment_type>::apply(
segment, previous_segment, intersection_point))
if (line_line_intersection::apply(
perp1, perp2, prev_perp1, prev_perp2, intersection_point))
{
std::vector<output_point_type> range_out;
if (join_strategy.apply(intersection_point,
@@ -247,7 +244,6 @@ struct buffer_point
{
typedef typename point_type<RingOutput>::type output_point_type;
typedef typename coordinate_type<RingOutput>::type coordinate_type;
typedef model::referring_segment<output_point_type const> segment_type;
typedef typename geometry::select_most_precise
<

View File

@@ -24,7 +24,6 @@ namespace detail { namespace buffer
// TODO: once change this to proper strategy
// It is different from current segment intersection because these are not segments but lines
// If we have the Line concept, we can create a strategy
template <typename Point, typename Line1, typename Line2 = Line1>
struct line_line_intersection
{
template <typename A, typename B, typename C, typename D>
@@ -42,16 +41,14 @@ struct line_line_intersection
&& math::sign(dy1) == math::sign(dy2);
}
static inline bool apply(Line1 const& line1, Line2 const& line2, Point& ip)
template <typename Point>
static inline bool apply(Point const& pi, Point const& pj,
Point const& qi, Point const& qj, Point& ip)
{
// See http://mathworld.wolfram.com/Line-LineIntersection.html
typedef typename coordinate_type<Point>::type coordinate_type;
coordinate_type x1 = get<0,0>(line1), y1 = get<0,1>(line1);
coordinate_type x2 = get<1,0>(line1), y2 = get<1,1>(line1);
coordinate_type x3 = get<0,0>(line2), y3 = get<0,1>(line2);
coordinate_type x4 = get<1,0>(line2), y4 = get<1,1>(line2);
coordinate_type denominator = det(x1 - x2, y1 - y2, x3 - x4, y3 - y4);
coordinate_type denominator = det(get<0>(pi) - get<0>(pj), get<1>(pi) - get<1>(pj), get<0>(qi) - get<0>(qj), get<1>(qi) - get<1>(qj));
// TODO: maybe use something else then denominator (sides?) to determine this.
@@ -74,7 +71,10 @@ struct line_line_intersection
// +---------------/ x3,y4
// x4,y4
// We then calculate the IP from one of the segments up to a certain distance
if (parallel_continue(x4 - x3, y4 - y3, x2 - x1, y2 - y1))
if (parallel_continue(get<0>(qj) - get<0>(qi),
get<1>(qj) - get<1>(qi),
get<0>(pj) - get<0>(pi),
get<1>(pj) - get<1>(pi)))
{
return false;
}
@@ -82,13 +82,11 @@ struct line_line_intersection
denominator = limit;
}
coordinate_type d1 = det(x1, y1, x2, y2);
coordinate_type d2 = det(x3, y3, x4, y4);
coordinate_type px = det(d1, x1 - x2, d2, x3 - x4) / denominator;
coordinate_type py = det(d1, y1 - y2, d2, y3 - y4) / denominator;
coordinate_type d1 = det(get<0>(pi), get<1>(pi), get<0>(pj), get<1>(pj));
coordinate_type d2 = det(get<0>(qi), get<1>(qi), get<0>(qj), get<1>(qj));
set<0>(ip, px);
set<1>(ip, py);
set<0>(ip, det(d1, get<0>(pi) - get<0>(pj), d2, get<0>(qi) - get<0>(qj)) / denominator);
set<1>(ip, det(d1, get<1>(pi) - get<1>(pj), d2, get<1>(qi) - get<1>(qj)) / denominator);
return true;
}