Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Segment_2_Segment_2_pair< R > Class Template Reference

#include <Segment_2_Segment_2_intersection.h>

Collaboration diagram for Segment_2_Segment_2_pair< R >:

Public Types

enum  Intersection_results { NO, POINT, SEGMENT }
 

Public Member Functions

 Segment_2_Segment_2_pair ()
 
 Segment_2_Segment_2_pair (Segment_2< R > const *seg1, Segment_2< R > const *seg2)
 
 ~Segment_2_Segment_2_pair ()
 
Intersection_results intersection_type () const
 
bool intersection (Point_2< R > &result) const
 
bool intersection (Segment_2< R > &result) const
 

Protected Attributes

Segment_2< R > const * _seg1
 
Segment_2< R > const * _seg2
 
bool _known
 
Intersection_results _result
 
Point_2< R > _intersection_point
 
Point_2< R > _other_point
 

Detailed Description

template<class R>
class Segment_2_Segment_2_pair< R >

Definition at line 61 of file Segment_2_Segment_2_intersection.h.

Member Enumeration Documentation

Constructor & Destructor Documentation

Segment_2_Segment_2_pair ( Segment_2< R > const *  seg1,
Segment_2< R > const *  seg2 
)

Definition at line 445 of file Segment_2_Segment_2_intersection.h.

447 {
448  _seg1 = seg1;
449  _seg2 = seg2;
450  _known = false;
451 }

Definition at line 67 of file Segment_2_Segment_2_intersection.h.

67 {}

Member Function Documentation

bool intersection ( Point_2< R > &  result) const

Definition at line 570 of file Segment_2_Segment_2_intersection.h.

571 {
572  if (!_known)
574  if (_result != POINT)
575  return false;
576  result = _intersection_point;
577  return true;
578 }
Intersection_results intersection_type() const
bool intersection ( Segment_2< R > &  result) const
Segment_2_Segment_2_pair< R >::Intersection_results intersection_type ( ) const

Definition at line 456 of file Segment_2_Segment_2_intersection.h.

References NTS::abs(), CGAL_NTS, do_overlap(), Line_2_Line_2_pair< R >::intersection(), Line_2_Line_2_pair< R >::intersection_type(), Point_2< T >::x(), Vector_2< Type >::x(), Point_2< T >::y(), and Vector_2< Type >::y().

457 {
458  if (_known)
459  return _result;
460  // The non const this pointer is used to cast away const.
461  _known = true;
462  if (!do_overlap(_seg1->bbox(), _seg2->bbox())) {
463  _result = NO;
464  return _result;
465  }
466  Line_2<R> const &l1 = _seg1->supporting_line();
467  Line_2<R> const &l2 = _seg2->supporting_line();
468  Line_2_Line_2_pair<R> linepair(&l1, &l2);
469  switch ( linepair.intersection_type()) {
471  _result = NO;
472  break;
477  break;
479  {
480  typedef typename R::RT RT;
481  Point_2<R> const &start1 = _seg1->start();
482  Point_2<R> const &end1 = _seg1->end();
483  Point_2<R> const &start2 = _seg2->start();
484  Point_2<R> const &end2 = _seg2->end();
485  Vector_2<R> diff1 = end1-start1;
486  Point_2<R> const *minpt;
487  Point_2<R> const *maxpt;
488  if (CGAL_NTS abs(diff1.x()) > CGAL_NTS abs(diff1.y())) {
489  if (start1.x() < end1.x()) {
490  minpt = &start1;
491  maxpt = &end1;
492  } else {
493  minpt = &end1;
494  maxpt = &start1;
495  }
496  if (start2.x() < end2.x()) {
497  if (start2.x() > minpt->x()) {
498  minpt = &start2;
499  }
500  if (end2.x() < maxpt->x()) {
501  maxpt = &end2;
502  }
503  } else {
504  if (end2.x() > minpt->x()) {
505  minpt = &end2;
506  }
507  if (start2.x() < maxpt->x()) {
508  maxpt = &start2;
509  }
510  }
511  if (maxpt->x() < minpt->x()) {
512  _result = NO;
513  return _result;
514  }
515  if (maxpt->x() == minpt->x()) {
516  _intersection_point = *minpt;
517  _result = POINT;
518  return _result;
519  }
520  _intersection_point = *minpt;
521  _other_point = *maxpt;
522  _result = SEGMENT;
523  return _result;
524  } else {
525  if (start1.y() < end1.y()) {
526  minpt = &start1;
527  maxpt = &end1;
528  } else {
529  minpt = &end1;
530  maxpt = &start1;
531  }
532  if (start2.y() < end2.y()) {
533  if (start2.y() > minpt->y()) {
534  minpt = &start2;
535  }
536  if (end2.y() < maxpt->y()) {
537  maxpt = &end2;
538  }
539  } else {
540  if (end2.y() > minpt->y()) {
541  minpt = &end2;
542  }
543  if (start2.y() < maxpt->y()) {
544  maxpt = &start2;
545  }
546  }
547  if (maxpt->y() < minpt->y()) {
548  _result = NO;
549  return _result;
550  }
551  if (maxpt->y() == minpt->y()) {
552  _intersection_point = *minpt;
553  _result = POINT;
554  return _result;
555  }
556  _intersection_point = *minpt;
557  _other_point = *maxpt;
558  _result = SEGMENT;
559  return _result;
560  }
561  }
562  }
563  return _result;
564 }
bool collinear_has_on(const CGAL::Point_2< R > &p) const
Definition: Segment_2.h:120
FT y() const
Definition: Point_2.h:144
CGAL::Line_2< R > supporting_line() const
Definition: Segment_2.h:173
Type x() const
Definition: mapbasic.h:208
FT x() const
Definition: Point_2.h:139
bool intersection(Point_2< R > &result) const
Type y() const
Definition: mapbasic.h:209
CGAL::Point_2< R > end() const
Definition: Segment_2.h:133
bool do_overlap(const Bbox_2 &bb1, const Bbox_2 &bb2)
NT abs(const NT &x)
Definition: number_utils.h:130
Bbox_2 bbox() const
Definition: Segment_2.h:179
#define CGAL_NTS
CGAL::Point_2< R > start() const
Definition: Segment_2.h:130

Here is the call graph for this function:

Member Data Documentation

Point_2<R> _intersection_point
mutableprotected

Definition at line 190 of file Segment_2_Segment_2_intersection.h.

bool _known
mutableprotected

Definition at line 188 of file Segment_2_Segment_2_intersection.h.

Point_2<R> _other_point
mutableprotected

Definition at line 190 of file Segment_2_Segment_2_intersection.h.

Intersection_results _result
mutableprotected

Definition at line 189 of file Segment_2_Segment_2_intersection.h.

Segment_2<R> const* _seg1
protected

Definition at line 186 of file Segment_2_Segment_2_intersection.h.

Segment_2<R> const* _seg2
protected

Definition at line 187 of file Segment_2_Segment_2_intersection.h.


The documentation for this class was generated from the following file: