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 };
76extern const LutEnumStr<PatchType> patch_type_lut;
77extern const LutEnumStr<ObjectType> object_type_lut;
78extern const LutEnumStr<Orientation> orientation_lut;
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))
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 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
274typedef Coord<float> Coordf;
275typedef Coord<int64_t> Coordi;
276typedef Coord<double> Coordd;
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)
334enum class CopyMode { DEEP, SHALLOW };
An abstract shape on 2D plane.
Definition shape.h:117
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