226 TVector2(
const SizeType InX,
const SizeType InY)
232 template<
typename OtherType,
typename = std::enable_if_t<std::is_convertible_v<OtherType, SizeType>>>
233 TVector2(
const OtherType InX,
const OtherType InY)
234 : X(
static_cast<SizeType
>(InX))
235 , Y(
static_cast<SizeType
>(InY))
239 template<
typename OtherType,
typename = std::enable_if_t<std::is_convertible_v<OtherType, SizeType>>>
241 : X(
static_cast<SizeType
>(Other.X))
242 , Y(
static_cast<SizeType
>(Other.Y))
284 return TVector2((X - Other.X), (Y - Other.Y));
287 template<
typename OtherType>
290 static_assert(std::is_convertible_v<OtherType, SizeType>,
"Narrowing conversion");
291 return TVector2((X -
static_cast<SizeType
>(Other.X)), (Y -
static_cast<SizeType
>(Other.Y)));
296 return TVector2((X + Other.X), (Y + Other.Y));
299 template<
typename OtherType>
302 static_assert(std::is_convertible_v<OtherType, SizeType>,
"Narrowing conversion");
303 return TVector2((X +
static_cast<SizeType
>(Other.X)), (Y +
static_cast<SizeType
>(Other.Y)));
306 template<
typename OtherType>
309 static_assert(std::is_convertible_v<OtherType, SizeType>,
"Narrowing conversion");
310 X =
static_cast<SizeType
>(Other.X);
311 Y =
static_cast<SizeType
>(Other.Y);
315 bool operator==(
const TVector2& Other)
const
317 return ((X == Other.X) && (Y == Other.Y));
320 bool operator!=(
const TVector2& Other)
const
322 return !(*
this == Other);
325 template<
typename OtherType>
328 return ((X ==
static_cast<SizeType
>(Other.X)) && (Y ==
static_cast<SizeType
>(Other.Y)));
331 FORCEINLINE
bool IsNull()
const
333 return ((X == 0) && (Y == 0));
341 template<
typename VectorTypeA,
typename VectorTypeB>
342 static SizeType Min(
const VectorTypeA& A,
const VectorTypeB& B)
344 using ReturnType = SizeType;
348 template<
typename VectorTypeA,
typename VectorTypeB>
349 static SizeType Max(
const VectorTypeA& A,
const VectorTypeB& B)
351 using ReturnType = SizeType;
355 template<
typename VectorType>
356 static VectorType Inverse(
const VectorType& Vector)
361 template<
typename VectorType>
362 static VectorType InverseSafe(
const VectorType& Vector)
367 template<
typename StringType = std::
string>
368 FORCEINLINE StringType ToString()
const
370 if constexpr (std::is_same_v<StringType, std::string>)
372 if constexpr (std::is_floating_point_v<SizeType>)
374 return LK_FMT_LIB::format(
"({:.2f}, {:.2f})", X, Y);
378 return LK_FMT_LIB::format(
"({}, {})", X, Y);
382 else if constexpr (std::is_same_v<StringType, const char*>)
384 static constexpr uint16_t BufSize = 256;
385 if constexpr (std::is_floating_point_v<SizeType>)
387 static std::array<char, BufSize> Buffer;
388 std::snprintf(Buffer.data(), Buffer.size(),
"(%.2f, %.2f)", X, Y);
389 return Buffer.data();
393 static std::array<char, BufSize> Buffer;
394 std::snprintf(Buffer.data(), Buffer.size(),
"(%d, %d)", X, Y);
395 return Buffer.data();
400 friend std::ostream& operator<<(std::ostream& os,
const TVector2& Vector)
402 os << Vector.ToString();
406 template<
typename VectorType>
407 VectorType As()
const
409 if constexpr (std::is_same_v<VectorType, glm::vec2>)
411 return glm::vec2(X, Y);
413 else if constexpr (std::is_same_v<VectorType, ImVec2>)
419 static_assert(!std::is_same_v<VectorType, VectorType>,
"Unsupported VectorType in TVector2::As()");
425 operator glm::vec2() {
return glm::vec2(X, Y); }
426 operator ImVec2() {
return ImVec2(X, Y); }
428 static_assert(std::disjunction_v<
429 std::is_same<SizeType, int>,
430 std::is_same<SizeType, uint16_t>,
431 std::is_same<SizeType, uint32_t>,
432 std::is_same<SizeType, uint64_t>,
433 std::is_same<SizeType, int16_t>,
434 std::is_same<SizeType, int32_t>,
435 std::is_same<SizeType, int64_t>,
436 std::is_same<SizeType, float>,
437 std::is_same<SizeType, double>
438 >,
"TVector2 can only be instantiated with int, float or double types");
441 #if LK_VECTOR_ANONYMOUS_STRUCT
444 struct { SizeType X, Y; };
445 struct { SizeType R, G; };
446 struct { SizeType S, T; };
449 union { SizeType X, R, S; };
450 union { SizeType Y, G, T; };