PCB Environment: /home/chr/devel/PhD/Environment/pub/PCBEnv/pcbenv/cxx/Via.hpp Source File

PCB Environment 2

Loading...
Searching...
No Matches
Via.hpp
1#ifndef GYM_PCB_VIA_H
2#define GYM_PCB_VIA_H
3
4#include "Py.hpp"
5#include "Geometry.hpp"
6
7class WideSegment_25;
8
9 class Via
10{
11public:
12 Via() { }
13 Via(const Point_2&, uint z1, uint z2, Real r);
14 const Point_2& location() const { return mPoint; }
15 uint zmin() const { return mLayer[0]; }
16 uint zmax() const { return mLayer[1]; }
17 uint z(uint i) const { return mLayer[i]; }
18 uint height() const { return zmax() - zmin() + 1; }
19 Real diameter() const { return mRadius * 2.0; }
20 Real radius() const { return mRadius; }
21 Real squared_radius() const { return mRadius * mRadius; }
22 bool overlaps(const WideSegment_25&, Real clearance, Point_25 * = 0) const;
23 bool overlaps(const Via&, Real clearance, Point_25 * = 0) const;
24 bool contains(const Point_25&) const;
25 Bbox_2 bbox() const;
26 Circle_2 getCircle() const { return Circle_2(mPoint, mRadius * mRadius); }
27 bool onLayer(uint z) const { return mLayer[0] <= z && z <= mLayer[1]; }
29 uint otherEnd(uint z) const;
30 Point_25 otherEnd(const Point_25&) const;
31 Point_25 zminEnd() const { return Point_25(mPoint, zmin()); }
32 Point_25 zmaxEnd() const { return Point_25(mPoint, zmax()); }
33 void extendTo(uint z);
34 void merge(const Via&);
35 uint cutLayers(uint zmin, uint zmax); // returns height left
36 void setRange(uint zmin, uint zmax);
37 static Via fromPy(PyObject *);
38 std::string str() const;
39 PyObject *getPy() const;
40 PyObject *getShortPy() const;
41private:
42 Point_2 mPoint;
43 uint mLayer[2];
44 Real mRadius;
45};
46inline Via::Via(const Point_2 &v, uint z1, uint z2, Real r) : mPoint(v), mRadius(r)
47{
48 if (z1 == z2)
49 throw std::invalid_argument("via of 0 height");
50 mLayer[0] = std::min(z1, z2);
51 mLayer[1] = std::max(z1, z2);
52}
53 inline uint Via::otherEnd(uint z) const
54{
55 if (z != zmin() && z != zmax())
56 throw std::runtime_error("the other end of this via from the specified point is not clearly defined");
57 return z == zmin() ? zmax() : zmin();
58}
59inline Point_25 Via::otherEnd(const Point_25 &v) const
60{
61 assert(contains(v));
62 return Point_25(v.xy(), otherEnd(v.z()));
63}
64inline void Via::extendTo(uint z)
65{
66 mLayer[0] = std::min(mLayer[0], z);
67 mLayer[1] = std::max(mLayer[1], z);
68}
69inline void Via::setRange(uint zmin, uint zmax)
70{
71 assert(zmin <= zmax);
72 mLayer[0] = zmin;
73 mLayer[1] = zmax;
74}
75
76#endif // GYM_PCB_VIA_H
Point_25
Definition Geometry.hpp:131
Via::otherEnd
uint otherEnd(uint z) const
FIXME: We need to distinguish between the vertical path of a track and the via itself,...
Definition Via.hpp:53
WideSegment_25
Definition AShape.hpp:332