54 double DRound(
const double &d,
int prec = 0)
57 return floor(d + 0.5);
58 double factor = pow(10.0, ((
double) prec));
59 return DRound(d * factor, 0) / factor;
70 template <
class NUMBER>
102 return m_x == p.
m_x && m_y == p.
m_y;
107 return m_x != p.
m_x || m_y != p.
m_y;
111 return (m_x < p.
m_x || (m_x == p.
m_x && m_y < p.
m_y));
121 const double dx1 = q.
m_x - m_x, dy1 = q.
m_y - m_y;
122 const double dx2 = r.
m_x - m_x, dy2 = r.
m_y - m_y;
125 if ((dx1 == 0 && dy1 == 0)
126 || (dx2 == 0 && dy2 == 0)) {
130 const double norm = (dx1*dx1+dy1*dy1)*(dx2*dx2+dy2*dy2);
131 const double cosphi = (dx1*dx2+dy1*dy2) / sqrt(norm);
132 if (cosphi >= 1.0)
return 0;
133 if (cosphi <= -1.0)
return Math::pi;
135 double phi = acos(cosphi);
137 if (dx1*dy2 < dy1*dx2) phi = -phi;
146 return angle(q, r)*360.0/(2*
Math::pi);
169 double distance(
const IPoint &p)
const;
181 return 7*ip.
m_x + 23*ip.
m_y;
209 double length()
const;
233 return OGDF_GEOM_ET.equal(m_x, dp.
m_x) && OGDF_GEOM_ET.equal(m_y,dp.
m_y);
238 return sqrt(m_x*m_x + m_y*m_y);
276 double distance(
const DPoint &p)
const;
318 DVector operator*(
const double val)
const;
321 DVector operator/(
const double val)
const;
324 double length()
const;
330 double operator*(
const DVector &dv)
const;
366 double length()
const;
375 DPoint position(
const double fraction,
double len = -1.0)
const;
384 void normalize(
DPoint src,
391 void reConvertToDouble();
414 DLine(
const DLine &dl) : m_start(dl.m_start), m_end(dl.m_end) {}
417 DLine(
double x1,
double y1,
double x2,
double y2) {
418 m_start.
m_x = x1; m_start.
m_y = y1; m_end.
m_x = x2; m_end.
m_y = y2;
428 return !(*
this == dl);
447 double dx()
const {
return m_end.
m_x - m_start.
m_x; }
450 double dy()
const {
return m_end.
m_y - m_start.
m_y; }
453 double slope()
const {
return (dx() == 0) ? numeric_limits<double>::max() : dy()/dx(); }
456 double yAbs()
const {
return (dx() == 0) ? numeric_limits<double>::max() : m_start.
m_y - (slope() * m_start.
m_x); }
459 bool isVertical()
const {
return OGDF_GEOM_ET.equal(dx(), 0.0); }
471 bool intersection(
const DLine &
line,
DPoint &inter,
bool endpoints =
true)
const;
473 bool intersectionOfLines(
const DLine &line,
DPoint &inter)
const;
476 bool contains(
const DPoint &p)
const;
492 int horIntersection(
const double horAxis,
double &crossing)
const;
505 int verIntersection(
const double verAxis,
double &crossing)
const;
539 DRect(
double x1,
double y1,
double x2,
double y2)
544 :
DRect(dl.start(), dl.end()) {}
546 virtual ~
DRect() =
default;
550 return m_p1 == dr.
m_p1 && m_p2 == dr.
m_p2;
555 return !(*
this == dr);
569 return m_p2.
m_x - m_p1.
m_x;
574 return m_p2.
m_y - m_p1.
m_y;
584 if (width() < 0) swap(m_p2.
m_x, m_p1.
m_x);
585 if (height() < 0) swap(m_p2.
m_y, m_p1.
m_y);
622 return OGDF_GEOM_ET.geq(p.
m_x, m_p1.
m_x)
623 && OGDF_GEOM_ET.leq(p.
m_x, m_p2.
m_x)
624 && OGDF_GEOM_ET.geq(p.
m_y, m_p1.
m_y)
625 && OGDF_GEOM_ET.leq(p.
m_y, m_p2.
m_y);
642 double parallelDist(
const DLine &d1,
const DLine &d2)
const;
668 void initAreaAndCenter();
677 { initAreaAndCenter(); }
687 , m_center(dr.m_center) {}
692 DPoint(center.m_x+width/2,center.m_y+height/2)) {};
709 double area()
const {
return m_area; }
744 m_factorX(to.width()/from.width()),
745 m_factorY(to.height()/from.height()),
746 m_offsetX(to.p1().m_x - from.p1().m_x * m_factorX),
747 m_offsetY(to.p1().m_y - from.p1().m_y * m_factorY) { }
758 double scaleToX(
double x) {
return x * m_factorX + m_offsetX; }
761 double scaleToY(
double y) {
return y * m_factorY + m_offsetY; }
794 DSegment(
double x1,
double y1,
double x2,
double y2) :
DLine(x1, y1, x2, y2) {}
807 return (dx() * segment.
dy() - dy() * segment.
dx());
857 return insertPoint(p, begin(), begin());
870 void insertCrossPoint(
const DPoint &p);
887 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).
static const double pi
The constant .
DLine right() const
Right bounding line.
DPolygon(const DPolygon &dop)
Copy constructor.
void normalize()
Normalizes the rectangle.
DPoint & operator+=(const DPoint &p)
const DLine rightLine() const
Returns the right side of the rectangle.
double angle(GenericPoint q, GenericPoint r) const
Compute angle (in radians) between vectors.
NUMBER m_y
The y-coordinate.
int hash(const IPoint &ip) const
Lit operator^(Lit p, bool b)
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.
double height() const
Returns the height of the rectangle.
Polygons with real coordinates.
double pointDist(const DPoint &p1, const DPoint &p2) const
Computes distance between two points.
DPoint(double x, double y)
Creates a real point (x,y).
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF DLL.
double scaleToY(double y)
Transforms y-coordinates from source to target coordinate system.
IPoint(const IPoint &ip)
Copy constructor.
DIntersectableRect(const DPoint &p1, const DPoint &p2)
Creates a rectangle with lower left point p1 and upper right point p2.
IPolyline()
Creates an empty integer polyline.
double width() const
Returns the width of the rectangle.
double DRound(const double &d, int prec=0)
Polylines with integer coordinates.
double m_factorX
The scaling factor for the x-coordinates.
GenericPoint(const GenericPoint &p)
Copy constructor.
bool counterclock()
Returns true iff points are given in counter-clockwise order.
Rectangles with real coordinates.
DLine left() const
Left bounding line.
double m_factorY
The scaling factor for the y-coordinates.
Lines with real coordinates.
bool isHorizontal() const
Returns true iff this line runs horizontally.
DIntersectableRect(const DIntersectableRect &dr)
Copy constructor.
DSegment()
Creates an empty line segment.
Declaration of classes used for hashing.
DPoint center() const
Center of the rectangle.
Polylines with real coordinates.
NUMBER m_x
The x-coordinate.
Rectangles with real coordinates.
bool operator==(const DLine &dl) const
Equality operator.
double norm() const
Returns the norm of the point.
MDMFLengthAttribute operator-(MDMFLengthAttribute x, const MDMFLengthAttribute &y)
DLine top() const
Top bounding line.
Compare floating point numbers with epsilons and integral numbers with normal compare operators...
IPoint()
Creates an integer point (0,0).
void yInvert()
Swaps the y-coordinates of the two points.
DPolyline()
Creates an empty integer polyline.
const DRect * m_from
Rectangluar area in source coordinate system.
DSegment(const DPoint &p1, const DPoint &p2)
Creates a line segment from p1 to p2.
ostream & operator<<(ostream &os, const ogdf::Array< E, INDEX > &a)
Prints array a to output stream os.
IPoint(int x, int y)
Creates an integer point (x,p y).
DPoint(const DPoint &dp)
Copy constructor.
double scaleWidth(double width)
Scales a horizontal length from source to target coordinate system.
Orientation
Determines the orientation in hierarchical layouts.
const DRect * m_to
Rectangluar area in target coordinate system.
bool operator==(const DRect &dr) const
Equality operator: both rectangles have the same coordinates.
DVector(double x, double y)
Creates a vector (x,y).
DVector operator=(const DPoint &ip)
Assignment operator.
GenericPoint & operator=(const GenericPoint &p)
Assignment operator.
DLine(double x1, double y1, double x2, double y2)
Creates a line with start point (x1,y1) and end point (x2,y2).
const EpsilonTest OGDF_GEOM_ET
DPoint & operator*=(double c)
DVector(const DPoint &dv)
Copy constructor from DPoint.
DLine()
Creates an empty line.
const DPoint & p1() const
Returns the lower left point of the rectangle.
int numberType
The type for coordinates of the point.
DVector(const DVector &dv)
Copy constructor.
double scaleToX(double x)
Transforms x-coordinates from source to target coordinate system.
DRect(const DLine &dl)
Creates a rectangle defined by the end points of line dl.
IPolyline(const IPolyline &ipl)
Copy constructor.
Doubly linked lists (maintaining the length of the list).
bool operator==(const DPoint &dp) const
Relaxed equality operator.
DRect(const DPoint &p1, const DPoint &p2)
Creates a rectangle with lower left point p1 and upper right point p2.
double m_offsetX
The offset for the x-coordinates.
DLine(const DLine &dl)
Copy constructor.
double yAbs() const
Returns the value y' such that (0,y') lies on the unlimited straight-line define dby this line...
double scaleHeight(double height)
Scales a vertical length from source to target coordinate system.
Edges are oriented from left to right.
const DRect & from() const
Returns the rectangle in the source coordinate system.
Vectors with real coordinates.
bool operator>(const GenericPoint &p)
bool contains(const DPoint &p) const
Returns true iff p lies within this rectangle, modulo the comparison epsilon OGDF_GEOM_ET.
double angleDegrees(GenericPoint q, GenericPoint r) const
Compute angle (in degrees) between vectors.
double dy() const
Returns the y-coordinate of the difference (end point - start point).
bool operator<(const GenericPoint &p)
DPoint m_start
The start point of the line.
DPolygon(const DRect &rect, bool cc=true)
Creates a polgon from a rectangle.
Encapsulates a pointer to a list element.
bool operator!=(const DLine &dl) const
Inequality operator.
DLine(const DPoint &p1, const DPoint &p2)
Creates a line with start point p1 and end point p2.
double length() const
Returns the length (euclidean distance between start and edn point) of this line. ...
double area() const
Area of the rectangle.
const T & move(const T &v)
DVector()
Creates a vector (0,0).
IPolyline & operator=(const IPolyline &ipl)
Assignment operator.
void xInvert()
Swaps the x-coordinates of the two points.
DPolygon & operator=(const DPolygon &dop)
Assignment operator.
DSegment(const DSegment &ds)
Copy constructor.
Edges are oriented from right to left.
bool operator<(const MDMFLengthAttribute &x, const MDMFLengthAttribute &y)
GenericPoint(NUMBER x, NUMBER y)
Creates a generic point (x,y).
const DLine bottomLine() const
Returns the bottom side of the rectangle.
Scaling between coordinate systems.
const DPoint & start() const
Returns the start point of the line.
DScaler(const DRect &from, const DRect &to)
Creates a scaler for scaling from area from to area to.
DPoint & operator/=(double c)
Parameterized base class for points.
DLine bottom() const
Bottom bounding line.
double distance(const DPoint &p) const
Returns the euclidean distance between p and this point.
Edges are oriented from top to bottom.
const DLine topLine() const
Returns the top side of the rectangle.
double m_offsetY
The offset for the y-coordinates.
static const double s_prec
The conversion-precision.
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.
bool isVertical() const
Returns true iff this line runs vertically.
const DPoint & end() const
Returns the end point of the line.
DRect(const DRect &dr)
Copy constructor.
The namespace for all OGDF objects.
GenericPoint()
Creates a generic point.
const DRect & to() const
Returns the rectangle in the target coordinate system.
List< E > & operator=(const List< E > &L)
Assignment operator.
const DPoint & p2() const
Returns the upper right point of the rectangle.
double dx() const
Returns the x-coordinate of the difference (end point - start point).
DPolygon(bool cc=true)
Creates an empty polygon.
DSegment(const DLine &dl)
Creates a line segment defined by the start and end point of line dl.
bool operator==(const GenericPoint &p) const
Equality operator.
DSegment(double x1, double y1, double x2, double y2)
Creates a line segment from (x1,y1) to (x2,y2).
DPoint()
Creates a real point (0,0).
DPoint m_end
The end point of the line.
double slope() const
Returns the slope of the line.
friend DPoint operator*(double c, const DPoint &p)
DPoint m_p2
The upper right point of the rectangle.
double det(const DSegment &segment) const
Determines if segment is left or right of this segment.
DPolyline(const DPolyline &dpl)
Copy constructor.
ListIterator< DPoint > insertPoint(const DPoint &p)
Inserts point p, that must lie on a polygon segment.
Line segments with real coordinates.
DPoint & operator-=(const DPoint &p)
Declaration of doubly linked lists and iterators.
MDMFLengthAttribute operator+(MDMFLengthAttribute x, const MDMFLengthAttribute &y)
const DLine leftLine() const
Returns the left side of the rectangle.
Edges are oriented from bottom to top.
bool operator!=(const GenericPoint &p) const
Inequality operator.
DPoint m_p1
The lower left point of the rectangle.
DPolyline & operator=(const DPolyline &dpl)
Assignment operator.
int orientation(const DPoint &p, const DPoint &q, const DPoint &r)