47 #ifndef OGDF_GEOMETRY_H
48 #define OGDF_GEOMETRY_H
55 #define OGDF_GEOM_EPS 1e-06
73 return (a < (b + eps) && a > (b - eps));
79 return (a > (b - eps));
85 return (a > (b + eps));
91 return (a < (b + eps));
97 return (a < (b - eps));
101 double DRound(
const double &d,
int prec = 0)
104 return floor(d + 0.5);
105 double factor = pow(10.0, ((
double) prec));
106 return DRound(d * factor, 0) / factor;
117 template <
class NUMBER>
178 double distance(
const IPoint &p)
const;
190 return 7*ip.
m_x + 23*ip.
m_y;
218 double length()
const;
247 return sqrt(m_x*m_x + m_y*m_y);
257 double distance(
const DPoint &p)
const;
290 DVector operator*(
const double val)
const;
293 DVector operator/(
const double val)
const;
296 double length()
const;
299 double operator^(
const DVector &dv)
const;
302 double operator*(
const DVector &dv)
const;
346 double length()
const;
355 DPoint position(
const double fraction,
double len = -1.0)
const;
358 void writeGML(
const char* filename)
const;
361 void writeGML(ostream &stream)
const;
370 void normalize(
DPoint src,
398 DLine(
const DLine &dl) : m_start(dl.m_start), m_end(dl.m_end) {}
401 DLine(
double x1,
double y1,
double x2,
double y2) {
402 m_start.m_x = x1; m_start.m_y = y1; m_end.m_x = x2; m_end.m_y = y2;
412 return !(*
this == dl);
431 double dx()
const {
return m_end.m_x - m_start.m_x; }
434 double dy()
const {
return m_end.m_y - m_start.m_y; }
437 double slope()
const {
return (dx() == 0) ? DBL_MAX : dy()/dx(); }
440 double yAbs()
const {
return (dx() == 0) ? DBL_MAX : m_start.m_y - (slope() * m_start.m_x); }
455 bool intersection(
const DLine &line,
DPoint &inter,
bool endpoints =
true)
const;
458 bool contains(
const DPoint &p)
const;
462 return m_start.distance(m_end);
474 int horIntersection(
const double horAxis,
double &crossing)
const;
487 int verIntersection(
const double verAxis,
double &crossing)
const;
491 ostream &
operator<<(ostream &os,
const DLine &dl);
512 DRect(
double x1,
double y1,
double x2,
double y2) {
513 m_p1.m_x = x1; m_p1.m_y = y1; m_p2.m_x = x2; m_p2.m_y = y2;
527 return m_p1 == dr.
m_p1 && m_p2 == dr.
m_p2;
532 return !(*
this == dr);
546 return m_p2.m_x - m_p1.m_x;
551 return m_p2.m_y - m_p1.m_y;
561 if (width() < 0) swap(m_p2.m_x, m_p1.m_x);
562 if (height() < 0) swap(m_p2.m_y, m_p1.m_y);
632 m_factorX(to.width()/from.width()),
633 m_factorY(to.height()/from.height()),
634 m_offsetX(to.p1().m_x - from.p1().m_x * m_factorX),
635 m_offsetY(to.p1().m_y - from.p1().m_y * m_factorY) { }
646 double scaleToX(
double x) {
return x * m_factorX + m_offsetX; }
649 double scaleToY(
double y) {
return y * m_factorY + m_offsetY; }
652 double scaleWidth(
double width) {
return width * m_to->width() /m_from->width(); }
655 double scaleHeight(
double height) {
return height * m_to->height()/m_from->height(); }
682 DSegment(
double x1,
double y1,
double x2,
double y2) :
DLine(x1, y1, x2, y2) {}
695 return (dx() * segment.
dy() - dy() * segment.
dx());
745 return insertPoint(p, begin(), begin());
758 void insertCrossPoint(
const DPoint &p);
770 void writeGML(
const char* filename)
const;
773 void writeGML(ostream &stream)
const;
781 bool containsPoint(
DPoint &p)
const;