11 enum class Orientation { LEFT, RIGHT, UP, DOWN };
15 enum class ObjectType {
68 SCHEMATIC_BLOCK_SYMBOL,
74 enum class PatchType { OTHER, TRACK, PAD, PAD_TH, VIA, PLANE, HOLE_PTH, HOLE_NPTH, BOARD_EDGE, TEXT, NET_TIE, N_TYPES };
76 extern const LutEnumStr<PatchType> patch_type_lut;
77 extern const LutEnumStr<ObjectType> object_type_lut;
78 extern const LutEnumStr<Orientation> orientation_lut;
88 template <
typename T>
class Coord {
101 Coord(T ix, T iy) : x(ix), y(iy)
107 Coord(std::vector<T> v) : x(v.at(0)), y(v.at(1))
138 bool operator==(
const Coord<T> &a)
const
140 return a.x == x && a.y == y;
142 bool operator!=(
const Coord<T> &a)
const
144 return !(a == *
this);
146 bool operator<(
const Coord<T> &a)
const
160 return Coord<T>(std::min(a.x, b.x), std::min(a.y, b.y));
168 return Coord<T>(std::max(a.x, b.x), std::max(a.y, b.y));
178 static_assert(std::is_floating_point_v<T>);
179 return {r * cos(phi), r * sin(phi)};
184 static_assert(std::is_floating_point_v<T>);
185 const T x2 = x * cos(a) - y * sin(a);
186 const T y2 = x * sin(a) + y * cos(a);
190 Coord<int64_t> to_coordi()
const
192 static_assert(std::is_floating_point_v<T>);
193 return Coord<int64_t>(x, y);
202 return x * a.x + y * a.y;
205 T cross(
const Coord<T> &other)
const
207 return (x * other.y) - (y * other.x);
215 return x * x + y * y;
220 static_assert(std::is_floating_point_v<T>);
224 Coord<T> normalize()
const
226 static_assert(std::is_floating_point_v<T>);
227 return *
this / mag();
232 static_assert(std::is_integral_v<T>);
236 bool in_range(
const Coord<T> &a,
const Coord<T> &b)
const
238 return x > a.x && y > a.y && x < b.x && y < b.y;
241 void operator+=(
const Coord<T> a)
246 void operator-=(
const Coord<T> a)
259 std::array<T, 2> as_array()
const
266 typedef Coord<float> Coordf;
267 typedef Coord<int64_t> Coordi;
268 typedef Coord<double> Coordd;
275 Color(
double ir,
double ig,
double ib) : r(ir), g(ig), b(ib)
280 static Color new_from_int(
unsigned int ir,
unsigned ig,
unsigned ib)
282 return Color(ir / 255.0, ig / 255.0, ib / 255.0);
284 Color() : r(0), g(0), b(0)
294 bool operator<(
const ColorI &other)
const
296 return hashify() < other.hashify();
299 Color to_color()
const
301 return Color::new_from_int(r, g, b);
305 uint32_t hashify()
const
307 return r | (g << 8) | (b << 16);
311 constexpr int64_t
operator"" _mm(
long double i)
315 constexpr int64_t
operator"" _mm(
unsigned long long int i)
326 enum class CopyMode { DEEP, SHALLOW };
Class SHAPE.
Definition: shape.h:59
Definition: common.hpp:270
Your typical coordinate class.
Definition: common.hpp:88
T dot(const Coord< T > &a) const
Definition: common.hpp:200
T mag_sq() const
Definition: common.hpp:213
static Coord< T > max(const Coord< T > &a, const Coord< T > &b)
Definition: common.hpp:166
static Coord< T > min(const Coord< T > &a, const Coord< T > &b)
Definition: common.hpp:158
static Coord< T > euler(T r, T phi)
Definition: common.hpp:176
Definition: common.hpp:289
Definition: common.hpp:320