19 #pragma GCC optimize("O3") 68 return isnan(
x) || isnan(y);
74 return isinf(
x) || isinf(y);
102 template <
typename T>
108 template <
typename T>
114 template <
typename T>
120 template <
typename T>
126 template <
typename T>
129 float len = this->length() * v2.
length();
133 float cosv = ((*this)*v2) / len;
146 template <
typename T>
152 const Vector2<T> ss2_ss1 = seg2_start - seg1_start;
153 const float r1xr2 = r1 % r2;
154 const float q_pxr = ss2_ss1 % r1;
155 if (fabsf(r1xr2) < FLT_EPSILON) {
161 float t = (ss2_ss1 % r2) / r1xr2;
162 float u = q_pxr / r1xr2;
163 if ((u >= 0) && (u <= 1) && (t >= 0)) {
167 intersection = seg1_start + (r1*t);
179 template <
typename T>
183 const Vector2f seg_start_local = seg_start - circle_center;
186 const Vector2f seg_end_minus_start = seg_end - seg_start;
188 const float a =
sq(seg_end_minus_start.
x) +
sq(seg_end_minus_start.
y);
189 const float b = 2 * ((seg_end_minus_start.
x * seg_start_local.
x) + (seg_end_minus_start.
y * seg_start_local.
y));
190 const float c =
sq(seg_start_local.
x) +
sq(seg_start_local.
y) -
sq(radius);
191 const float delta =
sq(b) - (4.0f * a * c);
194 if (fabsf(a) < FLT_EPSILON) {
197 if (isnan(a) || isnan(b) || isnan(c) || isnan(delta)) {
206 const float delta_sqrt =
safe_sqrt(delta);
207 const float t1 = (-b + delta_sqrt) / (2.0
f * a);
208 const float t2 = (-b - delta_sqrt) / (2.0
f * a);
222 if ((t1 >= 0.0
f) && (t1 <= 1.0f)) {
225 intersection = seg_start + (seg_end_minus_start * t1);
230 if ((t2 >= 0.0
f) && (t2 <= 1.0f)) {
232 intersection = seg_start + (seg_end_minus_start *
t2);
float norm(const T first, const U second, const Params... parameters)
Vector2< T > & operator*=(const T num)
Vector2< T > operator+(const Vector2< T > &v) const
float safe_sqrt(const T v)
Vector2< T > & operator-=(const Vector2< T > &v)
T operator%(const Vector2< T > &v) const
static bool segment_intersection(const Vector2< T > &seg1_start, const Vector2< T > &seg1_end, const Vector2< T > &seg2_start, const Vector2< T > &seg2_end, Vector2< T > &intersection)
Vector2< T > & operator/=(const T num)
Vector2< T > operator*(const T num) const
bool operator!=(const Vector2< T > &v) const
float angle(const Vector2< T > &v2) const
bool operator==(const Vector2< T > &v) const
static bool circle_segment_intersection(const Vector2< T > &seg_start, const Vector2< T > &seg_end, const Vector2< T > &circle_center, float radius, Vector2< T > &intersection)
Vector2< T > operator-(void) const
Vector2< T > operator/(const T num) const
std::enable_if< std::is_integral< typename std::common_type< Arithmetic1, Arithmetic2 >::type >::value,bool >::type is_equal(const Arithmetic1 v_1, const Arithmetic2 v_2)
Vector2< T > & operator+=(const Vector2< T > &v)