48Point::Point(
const double xv,
const double yv) :
57bool Point::operator==(
const Point& rhs)
const
67bool Point::operator!=(
const Point& rhs)
const
77bool Point::equals(
const Point& rhs,
double epsilon)
const
88bool Point::operator<(
const Point& rhs)
const
98double& Point::operator[](
const size_t dimension)
101 return ((dimension == 0) ?
x :
y);
105const double& Point::operator[](
const size_t dimension)
const
108 return ((dimension == 0) ?
x :
y);
127 psPoints(poly.
size())
129 COLA_ASSERT(router !=
nullptr);
130 for (
size_t i = 0; i < poly.
size(); ++i)
132 if (poly.
ps[i].id == 0)
141 const Polygon *polyPtr =
nullptr;
142 for (ObstacleList::const_iterator sh = router->
m_obstacles.begin();
145 if ((*sh)->id() == poly.
ps[i].id)
147 const Polygon& poly = (*sh)->polygon();
152 COLA_ASSERT(polyPtr !=
nullptr);
153 psRef[i] = std::make_pair(polyPtr, poly.
ps[i].vn);
175 return psRef.empty();
198 unsigned short poly_index =
psRef[
index].second;
199 COLA_ASSERT(poly_index < poly.
size());
201 return poly.
ps[poly_index];
213 bBox.
min.
x = DBL_MAX;
214 bBox.
min.
y = DBL_MAX;
215 bBox.
max.
x = -DBL_MAX;
216 bBox.
max.
y = -DBL_MAX;
218 for (
size_t i = 0; i <
size(); ++i)
275 for (
size_t i = 0; i < poly.
size(); ++i)
295 double dx = pt2.
x - pt1.
x;
296 double dy = pt2.
y - pt1.
y;
297 double f = 1.0 / std::sqrt((dx * dx) + (dy * dy));
300 return Point(dy, -dx);
309 for (
size_t i = 0; i <
size(); ++i)
311 newPoly.
ps.push_back(
at(i));
316 size_t numOfEdges =
size();
317 std::vector<Vector> normals(numOfEdges);
318 for (
size_t i = 0; i < numOfEdges; ++i)
323 size_t j = numOfEdges - 1;
324 for (
size_t i = 0; i < numOfEdges; ++i)
326 double R = 1 + ((normals[i].x * normals[j].x) +
327 (normals[i].y * normals[j].y));
328 if (((normals[j].x * normals[i].y) - (normals[i].x * normals[j].y)) *
332 Point pt =
Point(
at(i).x + (normals[j].x + normals[i].x) * q,
333 at(i).y + (normals[j].y + normals[i].y) * q);
337 newPoly.
ps.push_back(pt);
349 newPoly.
ps.push_back(pt1);
353 newPoly.
ps.push_back(pt2);
357 newPoly.
ps.push_back(pt3);
415static void shorten_line(
double& x1,
double& y1,
double& x2,
double& y2,
416 const unsigned int mode,
const double shorten_length)
423 double rise = y1 - y2;
424 double run = x1 - x2;
425 double disty = fabs(rise);
426 double distx = fabs(run);
431 (((distx > disty) && ((shorten_length * 2) > distx)) ||
432 ((disty >= distx) && ((shorten_length * 2) > disty))))
434 x1 = x2 = x1 - (run / 2);
435 y1 = y2 = y1 - (rise / 2);
439 (((distx > disty) && (shorten_length > distx)) ||
440 ((disty >= distx) && (shorten_length > disty))))
447 (((distx > disty) && (shorten_length > distx)) ||
448 ((disty >= distx) && (shorten_length > disty))))
459 int sign = (y1 < y2) ? 1: -1;
463 y1 += (
sign * shorten_length);
467 y2 -= (
sign * shorten_length);
474 int sign = (x1 < x2) ? 1: -1;
478 x1 += (
sign * shorten_length);
482 x2 -= (
sign * shorten_length);
487 int xpos = (x1 < x2) ? -1 : 1;
488 int ypos = (y1 < y2) ? -1 : 1;
490 double tangent = rise / run;
496 y2 += shorten_length * ypos;
497 x2 += shorten_length * ypos * (1 / tangent);
499 else if (disty < distx)
501 y2 += shorten_length * xpos * tangent;
502 x2 += shorten_length * xpos;
510 y1 -= shorten_length * ypos;
511 x1 -= shorten_length * ypos * (1 / tangent);
513 else if (disty < distx)
515 y1 -= shorten_length * xpos * tangent;
516 x1 -= shorten_length * xpos;
524 for (
size_t i = 0; i <
size(); ++i)
537 std::vector<std::pair<size_t, Point> >& checkpoints =
539 bool hasCheckpointInfo = !(checkpoints.empty());
541 std::vector<Point>::iterator it = simplified.
ps.begin();
542 if (it != simplified.
ps.end()) ++it;
545 for (
size_t j = 2; j < simplified.
size(); )
547 if (
vecDir(simplified.
ps[j - 2], simplified.
ps[j - 1],
548 simplified.
ps[j]) == 0)
552 it = simplified.
ps.erase(it);
554 if (hasCheckpointInfo)
570 size_t deletedPointValue = (j - 1) - 1;
571 for (
size_t i = 0; i < checkpoints.size(); ++i)
573 if (checkpoints[i].first == deletedPointValue)
575 checkpoints[i].first -= 1;
577 else if (checkpoints[i].first > deletedPointValue)
579 checkpoints[i].first -= 2;
595 int indexModifier)
const
597 std::vector<Point> checkpoints;
602 size_t checkpointLowerValue = 2 * segmentLowerIndex;
603 size_t checkpointUpperValue = checkpointLowerValue + 2;
606 if (indexModifier > 0)
608 checkpointLowerValue++;
610 else if (indexModifier < 0)
612 checkpointUpperValue--;
628#define mid(a, b) ((a < b) ? a + ((b - a) / 2) : b + ((a - b) / 2))
641 const bool closed)
const
646 size_t num_of_points =
size();
647 if (num_of_points <= 2)
651 curved.
ts.push_back(
'M');
652 curved.
ts.push_back(
'L');
662 double x1 = simplified.
ps[0].x;
663 double y1 = simplified.
ps[0].y;
664 double x2 = simplified.
ps[1].x;
665 double y2 = simplified.
ps[1].y;
667 curved.
ps.push_back(
Point(x1, y1));
668 curved.
ts.push_back(
'M');
672 curved.
ps.push_back(
ps[0]);
673 curved.
ts.push_back(
'M');
676 size_t simpSize = simplified.
size();
677 size_t finish = (closed) ? simpSize + 2 : simpSize;
678 for (
size_t j = 1; j < finish; ++j)
680 double x1 = simplified.
ps[(simpSize + j - 1) % simpSize].x;
681 double y1 = simplified.
ps[(simpSize + j - 1) % simpSize].y;
682 double x2 = simplified.
ps[j % simpSize].x;
683 double y2 = simplified.
ps[j % simpSize].y;
695 else if (j == (
size() - 1))
704 curved.
ts.insert(curved.
ts.end(), 3,
'C');
705 curved.
ps.push_back(
Point(mid(last_x, old_x), mid(last_y, old_y)));
706 curved.
ps.push_back(
Point(mid(x1, old_x), mid(y1, old_y)));
707 curved.
ps.push_back(
Point(x1, y1));
709 if (closed && (j == (finish - 1)))
712 curved.
ts.push_back(
'Z');
713 curved.
ps.push_back(
Point(x1, y1));
716 curved.
ts.push_back(
'L');
717 curved.
ps.push_back(
Point(x2, y2));
730 double xMin = std::min(topLeft.
x, bottomRight.
x);
731 double xMax = std::max(topLeft.
x, bottomRight.
x);
732 double yMin = std::min(topLeft.
y, bottomRight.
y);
733 double yMax = std::max(topLeft.
y, bottomRight.
y);
746 double halfWidth =
width / 2.0;
747 double halfHeight =
height / 2.0;
748 double xMin = centre.
x - halfWidth;
749 double xMax = centre.
x + halfWidth;
750 double yMin = centre.
y - halfHeight;
751 double yMax = centre.
y + halfHeight;
A bounding box, represented by the top-left and bottom-right corners.
Point min
The top-left point.
Point max
The bottom-right point.
double height(void) const
double length(size_t dimension) const
The Point class defines a point in the plane.
unsigned short vn
The vertex number associated with this point.
Point()
Default constructor.
unsigned int id
The ID associated with this point.
A common interface used by the Polygon classes.
virtual const Point & at(size_t index) const =0
Returns a specific point in the polygon.
Polygon boundingRectPolygon(void) const
Returns the bounding rectangle for this polygon.
virtual size_t size(void) const =0
Returns the number of points in this polygon.
Polygon offsetPolygon(double offset) const
virtual int id(void) const =0
Returns the ID value associated with this polygon.
Box offsetBoundingBox(double offset) const
Returns the bounding rectangle that contains this polygon with optionally some buffer space around it...
A dynamic Polygon, to which points can be easily added and removed.
void setPoint(size_t index, const Point &point)
Sets a position for a particular point in the polygon.
Polygon simplify(void) const
Returns a simplified Polyline, where all collinear line segments have been collapsed down into single...
size_t size(void) const
Returns the number of points in this polygon.
int id(void) const
Returns the ID value associated with this polygon.
Polygon curvedPolyline(const double curve_amount, const bool closed=false) const
Returns a curved approximation of this multi-segment PolyLine, with the corners replaced by smooth Be...
std::vector< char > ts
If used, denotes whether the corresponding point in ps is a move-to operation or a Bezier curve-to.
bool empty(void) const
Returns true if this polygon is empty.
void translate(const double xDist, const double yDist)
Translates the polygon position by a relative amount.
int _id
An ID for the polygon.
std::vector< Point > ps
A vector of the points that make up the Polygon.
void clear(void)
Resets this to the empty polygon.
const Point & at(size_t index) const
Returns a specific point in the polygon.
std::vector< std::pair< size_t, Point > > checkpointsOnRoute
Polygon()
Constructs an empty polygon (with zero points).
std::vector< Point > checkpointsOnSegment(size_t segmentLowerIndex, int indexModifier=0) const
A Rectangle, a simpler way to define the polygon for square or rectangular shapes.
Rectangle(const Point &topLeft, const Point &bottomRight)
Constructs a rectangular polygon given two opposing corner points.
const Point & at(size_t index) const
Returns a specific point in the polygon.
size_t size(void) const
Returns the number of points in this polygon.
std::vector< std::pair< const Polygon *, unsigned short > > psRef
std::vector< Point > psPoints
int id(void) const
Returns the ID value associated with this polygon.
void clear(void)
Resets this to the empty polygon.
bool empty(void) const
Returns true if this polygon is empty.
The Router class represents a libavoid router instance.
Contains the interface for various geometry types and classes.
libavoid: Object-avoiding orthogonal and polyline connector routing library.
static const unsigned int SHORTEN_END
static const unsigned short kUnassignedVertexNumber
Constant value representing an unassigned vertex number.
static void shorten_line(double &x1, double &y1, double &x2, double &y2, const unsigned int mode, const double shorten_length)
static int vecDir(const Point &a, const Point &b, const Point &c, const double maybeZero=0.0)
static const unsigned int SHORTEN_START
static const unsigned int SHORTEN_NONE
static const unsigned int SHORTEN_BOTH
static Point unitNormalForEdge(const Point &pt1, const Point &pt2)
Contains the interface for the Router class.
static double sign(double const x)
Returns -1 or 1 according to the sign of x.
Contains the interface for the ShapeRef class.