11enum class Orientation { LEFT, RIGHT, UP, DOWN };
15enum class ObjectType {
68 SCHEMATIC_BLOCK_SYMBOL,
74enum class PatchType { OTHER, TRACK, PAD, PAD_TH, VIA, PLANE, HOLE_PTH, HOLE_NPTH, BOARD_EDGE, TEXT, NET_TIE, N_TYPES };
88template <
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))
110 operator Coord<float>()
const
112 return Coord<float>(x, y);
114 operator Coord<double>()
const
116 return Coord<double>(x, y);
118 Coord<T> operator+(
const Coord<T> &a)
const
120 return Coord<T>(x + a.x, y + a.y);
122 Coord<T> operator-(
const Coord<T> &a)
const
124 return Coord<T>(x - a.x, y - a.y);
126 Coord<T> operator*(
const Coord<T> &a)
const
128 return Coord<T>(x * a.x, y * a.y);
130 Coord<T> operator*(T r)
const
132 return Coord<T>(x * r, y * r);
134 Coord<T> operator/(T r)
const
136 return Coord<T>(x / r, y / r);
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
158 static Coord<T>
min(
const Coord<T> &a,
const Coord<T> &b)
160 return Coord<T>(std::min(a.x, b.x), std::min(a.y, b.y));
166 static Coord<T>
max(
const Coord<T> &a,
const Coord<T> &b)
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);
200 T
dot(
const Coord<T> &a)
const
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 std::conditional_t<std::is_same_v<T, float>, float,
double> angle()
const
238 if constexpr (std::is_same_v<T, float>)
244 bool in_range(
const Coord<T> &a,
const Coord<T> &b)
const
246 return x > a.x && y > a.y && x < b.x && y < b.y;
249 void operator+=(
const Coord<T> a)
254 void operator-=(
const Coord<T> a)
267 std::array<T, 2> as_array()
const
283 Color(
double ir,
double ig,
double ib) : r(ir), g(ig), b(ib)
288 static Color new_from_int(
unsigned int ir,
unsigned ig,
unsigned ib)
290 return Color(ir / 255.0, ig / 255.0, ib / 255.0);
292 Color() : r(0), g(0), b(0)
302 bool operator<(
const ColorI &other)
const
304 return hashify() < other.hashify();
307 Color to_color()
const
309 return Color::new_from_int(r, g, b);
313 uint32_t hashify()
const
315 return r | (g << 8) | (b << 16);
319constexpr int64_t
operator"" _mm(
long double i)
323constexpr int64_t
operator"" _mm(
unsigned long long int i)
328struct shallow_copy_t {
329 explicit shallow_copy_t() =
default;
334enum class CopyMode { DEEP, SHALLOW };
Definition common.hpp:278
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 > min(const Coord< T > &a, const Coord< T > &b)
Definition common.hpp:158
static Coord< T > max(const Coord< T > &a, const Coord< T > &b)
Definition common.hpp:166
static Coord< T > euler(T r, T phi)
Definition common.hpp:176
Definition common.hpp:297
Definition common.hpp:328