1#ifndef GYM_PCB_NAVGRID_H
2#define GYM_PCB_NAVGRID_H
5#include "Rasterizer.hpp"
29constexpr const bool CanSafelyEraseOverlappingSegments =
false;
39 bool initialized()
const {
return !std::isnan(Clearance); }
40 bool operator==(
const NavSpacings &that)
const {
return Clearance == that.Clearance && TrackWidthHalf == that.TrackWidthHalf && ViaRadius == that.ViaRadius; }
43 Real getExpansionForVias(Real clarance)
const;
53 void setViolationCostInf() { Violation = std::numeric_limits<float>::infinity(); }
54 void setXYBiasNone() { WrongDirection = 1.0f; }
55 bool valid()
const {
return MaskedLayer >= 0.0f && Via >= 0.0f && Violation >= 0.0f && WrongDirection >= 0.0f; }
56 void setPy(PyObject *);
60class NavGrid :
public UniformGrid25
64 const PCBoard& getPCB()
const {
return mPCB; }
65 PCBoard& getPCB() {
return mPCB; }
68 void copyFrom(
const NavGrid&);
70 const std::vector<NavPoint>& getPoints()
const {
return mPoints; }
71 std::vector<NavPoint>& getPoints() {
return mPoints; }
72 uint getNumPoints()
const {
return mPoints.size(); }
74 const NavPoint& getPoint(uint i)
const {
return mPoints[i]; }
75 const NavPoint& getPoint(uint x, uint y, uint z)
const;
76 const NavPoint *getPoint(
const Point_2&, uint z)
const;
77 const NavPoint *getPoint(
const Point_25 &v)
const {
return getPoint(v.xy(), v.z()); }
78 NavPoint& getPoint(uint i) {
return mPoints[i]; }
79 NavPoint& getPoint(uint x, uint y, uint z);
81 NavPoint *getPoint(
const Point_2&, uint z);
83 int getDirectionStride(
GridDirection d)
const { assert(d.n() <= 9);
return mDirectionStride[d.n()]; }
84 uint32_t getAddressOffset(
const NavPoint *nav)
const;
85 NavPoint *getPointFromAddressOffset(uint32_t);
87 const NavSpacings& getSpacings()
const {
return mSpacings; }
89 void initSpacingsForAnyRoutedTrack();
92 void resetKeepoutsRRR();
101 void getCosts(std::vector<float>&, uint index);
102 void setCosts(uint index,
float,
const IBox_3&);
103 void setCosts(uint index,
const float *,
const IBox_3&);
104 void setCosts(uint index,
const float *);
105 AStarCosts& getAStarCosts() {
return mAStarCosts; }
109 uint16_t nextRasterSeq();
110 uint16_t nextSearchSeq();
111 uint16_t getSearchSeq()
const {
return mSearchSeq; }
113 std::string str(
const IBox_3 * = 0)
const;
114 PyObject *getPy(
const IBox_3&)
const;
115 PyObject *getPathCoordinatesNumpy(
const Track&)
const;
119 std::vector<NavPoint> mPoints;
122 int mDirectionStride[10];
126 void initDirectionStrides();
128 void rasterizeFootprints();
129 void rasterizeClearanceAreas();
132 uint16_t mSearchSeq{0};
133 uint16_t mRasterSeq{0};
134 void resetSearchSeq();
135 void resetRasterSeq();
138inline NavPoint& NavGrid::getPoint(uint x, uint y, uint z)
140 return mPoints.at(LinearIndex(z,y,x));
142inline const NavPoint& NavGrid::getPoint(uint x, uint y, uint z)
const
144 return mPoints.at(LinearIndex(z,y,x));
146inline NavPoint *NavGrid::getPoint(
const Point_2 &v, uint z)
148 const uint x = XIndex(v.x(), 0.0);
149 const uint y = YIndex(v.y(), 0.0);
150 return inside(x,y,z) ? &getPoint(x, y, z) : 0;
152inline const NavPoint *NavGrid::getPoint(
const Point_2 &v, uint z)
const
154 const uint x = XIndex(v.x(), 0.0);
155 const uint y = YIndex(v.y(), 0.0);
156 return inside(x,y,z) ? &getPoint(x, y, z) : 0;
159inline uint16_t NavGrid::nextSearchSeq()
161 if (mSearchSeq == 0x7fff)
165inline uint16_t NavGrid::nextRasterSeq()
167 if (mRasterSeq == 0xffff)
174 return std::max(Clearance, clearance) + TrackWidthHalf;
176inline Real NavSpacings::getExpansionForVias(Real clearance)
const
178 return std::max(Clearance, clearance) + ViaRadius;
183 char *_this =
const_cast<char *
>(
reinterpret_cast<const char *
>(
this));
186 return reinterpret_cast<NavPoint *
>(_this + nav.getDirectionStride(d));
189inline uint32_t NavGrid::getAddressOffset(
const NavPoint *nav)
const
191 const char *base =
reinterpret_cast<const char *
>(&mPoints[0]);
192 const char *addr =
reinterpret_cast<const char *
>(nav);
195inline NavPoint *NavGrid::getPointFromAddressOffset(uint32_t offset)
197 char *base =
reinterpret_cast<char *
>(&mPoints[0]);
198 return reinterpret_cast<NavPoint *
>(base + offset);
Definition Component.hpp:18
Definition Connection.hpp:17
Definition GridDirection.hpp:6
Definition IPoint3.hpp:36
The grid-representation of the board.
Definition NavGrid.hpp:61
Definition NavPoint.hpp:116
Definition PCBoard.hpp:36
Definition Geometry.hpp:131
Definition NavGrid.hpp:47
Definition IPoint3.hpp:60
Definition NavPoint.hpp:93
This struct stores the spacing requirements the NavGrid is/should be prepared for.
Definition NavGrid.hpp:33
Real getExpansionForTracks(Real clearance) const
@clearance is the clearance required by the obstacle, this.Clearance is that required by the track.
Definition NavGrid.hpp:172