Leviathan  0.8.0.0
Leviathan game engine
Leviathan::Float2 Struct Reference

#include <Types.h>

Public Member Functions

DLLEXPORT constexpr Float2 () noexcept=default
 
DLLEXPORT constexpr Float2 (float x, float y)
 
DLLEXPORT Float2 (const Int2 &values) noexcept
 
DLLEXPORT constexpr Float2 (float data)
 
DLLEXPORT bool HasInvalidValues () const noexcept
 
DLLEXPORT void CheckForNans () const
 
DLLEXPORT float & operator[] (int nindex)
 
DLLEXPORT Float2 operator+ (const Float2 &other) const noexcept
 
DLLEXPORT Float2operator+= (const Float2 &other) noexcept
 
DLLEXPORT Float2 operator- (const Float2 &other) const noexcept
 
DLLEXPORT Float2operator-= (const Float2 &other) noexcept
 
DLLEXPORT Float2 operator- () const noexcept
 
DLLEXPORT Float2 operator+ () const noexcept
 
DLLEXPORT Float2 operator* (const Float2 &other) const noexcept
 
DLLEXPORT Float2operator*= (const Float2 &other) noexcept
 
DLLEXPORT Float2 operator/ (float val) const
 
DLLEXPORT Float2operator/= (float val)
 
DLLEXPORT Float2 operator* (float val) const noexcept
 
DLLEXPORT Float2operator*= (float val) noexcept
 
DLLEXPORT Float2 operator/ (const Float2 &other) const
 
DLLEXPORT Float2operator/= (const Float2 &other)
 
DLLEXPORT bool operator< (const Float2 &other) const noexcept
 
DLLEXPORT bool operator<= (const Float2 &other) const noexcept
 
DLLEXPORT bool operator> (const Float2 &other) const noexcept
 
DLLEXPORT bool operator>= (const Float2 &other) const noexcept
 
DLLEXPORT bool operator== (const Float2 &other) const noexcept
 
DLLEXPORT bool operator!= (const Float2 &other) const noexcept
 
DLLEXPORT float GetX () const noexcept
 
DLLEXPORT float GetY () const noexcept
 
DLLEXPORT void SetX (float val)
 
DLLEXPORT void SetY (float val)
 
DLLEXPORT float HAdd () const noexcept
 
DLLEXPORT float HAddAbs () const noexcept
 
DLLEXPORT Float2 MinElements (const Float2 &other) const noexcept
 
DLLEXPORT Float2 MaxElements (const Float2 &other) const noexcept
 
DLLEXPORT Float2 Clamp (const Float2 &min, const Float2 &max) const noexcept
 
DLLEXPORT float Dot (const Float2 &val) const noexcept
 
DLLEXPORT float Length () const noexcept
 
DLLEXPORT float LengthSquared () const noexcept
 
DLLEXPORT Float2 Normalize () const
 
DLLEXPORT Float2 NormalizeSafe (const Float2 &safer) const noexcept
 
DLLEXPORT bool IsNormalized () const noexcept
 
DLLEXPORT Float2 Lerp (const Float2 &other, float f) const noexcept
 
DLLEXPORT bool Compare (const Float2 &other, float tolerance) const noexcept
 
 VALUE_TYPE (Float2)
 

Public Attributes

float X = 0
 
float Y = 0
 

Detailed Description

Definition at line 654 of file Types.h.

Constructor & Destructor Documentation

◆ Float2() [1/4]

DLLEXPORT constexpr Leviathan::Float2::Float2 ( )
inlinedefaultnoexcept

◆ Float2() [2/4]

DLLEXPORT constexpr Leviathan::Float2::Float2 ( float  x,
float  y 
)
inline

Definition at line 658 of file Types.h.

658  : X(x), Y(y)
659  {
660  DO_NAN_CHECK;
661  }
#define DO_NAN_CHECK
Definition: Types.h:20

◆ Float2() [3/4]

DLLEXPORT Leviathan::Float2::Float2 ( const Int2 values)
inlinenoexcept

Definition at line 663 of file Types.h.

663  :
664  X(static_cast<float>(values.X)), Y(static_cast<float>(values.Y))
665  {
666  DO_NAN_CHECK;
667  }
#define DO_NAN_CHECK
Definition: Types.h:20

◆ Float2() [4/4]

DLLEXPORT constexpr Leviathan::Float2::Float2 ( float  data)
inlineexplicit

Definition at line 669 of file Types.h.

669  : X(data), Y(data)
670  {
671  DO_NAN_CHECK;
672  }
#define DO_NAN_CHECK
Definition: Types.h:20

Member Function Documentation

◆ CheckForNans()

DLLEXPORT void Leviathan::Float2::CheckForNans ( ) const
inline

Definition at line 679 of file Types.h.

680  {
681  if(HasInvalidValues()) {
682  DEBUG_BREAK;
683  throw std::runtime_error("Float2 has NaNs (or infinites in it) in it!");
684  }
685  }
DLLEXPORT bool HasInvalidValues() const noexcept
Definition: Types.h:674

◆ Clamp()

DLLEXPORT Float2 Leviathan::Float2::Clamp ( const Float2 min,
const Float2 max 
) const
inlinenoexcept

Definition at line 876 of file Types.h.

877  {
878  const Float2 minval = this->MinElements(max);
879  return min.MaxElements(minval);
880  }
DLLEXPORT Float2 MinElements(const Float2 &other) const noexcept
Definition: Types.h:865
DLLEXPORT constexpr Float2() noexcept=default

◆ Compare()

DLLEXPORT bool Leviathan::Float2::Compare ( const Float2 other,
float  tolerance 
) const
inlinenoexcept

Definition at line 935 of file Types.h.

936  {
937  const Float2 difference = (*this) - other;
938  return difference.Dot(difference) < tolerance * tolerance;
939  }
DLLEXPORT constexpr Float2() noexcept=default

◆ Dot()

DLLEXPORT float Leviathan::Float2::Dot ( const Float2 val) const
inlinenoexcept

Definition at line 884 of file Types.h.

885  {
886  return X * val.X + Y * val.Y;
887  }

◆ GetX()

DLLEXPORT float Leviathan::Float2::GetX ( ) const
inlinenoexcept

Definition at line 829 of file Types.h.

830  {
831  return X;
832  }

◆ GetY()

DLLEXPORT float Leviathan::Float2::GetY ( ) const
inlinenoexcept

Definition at line 834 of file Types.h.

835  {
836  return Y;
837  }

◆ HAdd()

DLLEXPORT float Leviathan::Float2::HAdd ( ) const
inlinenoexcept

Definition at line 853 of file Types.h.

854  {
855  return X + Y;
856  }

◆ HAddAbs()

DLLEXPORT float Leviathan::Float2::HAddAbs ( ) const
inlinenoexcept

Definition at line 859 of file Types.h.

860  {
861  return std::fabs(X) + std::fabs(Y);
862  }

◆ HasInvalidValues()

DLLEXPORT bool Leviathan::Float2::HasInvalidValues ( ) const
inlinenoexcept

Definition at line 674 of file Types.h.

675  {
676  return !std::isfinite(X) || !std::isfinite(Y);
677  }
#define isfinite
Definition: jsoncpp.cpp:4247

◆ IsNormalized()

DLLEXPORT bool Leviathan::Float2::IsNormalized ( ) const
inlinenoexcept

Definition at line 921 of file Types.h.

922  {
923  // is absolute -1.f under normalization tolerance //
924  return fabs(X * X + Y * Y - 1.0f) < NORMALIZATION_TOLERANCE;
925  }
constexpr float NORMALIZATION_TOLERANCE
For checking vector normalization.
Definition: Define.h:50

◆ Length()

DLLEXPORT float Leviathan::Float2::Length ( ) const
inlinenoexcept

Definition at line 890 of file Types.h.

891  {
892  return std::sqrt(LengthSquared());
893  }
DLLEXPORT float LengthSquared() const noexcept
Definition: Types.h:895

◆ LengthSquared()

DLLEXPORT float Leviathan::Float2::LengthSquared ( ) const
inlinenoexcept

Definition at line 895 of file Types.h.

896  {
897  return X * X + Y * Y;
898  }

◆ Lerp()

DLLEXPORT Float2 Leviathan::Float2::Lerp ( const Float2 other,
float  f 
) const
inlinenoexcept

Definition at line 929 of file Types.h.

930  {
931  return Float2((other.X - X) * f + X, (other.Y - Y) * f + Y);
932  }
DLLEXPORT constexpr Float2() noexcept=default

◆ MaxElements()

DLLEXPORT Float2 Leviathan::Float2::MaxElements ( const Float2 other) const
inlinenoexcept

Definition at line 870 of file Types.h.

871  {
872  return Float2(X > other.X ? X : other.X, Y > other.Y ? Y : other.Y);
873  }
DLLEXPORT constexpr Float2() noexcept=default

◆ MinElements()

DLLEXPORT Float2 Leviathan::Float2::MinElements ( const Float2 other) const
inlinenoexcept

Definition at line 865 of file Types.h.

866  {
867  return Float2(X < other.X ? X : other.X, Y < other.Y ? Y : other.Y);
868  }
DLLEXPORT constexpr Float2() noexcept=default

◆ Normalize()

DLLEXPORT Float2 Leviathan::Float2::Normalize ( ) const
inline

Definition at line 901 of file Types.h.

902  {
903  const float length = Length();
904  if(length == 0)
905  return Float2(0, 0);
906  return (*this) / length;
907  }
DLLEXPORT constexpr Float2() noexcept=default
DLLEXPORT float Length() const noexcept
Definition: Types.h:890

◆ NormalizeSafe()

DLLEXPORT Float2 Leviathan::Float2::NormalizeSafe ( const Float2 safer) const
inlinenoexcept

Definition at line 910 of file Types.h.

911  {
912  // security //
913  LEVIATHAN_ASSERT(safer.IsNormalized(), "safer not normalized");
914  if(LengthSquared() == 0)
915  return safer;
916  const float length = Length();
917  return (*this) / length;
918  }
DLLEXPORT float LengthSquared() const noexcept
Definition: Types.h:895
#define LEVIATHAN_ASSERT(x, msg)
Definition: Define.h:100
DLLEXPORT float Length() const noexcept
Definition: Types.h:890

◆ operator!=()

DLLEXPORT bool Leviathan::Float2::operator!= ( const Float2 other) const
inlinenoexcept

Definition at line 822 of file Types.h.

823  {
824  return X != other.X || Y != other.Y;
825  }

◆ operator*() [1/2]

DLLEXPORT Float2 Leviathan::Float2::operator* ( const Float2 other) const
inlinenoexcept

Definition at line 740 of file Types.h.

741  {
742  return Float2(X * other.X, Y * other.Y);
743  }
DLLEXPORT constexpr Float2() noexcept=default

◆ operator*() [2/2]

DLLEXPORT Float2 Leviathan::Float2::operator* ( float  val) const
inlinenoexcept

Definition at line 768 of file Types.h.

769  {
770  return Float2(X * val, Y * val);
771  }
DLLEXPORT constexpr Float2() noexcept=default

◆ operator*=() [1/2]

DLLEXPORT Float2& Leviathan::Float2::operator*= ( const Float2 other)
inlinenoexcept

Definition at line 745 of file Types.h.

746  {
747  X *= other.X;
748  Y *= other.Y;
749  DO_NAN_CHECK;
750  return *this;
751  }
#define DO_NAN_CHECK
Definition: Types.h:20

◆ operator*=() [2/2]

DLLEXPORT Float2& Leviathan::Float2::operator*= ( float  val)
inlinenoexcept

Definition at line 773 of file Types.h.

774  {
775  X *= val;
776  Y *= val;
777  DO_NAN_CHECK;
778  return *this;
779  }
#define DO_NAN_CHECK
Definition: Types.h:20

◆ operator+() [1/2]

DLLEXPORT Float2 Leviathan::Float2::operator+ ( const Float2 other) const
inlinenoexcept

Definition at line 702 of file Types.h.

703  {
704  return Float2(X + other.X, Y + other.Y);
705  }
DLLEXPORT constexpr Float2() noexcept=default

◆ operator+() [2/2]

DLLEXPORT Float2 Leviathan::Float2::operator+ ( ) const
inlinenoexcept

Definition at line 734 of file Types.h.

735  {
736  return Float2(*this);
737  }
DLLEXPORT constexpr Float2() noexcept=default

◆ operator+=()

DLLEXPORT Float2& Leviathan::Float2::operator+= ( const Float2 other)
inlinenoexcept

Definition at line 707 of file Types.h.

708  {
709  X += other.X;
710  Y += other.Y;
711  return *this;
712  }

◆ operator-() [1/2]

DLLEXPORT Float2 Leviathan::Float2::operator- ( const Float2 other) const
inlinenoexcept

Definition at line 715 of file Types.h.

716  {
717  return Float2(X - other.X, Y - other.Y);
718  }
DLLEXPORT constexpr Float2() noexcept=default

◆ operator-() [2/2]

DLLEXPORT Float2 Leviathan::Float2::operator- ( ) const
inlinenoexcept

Definition at line 728 of file Types.h.

729  {
730  return Float2(-X, -Y);
731  }
DLLEXPORT constexpr Float2() noexcept=default

◆ operator-=()

DLLEXPORT Float2& Leviathan::Float2::operator-= ( const Float2 other)
inlinenoexcept

Definition at line 720 of file Types.h.

721  {
722  X -= other.X;
723  Y -= other.Y;
724  return *this;
725  }

◆ operator/() [1/2]

DLLEXPORT Float2 Leviathan::Float2::operator/ ( float  val) const
inline

Definition at line 754 of file Types.h.

755  {
756  return Float2(X / val, Y / val);
757  }
DLLEXPORT constexpr Float2() noexcept=default

◆ operator/() [2/2]

DLLEXPORT Float2 Leviathan::Float2::operator/ ( const Float2 other) const
inline

Definition at line 782 of file Types.h.

783  {
784  return Float2(X / other.X, Y / other.Y);
785  }
DLLEXPORT constexpr Float2() noexcept=default

◆ operator/=() [1/2]

DLLEXPORT Float2& Leviathan::Float2::operator/= ( float  val)
inline

Definition at line 759 of file Types.h.

760  {
761  X /= val;
762  Y /= val;
763  DO_NAN_CHECK;
764  return *this;
765  }
#define DO_NAN_CHECK
Definition: Types.h:20

◆ operator/=() [2/2]

DLLEXPORT Float2& Leviathan::Float2::operator/= ( const Float2 other)
inline

Definition at line 787 of file Types.h.

788  {
789  X /= other.X;
790  Y /= other.Y;
791  DO_NAN_CHECK;
792  return *this;
793  }
#define DO_NAN_CHECK
Definition: Types.h:20

◆ operator<()

DLLEXPORT bool Leviathan::Float2::operator< ( const Float2 other) const
inlinenoexcept

Definition at line 797 of file Types.h.

798  {
799  return std::tie(X, Y) < std::tie(other.X, other.Y);
800  }

◆ operator<=()

DLLEXPORT bool Leviathan::Float2::operator<= ( const Float2 other) const
inlinenoexcept

Definition at line 802 of file Types.h.

803  {
804  return std::tie(X, Y) <= std::tie(other.X, other.Y);
805  }

◆ operator==()

DLLEXPORT bool Leviathan::Float2::operator== ( const Float2 other) const
inlinenoexcept

Definition at line 817 of file Types.h.

818  {
819  return X == other.X && Y == other.Y;
820  }

◆ operator>()

DLLEXPORT bool Leviathan::Float2::operator> ( const Float2 other) const
inlinenoexcept

Definition at line 807 of file Types.h.

808  {
809  return std::tie(X, Y) > std::tie(other.X, other.Y);
810  }

◆ operator>=()

DLLEXPORT bool Leviathan::Float2::operator>= ( const Float2 other) const
inlinenoexcept

Definition at line 812 of file Types.h.

813  {
814  return std::tie(X, Y) >= std::tie(other.X, other.Y);
815  }

◆ operator[]()

DLLEXPORT float& Leviathan::Float2::operator[] ( int  nindex)
inline

Definition at line 688 of file Types.h.

689  {
690  switch(nindex) {
691  case 0: return X;
692  case 1: return Y;
693  default: break;
694  }
695 
696  LEVIATHAN_ASSERT(0, "invalid [] access");
697  return X;
698  }
#define LEVIATHAN_ASSERT(x, msg)
Definition: Define.h:100

◆ SetX()

DLLEXPORT void Leviathan::Float2::SetX ( float  val)
inline

Definition at line 840 of file Types.h.

841  {
842  X = val;
843  DO_NAN_CHECK;
844  }
#define DO_NAN_CHECK
Definition: Types.h:20

◆ SetY()

DLLEXPORT void Leviathan::Float2::SetY ( float  val)
inline

Definition at line 846 of file Types.h.

847  {
848  Y = val;
849  DO_NAN_CHECK;
850  }
#define DO_NAN_CHECK
Definition: Types.h:20

◆ VALUE_TYPE()

Leviathan::Float2::VALUE_TYPE ( Float2  )

Member Data Documentation

◆ X

float Leviathan::Float2::X = 0

Definition at line 950 of file Types.h.

◆ Y

float Leviathan::Float2::Y = 0

Definition at line 951 of file Types.h.


The documentation for this struct was generated from the following file: