8template <
typename T>
struct vec2 {
13 constexpr vec2() =
default;
16 template <
typename U>
explicit constexpr vec2(U
xy) :
x(
xy),
y(
xy) {}
119 return (
x ==
p.x &&
y ==
p.y);
123 return (
x !=
p.x ||
y !=
p.y);
131 return vec2<U>(
static_cast<U
>(
x),
static_cast<U
>(
y));
145 return sqrt(dx * dx + dy * dy);
173 line_xy(T start_x, T start_y, T end_x, T end_y)
174 :
start(start_x, start_y),
end(end_x, end_y) {}
179 vec2<T> *out_projected =
nullptr)
const {
189 vec2<T> &out_proj = out_projected ? *out_projected : maybe;
190 float dx = b.
x - a.
x;
191 float dy = b.
y - a.
y;
192 float len_sq = dx * dx + dy * dy;
194#pragma GCC diagnostic push
195#pragma GCC diagnostic ignored "-Wfloat-equal"
196 const bool is_zero = (len_sq == 0.0f);
197#pragma GCC diagnostic pop
204 return sqrt(dx * dx + dy * dy);
208 float t = ((
p.x - a.
x) * dx + (
p.y - a.
y) * dy) / len_sq;
217 out_proj.
x = a.
x + t * dx;
218 out_proj.
y = a.
y + t * dy;
220 dx =
p.x - out_proj.
x;
221 dy =
p.y - out_proj.
y;
222 return sqrt(dx * dx + dy * dy);
226template <
typename T>
struct rect {
233 rect(T min_x, T min_y, T max_x, T max_y)
234 :
mMin(min_x, min_y),
mMax(max_x, max_y) {}
275 return !(*
this == r);
unsigned int xy(unsigned int x, unsigned int y)
vec2< float > pair_xy_float
Implements a simple red square effect for 2D LED grids.
static FASTLED_NAMESPACE_BEGIN uint8_t const p[]
static float distance_to_line_with_point(vec2< T > p, vec2< T > a, vec2< T > b, vec2< T > *out_projected)
float distance_to(const vec2< T > &p, vec2< T > *out_projected=nullptr) const
line_xy(const vec2< T > &start, const vec2< T > &end)
line_xy(T start_x, T start_y, T end_x, T end_y)
pair_xy(const vec2< T > &p)
bool operator==(const rect &r) const
rect(const vec2< T > &min, const vec2< T > &max)
bool operator!=(const rect< U > &r) const
void expand(const rect &r)
rect(T min_x, T min_y, T max_x, T max_y)
bool contains(const vec2< T > &p) const
void expand(const vec2< T > &p)
bool operator==(const rect< U > &r) const
bool operator!=(const rect &r) const
bool contains(const T &x, const T &y) const
bool operator==(const vec2< U > &p) const
vec2 operator/(const vec2 &p) const
vec2 operator/(const NumberT &p) const
vec2 & operator/=(const double &f)
vec2 operator-(const NumberT &p) const
vec2 & operator/=(const float &f)
vec2 getMin(const vec2 &p) const
T distance(const vec2 &p) const
vec2 operator*(const vec2 &p) const
vec2 operator+(const NumberT &p) const
vec2 & operator=(const vec2 &p)
vec2 getMax(const vec2< U > &p) const
vec2 getMax(const vec2 &p) const
vec2 & operator/=(const vec2 &p)
vec2 operator-(const vec2 &p) const
constexpr vec2(const vec2 &p)
vec2 operator+(const vec2 &p) const
bool operator==(const vec2 &p) const
bool operator!=(const vec2 &p) const
vec2 & operator*=(const double &f)
vec2 & operator/=(const uint16_t &d)
vec2 & operator+=(const vec2 &p)
vec2 operator*(const NumberT &p) const
vec2 getMin(const vec2< U > &p) const
vec2 & operator-=(const vec2 &p)
vec2 & operator*=(const float &f)
vec2 operator+(const vec2< U > &p) const
vec2 & operator/=(const int &d)
bool operator!=(const vec2< U > &p) const