Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
geomtypes.h
Go to the documentation of this file.
1/*
2 * vim: ts=4 sw=4 et tw=0 wm=0
3 *
4 * libavoid - Fast, Incremental, Object-avoiding Line Router
5 *
6 * Copyright (C) 2004-2014 Monash University
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 * See the file LICENSE.LGPL distributed with the library.
13 *
14 * Licensees holding a valid commercial license may use this file in
15 * accordance with the commercial license agreement provided with the
16 * library.
17 *
18 * This library is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
21 *
22 * Author(s): Michael Wybrow
23*/
24
27
28
29#ifndef AVOID_GEOMTYPES_H
30#define AVOID_GEOMTYPES_H
31
32#include <cstdlib>
33#include <vector>
34#include <utility>
35
36#include "libavoid/dllexport.h"
37
38
39namespace Avoid
40{
41
42static const size_t XDIM = 0;
43static const size_t YDIM = 1;
44
45class Polygon;
46
52class AVOID_EXPORT Point
53{
54 public:
57 Point();
63 Point(const double xv, const double yv);
64
70 bool operator==(const Point& rhs) const;
79 bool equals(const Point& rhs, double epsilon = 0.0001) const;
85 bool operator!=(const Point& rhs) const;
94 bool operator<(const Point& rhs) const;
95
100 double& operator[](const size_t dimension);
101 const double& operator[](const size_t dimension) const;
102
103 Point operator+(const Point& rhs) const;
104 Point operator-(const Point& rhs) const;
105
107 double x;
109 double y;
111 unsigned int id;
113 unsigned short vn;
114
115};
116
117
120static const unsigned short kUnassignedVertexNumber = 8;
121
123static const unsigned short kShapeConnectionPin = 9;
124
125
128typedef Point Vector;
129
133class AVOID_EXPORT Box
134{
135 public:
140
141 double length(size_t dimension) const;
142 double width(void) const;
143 double height(void) const;
144};
145
146
147
150class AVOID_EXPORT PolygonInterface
151{
152 public:
156 virtual ~PolygonInterface() { }
158 virtual void clear(void) = 0;
160 virtual bool empty(void) const = 0;
162 virtual size_t size(void) const = 0;
164 virtual int id(void) const = 0;
167 virtual const Point& at(size_t index) const = 0;
171 Polygon boundingRectPolygon(void) const;
180 Box offsetBoundingBox(double offset) const;
181
182 Polygon offsetPolygon(double offset) const;
183};
184
185
188class AVOID_EXPORT Edge
189{
190 public:
195};
196
197
198class Router;
200
201
207class AVOID_EXPORT Polygon : public PolygonInterface
208{
209 public:
211 Polygon();
226 Polygon(const int n);
231 Polygon(const PolygonInterface& poly);
233 void clear(void);
235 bool empty(void) const;
237 size_t size(void) const;
239 int id(void) const;
242 const Point& at(size_t index) const;
246 void setPoint(size_t index, const Point& point);
253 Polygon simplify(void) const;
274 Polygon curvedPolyline(const double curve_amount,
275 const bool closed = false) const;
280 void translate(const double xDist, const double yDist);
281
283 int _id;
285 std::vector<Point> ps;
301 std::vector<char> ts;
302
303 // @brief If used, denotes checkpoints through which the route travels
304 // and the relevant segment of the route.
305 //
306 // Set and used by the orthogonal routing code. Note the first value
307 // in the pair doesn't correspond to the segment index containing the
308 // checkpoint, but rather the segment or bendpoint on which it lies.
309 // 0 if on ps[0]
310 // 1 if on line ps[0]-ps[1]
311 // 2 if on ps[1]
312 // 3 if on line ps[1]-ps[2]
313 // etc.
314 std::vector<std::pair<size_t, Point> > checkpointsOnRoute;
315
316 // Returns true if at least one checkpoint lies on the line segment
317 // or at either end of it. An indexModifier of +1 will cause it to
318 // ignore a checkpoint on the corner at the start of the segment and
319 // -1 will cause it to do the same for the corner at the end of the
320 // segment.
321 std::vector<Point> checkpointsOnSegment(size_t segmentLowerIndex,
322 int indexModifier = 0) const;
323};
324
325
329
330
336class AVOID_EXPORT ReferencingPolygon : public PolygonInterface
337{
338 public:
340 ReferencingPolygon(const Polygon& poly, const Router *router);
341 void clear(void);
342 bool empty(void) const;
343 size_t size(void) const;
344 int id(void) const;
345 const Point& at(size_t index) const;
346
347 int _id;
348 std::vector<std::pair<const Polygon *, unsigned short> > psRef;
349 std::vector<Point> psPoints;
350};
351
352
356class AVOID_EXPORT Rectangle : public Polygon
357{
358 public:
365 Rectangle(const Point& topLeft, const Point& bottomRight);
366
375 Rectangle(const Point& centre, const double width, const double height);
376};
377
378
379}
380
381#endif
pair< double, double > Point
Definition parser.cpp:7
static bool operator<(const Baseline &a, const Baseline &b)
A bounding box, represented by the top-left and bottom-right corners.
Definition geomtypes.h:134
Point min
The top-left point.
Definition geomtypes.h:137
Point max
The bottom-right point.
Definition geomtypes.h:139
A line between two points.
Definition geomtypes.h:189
Point a
The first point.
Definition geomtypes.h:192
Point b
The second point.
Definition geomtypes.h:194
The Point class defines a point in the plane.
Definition geomtypes.h:53
unsigned short vn
The vertex number associated with this point.
Definition geomtypes.h:113
double y
The y position.
Definition geomtypes.h:109
double x
The x position.
Definition geomtypes.h:107
unsigned int id
The ID associated with this point.
Definition geomtypes.h:111
A common interface used by the Polygon classes.
Definition geomtypes.h:151
virtual void clear(void)=0
Resets this to the empty polygon.
virtual const Point & at(size_t index) const =0
Returns a specific point in the polygon.
virtual ~PolygonInterface()
Destructor.
Definition geomtypes.h:156
virtual size_t size(void) const =0
Returns the number of points in this polygon.
PolygonInterface()
Constructor.
Definition geomtypes.h:154
virtual int id(void) const =0
Returns the ID value associated with this polygon.
virtual bool empty(void) const =0
Returns true if this polygon is empty.
A dynamic Polygon, to which points can be easily added and removed.
Definition geomtypes.h:208
std::vector< char > ts
If used, denotes whether the corresponding point in ps is a move-to operation or a Bezier curve-to.
Definition geomtypes.h:301
int _id
An ID for the polygon.
Definition geomtypes.h:283
std::vector< Point > ps
A vector of the points that make up the Polygon.
Definition geomtypes.h:285
std::vector< std::pair< size_t, Point > > checkpointsOnRoute
Definition geomtypes.h:314
A Rectangle, a simpler way to define the polygon for square or rectangular shapes.
Definition geomtypes.h:357
A Polygon which just references its points from other Polygons.
Definition geomtypes.h:337
std::vector< std::pair< const Polygon *, unsigned short > > psRef
Definition geomtypes.h:348
std::vector< Point > psPoints
Definition geomtypes.h:349
The Router class represents a libavoid router instance.
Definition router.h:386
Geom::IntPoint size
double offset
sufficient_stats operator-(sufficient_stats const &a, sufficient_stats const &b)
Definition metro.cpp:119
sufficient_stats operator+(sufficient_stats const &a, sufficient_stats const &b)
Definition metro.cpp:107
libavoid: Object-avoiding orthogonal and polyline connector routing library.
static const unsigned short kUnassignedVertexNumber
Constant value representing an unassigned vertex number.
Definition geomtypes.h:120
static const size_t XDIM
Definition geomtypes.h:42
Point Vector
A vector, represented by the Point class.
Definition geomtypes.h:128
static const unsigned short kShapeConnectionPin
Constant value representing a ShapeConnectionPin.
Definition geomtypes.h:123
static const size_t YDIM
Definition geomtypes.h:43
Polygon PolyLine
A multi-segment line, represented with the Polygon class.
Definition geomtypes.h:328
int index
double height
double width