@@ -353,6 +353,42 @@ class Segment_2_Segment_2_pair {
353353 mutable typename K::Point_2 _intersection_point, _other_point;
354354};
355355
356+
357+ inline
358+ double s2s2_alpha (double x0, double y0,
359+ double x1, double y1,
360+ double x2, double y2,
361+ double x3, double y3)
362+ {
363+ const double s1_dx = x0 - x1,
364+ s1_dy = y0 - y1,
365+ s2_dx = x3 - x2,
366+ s2_dy = y3 - y2,
367+ lx = x3 - x1,
368+ ly = y3 - y1;
369+ double val = std::fma (lx,s2_dy,-ly*s2_dx)/std::fma (s1_dx,s2_dy,-s1_dy*s2_dx);
370+ if (val!=val) return 0.5 ;
371+ if (val<0 ) return 0 ;
372+ if (val>1 ) return 1 ;
373+ return val;
374+ }
375+
376+ template <class FT >
377+ FT s2s2_alpha (const FT& x0, const FT& y0,
378+ const FT& x1, const FT& y1,
379+ const FT& x2, const FT& y2,
380+ const FT& x3, const FT& y3)
381+ {
382+ FT s1_dx = x0 - x1,
383+ s1_dy = y0 - y1,
384+ s2_dx = x3 - x2,
385+ s2_dy = y3 - y2,
386+ lx = x3 - x1,
387+ ly = y3 - y1;
388+ return (lx*s2_dy-ly*s2_dx)/(s1_dx*s2_dy-s1_dy*s2_dx);
389+ }
390+
391+
356392template <class K >
357393typename Segment_2_Segment_2_pair<K>::Intersection_results
358394Segment_2_Segment_2_pair<K>::intersection_type() const
@@ -400,14 +436,8 @@ Segment_2_Segment_2_pair<K>::intersection_type() const
400436 : CGAL::make_array ( _seg2->point (s2s2_id[c][2 ]), _seg2->point (s2s2_id[c][3 ]),
401437 _seg1->point (s2s2_id[c][0 ]), _seg1->point (s2s2_id[c][1 ]) );
402438
403- typename K::FT s1_dx = pts[0 ].x () - pts[1 ].x (),
404- s1_dy = pts[0 ].y () - pts[1 ].y (),
405- s2_dx = pts[3 ].x () - pts[2 ].x (),
406- s2_dy = pts[3 ].y () - pts[2 ].y (),
407- lx = pts[3 ].x () - pts[1 ].x (),
408- ly = pts[3 ].y () - pts[1 ].y ();
439+ typename K::FT alpha = s2s2_alpha (pts[0 ].x (), pts[0 ].y (), pts[1 ].x (), pts[1 ].y (), pts[2 ].x (), pts[2 ].y (), pts[3 ].x (), pts[3 ].y ());
409440
410- typename K::FT alpha = (lx*s2_dy-ly*s2_dx)/(s1_dx*s2_dy-s1_dy*s2_dx);
411441 _intersection_point = K ().construct_barycenter_2_object ()(pts[0 ], alpha, pts[1 ]);
412442
413443 return _result;
0 commit comments