26 #ifndef WFMATH_SEGMENT_H 27 #define WFMATH_SEGMENT_H 29 #include <wfmath/point.h> 30 #include <wfmath/intersect_decls.h> 35 std::ostream& operator<<(std::ostream& os, const Segment<dim>& s);
37 std::istream& operator>>(std::istream& is, Segment<dim>& s);
57 friend std::ostream& operator<< <dim>(std::ostream& os,
const Segment& s);
58 friend std::istream&
operator>> <dim>(std::istream& is,
Segment& s);
64 bool operator==(
const Segment& b)
const {
return isEqualTo(b);}
65 bool operator!=(
const Segment& b)
const {
return !isEqualTo(b);}
67 bool isValid()
const {
return m_p1.isValid() && m_p2.isValid();}
71 size_t numCorners()
const {
return 2;}
72 Point<dim> getCorner(
size_t i)
const {
return i ? m_p2 : m_p1;}
83 {m_p1 += v; m_p2 += v;
return *
this;}
86 {
return shift(p - getCenter());}
90 {rotatePoint(m, getCenter());
return *
this;}
92 {m_p1.rotate(m, p); m_p2.rotate(m, p);
return *
this;}
103 {
return Ball<dim>(getCenter(), Distance(m_p1, m_p2) / 2);}
105 {
return Ball<dim>(getCenter(), SloppyDistance(m_p1, m_p2) / 2);}
109 {
return Segment(m_p1.toParentCoords(origin, rotation),
110 m_p2.toParentCoords(origin, rotation));}
112 {
return Segment(m_p1.toParentCoords(coords), m_p2.toParentCoords(coords));}
114 {
return Segment(m_p1.toParentCoords(coords), m_p2.toParentCoords(coords));}
122 {
return Segment(m_p1.toLocalCoords(origin, rotation),
123 m_p2.toLocalCoords(origin, rotation));}
125 {
return Segment(m_p1.toLocalCoords(coords), m_p2.toLocalCoords(coords));}
127 {
return Segment(m_p1.toLocalCoords(coords), m_p2.toLocalCoords(coords));}
141 friend bool Intersect<dim>(
const Segment& s,
const Ball<dim>& b,
bool proper);
142 friend bool Contains<dim>(
const Ball<dim>& b,
const Segment& s,
bool proper);
144 friend bool Intersect<dim>(
const Segment& s1,
const Segment& s2,
bool proper);
145 friend bool Contains<dim>(
const Segment& s1,
const Segment& s2,
bool proper);
164 return Equal(m_p1, s.m_p1, epsilon)
165 && Equal(m_p2, s.m_p2, epsilon);
170 #endif // WFMATH_SEGMENT_H Generic library namespace.
const Point< dim > & endpoint(const int i) const
get one end of the segment
A dim dimensional axis-aligned box.
A dim dimensional rotation matrix. Technically, a member of the group O(dim).
double CoordType
Basic floating point type.
A dim dimensional box, lying at an arbitrary angle.
A polygon, all of whose points lie in a plane, embedded in dim dimensions.
Point< dim > Midpoint(const Point< dim > &p1, const Point< dim > &p2, CoordType dist=0.5)
Segment()
construct an uninitialized segment
A dim dimensional vector.
A line segment embedded in dim dimensions.
Point< dim > & endpoint(const int i)
get one end of the segment
Segment(const Point< dim > &p1, const Point< dim > &p2)
construct a segment with endpoints p1 and p2