PCB Environment 2
Loading...
Searching...
No Matches
Path.hpp
1
2#ifndef GYM_PCB_PATH_H
3#define GYM_PCB_PATH_H
4
5#include "Py.hpp"
6#include "Geometry.hpp"
7#include <vector>
8
9class Pin;
10class Via;
11
12class Path
13{
14public:
15 const Point_25& getPoint(uint i) const { return mPoints.at(i); }
16 const std::vector<Point_25>& getPoints() const { return mPoints; }
17 void setPoint(uint i, const Point_25 &v) { mPoints.at(i) = v; }
18
19 const Point_25& front() const { return mPoints.front(); }
20 const Point_25& back() const { return mPoints.back(); }
21 const Point_25& back(uint n) const { assert(mPoints.size() >= n); return mPoints[mPoints.size() - n]; }
22 Point_25 pop_back();
23
24 bool isPlanarAt(uint i) const;
25 Segment_2 getSegmentAt(uint i) const;
26
27 uint numPoints() const { return mPoints.size(); }
28 bool empty() const { return mPoints.empty(); }
29 uint numLayerChanges() const { return mNumLayerChanges; }
30
32 Real length() const { return mLength; }
34 Real RMSD() const { return mRMSD; }
36 float winding() const { return mWinding; }
37 float turning() const { return mTurning; } // sum of abs(angle)
38
39 Bbox_2 bbox() const;
40 Bbox_2 bbox(int z) const;
41
42 void clear();
43 void resizeTo1();
45 void setPoints(const std::vector<Point_25>&, uint start, uint size);
47 void _add(const Point_25 &v) { mPoints.push_back(v); }
49 void add(const Point_25&);
51 void extendTo(const Point_25&);
52 void append(const Path&);
53 void reverse();
54 uint removeUnnecessaryPoints();
55
58 void computeRMSD();
59 void computeWinding();
60
61 bool compare(const Path&) const;
62
63 Real squared_distance(const Point_25&, Real dz = std::numeric_limits<Real>::infinity()) const;
64 Real squared_distance(const Pin&) const;
65 bool intersects(const Path&) const;
66 bool violatesClearance(const Path&, Real clearance) const;
67 bool violatesClearance(const Via&, Real clearance) const;
68 uint countIntersections(const Path&) const;
69
70 std::string str() const;
71 PyObject *getIntegerPointsPy(Real scaleXY) const;
72 PyObject *getPointsNumpy() const;
73protected:
74 std::vector<Point_25> mPoints;
75 uint mNumLayerChanges{0};
76 Real mLength{0.0f};
77 Real mRMSD;
78 float mWinding;
79 float mTurning;
80};
81
82inline void Path::clear()
83{
84 mPoints.clear();
85 mLength = 0.0f;
86 mNumLayerChanges = 0;
87}
88inline void Path::resizeTo1()
89{
90 mPoints.resize(1);
91 mLength = 0.0f;
92 mNumLayerChanges = 0;
93}
94
95inline bool Path::isPlanarAt(uint i) const
96{
97 assert(i > 0 && i < mPoints.size());
98 return mPoints[i].z() == mPoints[i-1].z();
99}
100inline Segment_2 Path::getSegmentAt(uint i) const
101{
102 assert(isPlanarAt(i));
103 return Segment_2(mPoints[i-1].xy(), mPoints[i].xy());
104}
105
106inline Point_25 Path::pop_back()
107{
108 assert(!empty());
109 const auto v = mPoints.back();
110 mPoints.pop_back();
111 return v;
112}
113
114#endif // GYM_PCB_PATH_H
Definition Path.hpp:13
void extendTo(const Point_25 &)
Adds the new point; replaces the last point if the new one continues the segment formed by the last t...
Real length() const
Length of the path (assumes it is contiguous).
Definition Path.hpp:32
void setPoints(const std::vector< Point_25 > &, uint start, uint size)
All modification functions except reverse() invalidate the statistics.
float winding() const
The winding number is the sum of the angles between the segments (0 for an Z, 90 for an L,...
Definition Path.hpp:36
void _add(const Point_25 &v)
Adds the new point but does not update any statistics or do any checks.
Definition Path.hpp:47
Real RMSD() const
The root mean squared distance of the from the straight line between the first and last point (assume...
Definition Path.hpp:34
void add(const Point_25 &)
Adds the new point and updates length and layer change count. Asserts that layer changes don't have p...
void computeLength()
These need to be called whenever segments are added or removed.
Definition Pin.hpp:18
Definition Geometry.hpp:131
Definition Via.hpp:10