99 return OGDF_GEOM_ET.equal(m_x, dp.
m_x) && OGDF_GEOM_ET.equal(m_y,dp.
m_y);
104 return !(*
this == p);
109 bool operator<(const GenericPoint<T> &p)
const {
111 return OGDF_GEOM_ET.less(m_x, p.m_x)
112 || (OGDF_GEOM_ET.equal(m_x, p.m_x) && OGDF_GEOM_ET.less(m_y, p.m_y));
132 const double dx1 = q.
m_x - m_x, dy1 = q.
m_y - m_y;
133 const double dx2 = r.
m_x - m_x, dy2 = r.
m_y - m_y;
136 if ((dx1 == 0 && dy1 == 0) || (dx2 == 0 && dy2 == 0)) {
140 double phi = std::atan2(dy2, dx2) - std::atan2(dy1, dx1);
153 double dx = p.
m_x - m_x;
154 double dy = p.
m_y - m_y;
155 return sqrt( dx * dx + dy * dy );
160 return sqrt(m_x*m_x + m_y*m_y);
208 return (m_x * dv.
m_y) - (m_y * dv.
m_x);
213 return (m_x * dv.
m_x) + (m_y * dv.
m_y);
225 ret.
m_x = - m_y / m_x;
235 std::ostream &operator<<(std::ostream &os, const GenericPoint<T>& p) {
236 os <<
"(" << p.
m_x <<
"," << p.m_y <<
")";
250 return 7*ip.
m_x + 23*ip.
m_y;
262 template<
class Po
intType>
287 pred = iter = this->begin();
290 while (iter.
valid()) {
291 len += (*iter).distance(*pred);
310 if (len < 0.0) { len = length(); }
313 DPoint p = *(this->begin());
315 double pos = len * fraction;
319 pred = iter = this->begin();
323 double DX = 0, DY = 0;
324 while (iter.
valid()) {
325 DX = (*iter).m_x - (*pred).m_x;
326 DY = (*iter).m_y - (*pred).m_y;
327 seglen = sqrt( DX*DX + DY*DY );
336 p = *(this->rbegin());
341 double segpos = seglen + pos - liter;
343 double dx = DX * segpos / seglen;
344 double dy = DY * segpos / seglen;
356 if (this->empty())
return;
358 for (iter = next = this->begin(), ++next; next.
valid() && (this->size() > 2); ++next) {
359 if (*iter == *next) {
377 double maxAngle = 2*
Math::pi - minAngle;
381 while (iter.
valid()) {
383 if (!next.
valid()) {
break; }
384 onext = next; ++onext;
385 if (!onext.
valid()) {
break; }
386 double phi = (*next).angle(*iter, *onext);
389 if (OGDF_GEOM_ET.geq(phi, minAngle) &&
390 OGDF_GEOM_ET.leq(phi, maxAngle)) {
392 if (iter != this->begin()) {
420 normalizeUnified(minAngle);
430 this->pushFront(src);
445 template<
class Po
intType>
466 GenericLine(
const PointType &p1,
const PointType &p2) : m_p1(p1), m_p2(p2) {}
473 :
GenericLine(PointType(x1, y1), PointType(x2, y2)) {}
477 return isVertical() ? dl.
isVertical() && m_p1.m_x == dl.
m_p1.m_x :
478 slope() == dl.
slope() && yAbs() == dl.
yAbs();
483 return !(*
this == dl);
496 bool isVertical()
const {
return OGDF_GEOM_ET.equal(dx(), 0.0); }
503 return isVertical() ? std::numeric_limits<double>::max() : dy()/dx();
509 return isVertical() ? std::numeric_limits<double>::max() : m_p1.m_y - (slope() * m_p1.m_x);
520 return dx() * line.
dy() - dy() * line.
dx();
534 return OGDF_GEOM_ET.equal(m_p1.m_x, line.
m_p1.m_x) ?
536 }
else if (isVertical()) {
542 }
else if (OGDF_GEOM_ET.equal(slope(), line.
slope())) {
545 return OGDF_GEOM_ET.equal(yAbs(), line.
yAbs()) ?
548 double ix = (line.
yAbs() - yAbs()) / (slope() - line.
slope());
549 inter =
DPoint(ix, slope() * ix + yAbs());
556 if (p == m_p1 || p == m_p2) {
561 return OGDF_GEOM_ET.equal(p.
m_x, m_p1.m_x);
564 double dx2p = p.
m_x - m_p1.m_x;
565 double dy2p = p.
m_y - m_p1.m_y;
572 return OGDF_GEOM_ET.equal(slope(), (dy2p/dx2p));
585 if (isHorizontal()) {
589 crossing = (m_p1.m_x * (m_p2.m_y - horAxis) -
590 m_p2.m_x * (m_p1.m_y - horAxis) ) / dy();
607 crossing = (m_p1.m_y * (m_p2.m_x - verAxis) -
608 m_p2.m_y * (m_p1.m_x - verAxis) ) / dx();
614 template<
class Po
intType>
615 std::ostream &operator<<(std::ostream &os, const GenericLine<PointType> &line) {
616 if (line.isVertical()) {
617 os <<
"Line: vertical with x = " << line.m_p1.m_x ;
619 os <<
"Line: f(x) = " << line.slope() <<
"x + " << line.yAbs() ;
628 template<
class Po
intType>
640 double minx = min(this->m_p1.m_x, this->m_p2.m_x);
641 double miny = min(this->m_p1.m_y, this->m_p2.m_y);
642 double maxx = max(this->m_p1.m_x, this->m_p2.m_x);
643 double maxy = max(this->m_p1.m_y, this->m_p2.m_y);
645 if (includeBorders) {
646 return OGDF_GEOM_ET.geq(p.m_x, minx) &&
647 OGDF_GEOM_ET.leq(p.m_x, maxx) &&
648 OGDF_GEOM_ET.geq(p.m_y, miny) &&
649 OGDF_GEOM_ET.leq(p.m_y, maxy);
651 return OGDF_GEOM_ET.greater(p.m_x, minx) &&
652 OGDF_GEOM_ET.less (p.m_x, maxx) &&
653 OGDF_GEOM_ET.greater(p.m_y, miny) &&
654 OGDF_GEOM_ET.less (p.m_y, maxy);
683 return this->m_p1 == dl.
m_p1 && this->m_p2 == dl.
m_p2;
688 return !(*
this == dl);
692 const PointType &
start()
const {
return this->m_p1; }
695 const PointType &
end()
const {
return this->m_p2; }
723 return inBoundingRect(inter, endpoints)
734 if (!inBoundingRect(inter, endpoints) ||
737 }
else if (points[1] == points[2] &&
738 !(this->m_p1 == inter && this->m_p2 == inter) &&
739 !(segment.
m_p1 == inter && segment.
m_p2 == inter)) {
756 return this->m_p1.distance(this->m_p2);
772 }
else if (inBoundingRect(
DPoint(crossing, horAxis))) {
793 }
else if (inBoundingRect(
DPoint(verAxis, crossing))) {
803 template<
class Po
intType>
804 std::ostream &operator<<(std::ostream &os, const GenericSegment<PointType> &dl) {
805 os <<
"Segment-Start: " << dl.start() <<
", Segment-End: " << dl.end();
839 DRect(
double x1,
double y1,
double x2,
double y2)
844 :
DRect(dl.start(), dl.end()) {}
846 virtual ~
DRect() =
default;
850 return m_p1 == dr.
m_p1 && m_p2 == dr.
m_p2;
855 return !(*
this == dr);
869 return m_p2.
m_x - m_p1.
m_x;
874 return m_p2.
m_y - m_p1.
m_y;
884 if (width() < 0) std::swap(m_p2.
m_x, m_p1.
m_x);
885 if (height() < 0) std::swap(m_p2.
m_y, m_p1.
m_y);
922 return OGDF_GEOM_ET.geq(p.
m_x, m_p1.
m_x)
923 && OGDF_GEOM_ET.leq(p.
m_x, m_p2.
m_x)
924 && OGDF_GEOM_ET.geq(p.
m_y, m_p1.
m_y)
925 && OGDF_GEOM_ET.leq(p.
m_y, m_p2.
m_y);
964 void initAreaAndCenter();
973 { initAreaAndCenter(); }
983 , m_center(dr.m_center) {}
988 DPoint(center.m_x+width/2,center.m_y+height/2)) {};
1005 double area()
const {
return m_area; }
1067 return insertPoint(p, begin(), begin());
1080 void insertCrossPoint(
const DPoint &p);
1097 bool containsPoint(
DPoint &p)
const;
DIntersectableRect(double x1, double y1, double x2, double y2)
Creates a rectangle with lower left point (x1,y1) and upper right point (x1,y2).
DRect(const DSegment &dl)
Creates a rectangle defined by the end points of line segment dl.
double slope() const
Returns the slope of the line.
bool isVertical() const
Returns true iff this line runs vertically.
bool operator!=(const GenericPoint< T > &p) const
Inequality operator.
DPolygon(const DPolygon &dop)
Copy constructor.
const DSegment top() const
Returns the top side of the rectangle.
GenericPolyline(const List< PointType > &pl)
Creates a polyline using the list of points pl.
const DSegment bottom() const
Returns the bottom side of the rectangle.
void normalize()
Normalizes the rectangle.
DPoint position(const double fraction, double len=-1.0) const
Returns a point on the polyline which is fraction * len away from the start point.
double distance(const GenericPoint< T > &p) const
Returns the Euclidean distance between p and this point.
GenericSegment()
Creates an empty line segment.
void unify()
Deletes all successive points with equal coordinates.
GenericPolyline(const GenericPolyline< PointType > &pl)
Copy constructor.
The parameterized class Array implements dynamic arrays of type E.
int hash(const IPoint &ip) const
T operator*(const GenericPoint< T > &dv) const
Returns the scalar product of this and dv.
IntersectionType
Determines the type of intersection of two geometric objects.
GenericLine(numberType x1, numberType y1, numberType x2, numberType y2)
Creates a line through the points (x1,y1) and (x2,y2).
bool m_counterclock
If true points are given in conter-clockwise order.
DIntersectableRect(const DPoint ¢er, double width, double height)
Constructs a rectangle from the center point, width and height.
bool inBoundingRect(const PointType &p, bool includeBorders=true) const
Returns whether p lies in the rectangle which has m_p1 and m_p2 as opposing corners.
double height() const
Returns the height of the rectangle.
IntersectionType verIntersection(const double verAxis, double &crossing) const override
Computes the intersection between this line segment and the vertical line through x = verAxis...
Polygons with real coordinates.
double pointDist(const DPoint &p1, const DPoint &p2) const
Computes distance between two points.
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF DLL.
GenericPoint< double > DPoint
Representing two-dimensional point with real coordinates.
DIntersectableRect(const DPoint &p1, const DPoint &p2)
Creates a rectangle with lower left point p1 and upper right point p2.
IntersectionType horIntersection(const double horAxis, double &crossing) const override
Computes the intersection of this line segment and the horizontal line through y = horAxis...
double width() const
Returns the width of the rectangle.
double yAbs() const
Returns the value y' such that (0,y') lies on the unlimited straight-line defined by this line...
GenericPoint< T > operator+(const GenericPoint< T > &p) const
Addition of points.
PointType m_p1
The first point of the line.
const DSegment right() const
Returns the right side of the rectangle.
bool counterclock()
Returns true iff points are given in counter-clockwise order.
const PointType & start() const
Returns the start point of the line segment.
Rectangles with real coordinates.
DIntersectableRect(const DIntersectableRect &dr)
Copy constructor.
IntersectionType intersection(const GenericLine< PointType > &line, DPoint &inter) const
Returns an IntersectionType specifying whether line and this line intersect.
Declaration of classes used for hashing.
DPoint center() const
Center of the rectangle.
Two geometric objects intersect in a single point.
Rectangles with real coordinates.
GenericLine< PointType >::numberType dy() const
Returns the y-coordinate of the difference (end point - start point).
GenericPoint(const GenericPoint< T > &p)
Copy constructor.
PointType m_p2
The second point of the line.
virtual IntersectionType horIntersection(const double horAxis, double &crossing) const
Computes the intersection of this line and the horizontal line through y = horAxis.
bool operator!=(const GenericLine< PointType > &dl) const
Inequality operator.
GenericLine()
Creates an empty line.
GenericLine(const PointType &p1, const PointType &p2)
Creates a line through the points p1 and p2.
double radiansToDegrees(const double &angleInRadians)
Converts an angle from radians to degrees.
const DSegment left() const
Returns the left side of the rectangle.
Compare floating point numbers with epsilons and integral numbers with normal compare operators...
int numberType
The type for coordinates of the point.
bool operator==(const GenericPoint< T > &dp) const
Equality operator.
void yInvert()
Swaps the y-coordinates of the two points.
friend GenericPoint< T > operator*(const GenericPoint< T > &p, T c)
Point-wise multiplies p with c.
bool valid() const
Returns true iff the iterator points to an element.
GenericLine(const GenericLine< PointType > &dl)
Copy constructor.
double length() const
Returns the length (Euclidean distance between start and end point) of this line segment.
constexpr double pi
The constant .
Orientation
Determines the orientation in hierarchical layouts.
bool operator==(const DRect &dr) const
Equality operator: both rectangles have the same coordinates.
void sort(T *array, int size, LessThan lt)
GenericPolyline()
Creates an empty polyline.
const EpsilonTest OGDF_GEOM_ET
const DPoint & p1() const
Returns the lower left point of the rectangle.
bool operator>(const GenericPoint< T > &p) const
Operator 'greater'. Returns true iff p is less than this.
numberType dx() const
Returns the x-coordinate of the difference (second point - first point).
GenericPoint(T x=0, T y=0)
Creates a generic point (x,y).
const PointType & end() const
Returns the end point of the line segment.
GenericPoint< T > & operator/=(T c)
Point-wise divide this by c.
double length() const
Returns the Euclidean length of the polyline.
T determinant(const GenericPoint< T > &dv) const
Returns the determinant of the matrix (this, dv).
virtual bool contains(const DPoint &p) const
Returns true iff p lies on this line.
void normalize(double minAngle=Math::pi)
Deletes all redundant points on the polyline that lie on a (nearly) straight line given by their adja...
Doubly linked lists (maintaining the length of the list).
GenericPoint< T > & operator+=(const GenericPoint< T > &p)
Adds p to this.
DRect(const DPoint &p1, const DPoint &p2)
Creates a rectangle with lower left point p1 and upper right point p2.
GenericLine< PointType > & operator=(const GenericLine< PointType > &dl)
Assignment operator.
Edges are oriented from left to right.
bool contains(const DPoint &p) const
Returns true iff p lies within this rectangle, modulo the comparison epsilon OGDF_GEOM_ET.
DPolygon(const DRect &rect, bool cc=true)
Creates a polgon from a rectangle.
bool intersection(const DSegment &segment) const
Returns true iff segment intersects this DRect.
double angleDegrees(GenericPoint< T > q, GenericPoint< T > r) const
Compute angle (in degrees) between vectors.
GenericPoint< T > orthogonal() const
Returns a vector that is orthogonal to this vector.
friend GenericPoint< T > operator/(const GenericPoint< T > &p, double c)
Point-wise divide p by c.
Encapsulates a pointer to a list element.
Polylines with PointType points.
double area() const
Area of the rectangle.
GenericSegment< DPoint > DSegment
Segments with real coordinates.
const T & move(const T &v)
GenericPoint< T > & operator-=(const GenericPoint< T > &p)
Subtracts p from this.
void xInvert()
Swaps the x-coordinates of the two points.
DPolygon & operator=(const DPolygon &dop)
Assignment operator.
Edges are oriented from right to left.
bool contains(const PointType &p) const override
Returns true iff p lies on this line segment.
GenericSegment(const PointType &p1, const PointType &p2)
Creates a line segment from p1 to p2.
Two geometric objects intersect in infinitely many points.
virtual IntersectionType verIntersection(const double verAxis, double &crossing) const
Computes the intersection between this line and the vertical line through x = verAxis.
GenericPoint< T > & operator=(const GenericPoint< T > &p)
Assignment operator.
GenericPoint< T > & operator*=(T c)
Point-wise multiplies this with c.
bool isHorizontal() const
Returns true iff this line runs horizontally.
bool operator==(const GenericSegment< PointType > &dl) const
Equality operator.
Two geometric objects do not intersect.
Parameterized base class for points.
typename PointType::numberType numberType
Edges are oriented from top to bottom.
GenericLine< PointType >::numberType dx() const
Returns the x-coordinate of the difference (end point - start point).
DRect(double x1, double y1, double x2, double y2)
Creates a rectangle with lower left point (x1,y1) and upper right point (x2,y2).
bool operator!=(const DRect &dr) const
Inequality operator.
double det(const GenericLine< PointType > &line) const
Determines if line is left or right of this line.
DRect(const DRect &dr)
Copy constructor.
friend GenericPoint< T > operator*(T c, const GenericPoint< T > &p)
Point-wise multiplies p with c.
void normalize(PointType src, PointType tgt, double minAngle=Math::pi)
Deletes all redundant points on the polyline that lie on a (nearly) straight line given by their adja...
The namespace for all OGDF objects.
GenericSegment(double x1, double y1, double x2, double y2)
Creates a line segment from (x1,y1) to (x2,y2).
GenericPoint< T > operator-(const GenericPoint< T > &p) const
Subtraction of points.
List< E > & operator=(const List< E > &L)
Assignment operator.
const DPoint & p2() const
Returns the upper right point of the rectangle.
GenericPolyline< PointType > & operator=(const GenericPolyline &pl)
Assignment operator.
numberType dy() const
Returns the y-coordinate of the difference (second point - first point).
DPolygon(bool cc=true)
Creates an empty polygon.
bool operator==(const GenericLine< PointType > &dl) const
Equality operator.
double norm() const
Returns the norm of the point.
bool operator!=(const GenericSegment< PointType > &dl) const
Inequality operator.
GenericSegment(const GenericLine< PointType > &dl)
Creates a line segment defined by the start and end point of line dl.
IntersectionType intersection(const GenericSegment< PointType > &segment, PointType &inter, bool endpoints=true) const
Returns an IntersectionType specifying whether segment and this line segment intersect.
DPoint m_p2
The upper right point of the rectangle.
void normalizeUnified(double minAngle)
Deletes all redundant points on the polyline that lie on a (nearly) straight line given by their adja...
ListIterator< DPoint > insertPoint(const DPoint &p)
Inserts point p, that must lie on a polygon segment.
std::ostream & operator<<(std::ostream &os, const ogdf::Array< E, INDEX > &a)
Prints array a to output stream os.
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
double angle(GenericPoint< T > q, GenericPoint< T > r) const
Compute angle (in radians) between vectors.
Declaration of doubly linked lists and iterators.
Edges are oriented from bottom to top.
DPoint m_p1
The lower left point of the rectangle.
int orientation(const DPoint &p, const DPoint &q, const DPoint &r)