Leviathan  0.8.0.0
Leviathan game engine
Leviathan::Float2 Struct Reference

#include <Types.h>

Public Member Functions

DLLEXPORT Float2 () noexcept=default
 
DLLEXPORT Float2 (float x, float y)
 
DLLEXPORT Float2 (const Int2 &values) noexcept
 
DLLEXPORT 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 577 of file Types.h.

Constructor & Destructor Documentation

◆ Float2() [1/4]

DLLEXPORT Leviathan::Float2::Float2 ( )
inlinedefaultnoexcept

◆ Float2() [2/4]

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

Definition at line 581 of file Types.h.

581  : X(x), Y(y)
582  {
583  DO_NAN_CHECK;
584  }
#define DO_NAN_CHECK
Definition: Types.h:20

◆ Float2() [3/4]

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

Definition at line 586 of file Types.h.

586  :
587  X(static_cast<float>(values.X)), Y(static_cast<float>(values.Y))
588  {
589  DO_NAN_CHECK;
590  }
#define DO_NAN_CHECK
Definition: Types.h:20

◆ Float2() [4/4]

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

Definition at line 592 of file Types.h.

592  : X(data), Y(data)
593  {
594  DO_NAN_CHECK;
595  }
#define DO_NAN_CHECK
Definition: Types.h:20

Member Function Documentation

◆ CheckForNans()

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

Definition at line 602 of file Types.h.

603  {
604  if(HasInvalidValues()) {
605  DEBUG_BREAK;
606  throw std::runtime_error("Float2 has NaNs (or infinites in it) in it!");
607  }
608  }
DLLEXPORT bool HasInvalidValues() const noexcept
Definition: Types.h:597

◆ Clamp()

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

Definition at line 799 of file Types.h.

800  {
801  const Float2 minval = this->MinElements(max);
802  return min.MaxElements(minval);
803  }
DLLEXPORT Float2() noexcept=default
DLLEXPORT Float2 MinElements(const Float2 &other) const noexcept
Definition: Types.h:788

◆ Compare()

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

Definition at line 858 of file Types.h.

859  {
860  const Float2 difference = (*this) - other;
861  return difference.Dot(difference) < tolerance * tolerance;
862  }
DLLEXPORT Float2() noexcept=default

◆ Dot()

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

Definition at line 807 of file Types.h.

808  {
809  return X * val.X + Y * val.Y;
810  }

◆ GetX()

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

Definition at line 752 of file Types.h.

753  {
754  return X;
755  }

◆ GetY()

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

Definition at line 757 of file Types.h.

758  {
759  return Y;
760  }

◆ HAdd()

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

Definition at line 776 of file Types.h.

777  {
778  return X + Y;
779  }

◆ HAddAbs()

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

Definition at line 782 of file Types.h.

783  {
784  return std::fabs(X) + std::fabs(Y);
785  }

◆ HasInvalidValues()

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

Definition at line 597 of file Types.h.

598  {
599  return !std::isfinite(X) || !std::isfinite(Y);
600  }
#define isfinite
Definition: jsoncpp.cpp:4247

◆ IsNormalized()

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

Definition at line 844 of file Types.h.

845  {
846  // is absolute -1.f under normalization tolerance //
847  return fabs(X * X + Y * Y - 1.0f) < NORMALIZATION_TOLERANCE;
848  }
constexpr float NORMALIZATION_TOLERANCE
For checking vector normalization.
Definition: Define.h:44

◆ Length()

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

Definition at line 813 of file Types.h.

814  {
815  return std::sqrt(LengthSquared());
816  }
DLLEXPORT float LengthSquared() const noexcept
Definition: Types.h:818

◆ LengthSquared()

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

Definition at line 818 of file Types.h.

819  {
820  return X * X + Y * Y;
821  }

◆ Lerp()

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

Definition at line 852 of file Types.h.

853  {
854  return Float2((other.X - X) * f + X, (other.Y - Y) * f + Y);
855  }
DLLEXPORT Float2() noexcept=default

◆ MaxElements()

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

Definition at line 793 of file Types.h.

794  {
795  return Float2(X > other.X ? X : other.X, Y > other.Y ? Y : other.Y);
796  }
DLLEXPORT Float2() noexcept=default

◆ MinElements()

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

Definition at line 788 of file Types.h.

789  {
790  return Float2(X < other.X ? X : other.X, Y < other.Y ? Y : other.Y);
791  }
DLLEXPORT Float2() noexcept=default

◆ Normalize()

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

Definition at line 824 of file Types.h.

825  {
826  const float length = Length();
827  if(length == 0)
828  return Float2(0, 0);
829  return (*this) / length;
830  }
DLLEXPORT Float2() noexcept=default
DLLEXPORT float Length() const noexcept
Definition: Types.h:813

◆ NormalizeSafe()

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

Definition at line 833 of file Types.h.

834  {
835  // security //
836  LEVIATHAN_ASSERT(safer.IsNormalized(), "safer not normalized");
837  if(LengthSquared() == 0)
838  return safer;
839  const float length = Length();
840  return (*this) / length;
841  }
DLLEXPORT float LengthSquared() const noexcept
Definition: Types.h:818
#define LEVIATHAN_ASSERT(x, msg)
Definition: Define.h:92
DLLEXPORT float Length() const noexcept
Definition: Types.h:813

◆ operator!=()

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

Definition at line 745 of file Types.h.

746  {
747  return X != other.X || Y != other.Y;
748  }

◆ operator*() [1/2]

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

Definition at line 663 of file Types.h.

664  {
665  return Float2(X * other.X, Y * other.Y);
666  }
DLLEXPORT Float2() noexcept=default

◆ operator*() [2/2]

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

Definition at line 691 of file Types.h.

692  {
693  return Float2(X * val, Y * val);
694  }
DLLEXPORT Float2() noexcept=default

◆ operator*=() [1/2]

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

Definition at line 668 of file Types.h.

669  {
670  X *= other.X;
671  Y *= other.Y;
672  DO_NAN_CHECK;
673  return *this;
674  }
#define DO_NAN_CHECK
Definition: Types.h:20

◆ operator*=() [2/2]

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

Definition at line 696 of file Types.h.

697  {
698  X *= val;
699  Y *= val;
700  DO_NAN_CHECK;
701  return *this;
702  }
#define DO_NAN_CHECK
Definition: Types.h:20

◆ operator+() [1/2]

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

Definition at line 625 of file Types.h.

626  {
627  return Float2(X + other.X, Y + other.Y);
628  }
DLLEXPORT Float2() noexcept=default

◆ operator+() [2/2]

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

Definition at line 657 of file Types.h.

658  {
659  return Float2(*this);
660  }
DLLEXPORT Float2() noexcept=default

◆ operator+=()

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

Definition at line 630 of file Types.h.

631  {
632  X += other.X;
633  Y += other.Y;
634  return *this;
635  }

◆ operator-() [1/2]

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

Definition at line 638 of file Types.h.

639  {
640  return Float2(X - other.X, Y - other.Y);
641  }
DLLEXPORT Float2() noexcept=default

◆ operator-() [2/2]

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

Definition at line 651 of file Types.h.

652  {
653  return Float2(-X, -Y);
654  }
DLLEXPORT Float2() noexcept=default

◆ operator-=()

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

Definition at line 643 of file Types.h.

644  {
645  X -= other.X;
646  Y -= other.Y;
647  return *this;
648  }

◆ operator/() [1/2]

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

Definition at line 677 of file Types.h.

678  {
679  return Float2(X / val, Y / val);
680  }
DLLEXPORT Float2() noexcept=default

◆ operator/() [2/2]

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

Definition at line 705 of file Types.h.

706  {
707  return Float2(X / other.X, Y / other.Y);
708  }
DLLEXPORT Float2() noexcept=default

◆ operator/=() [1/2]

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

Definition at line 682 of file Types.h.

683  {
684  X /= val;
685  Y /= val;
686  DO_NAN_CHECK;
687  return *this;
688  }
#define DO_NAN_CHECK
Definition: Types.h:20

◆ operator/=() [2/2]

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

Definition at line 710 of file Types.h.

711  {
712  X /= other.X;
713  Y /= other.Y;
714  DO_NAN_CHECK;
715  return *this;
716  }
#define DO_NAN_CHECK
Definition: Types.h:20

◆ operator<()

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

Definition at line 720 of file Types.h.

721  {
722  return std::tie(X, Y) < std::tie(other.X, other.Y);
723  }

◆ operator<=()

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

Definition at line 725 of file Types.h.

726  {
727  return std::tie(X, Y) <= std::tie(other.X, other.Y);
728  }

◆ operator==()

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

Definition at line 740 of file Types.h.

741  {
742  return X == other.X && Y == other.Y;
743  }

◆ operator>()

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

Definition at line 730 of file Types.h.

731  {
732  return std::tie(X, Y) > std::tie(other.X, other.Y);
733  }

◆ operator>=()

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

Definition at line 735 of file Types.h.

736  {
737  return std::tie(X, Y) >= std::tie(other.X, other.Y);
738  }

◆ operator[]()

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

Definition at line 611 of file Types.h.

612  {
613  switch(nindex) {
614  case 0: return X;
615  case 1: return Y;
616  default: break;
617  }
618 
619  LEVIATHAN_ASSERT(0, "invalid [] access");
620  return X;
621  }
#define LEVIATHAN_ASSERT(x, msg)
Definition: Define.h:92

◆ SetX()

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

Definition at line 763 of file Types.h.

764  {
765  X = val;
766  DO_NAN_CHECK;
767  }
#define DO_NAN_CHECK
Definition: Types.h:20

◆ SetY()

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

Definition at line 769 of file Types.h.

770  {
771  Y = val;
772  DO_NAN_CHECK;
773  }
#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 873 of file Types.h.

◆ Y

float Leviathan::Float2::Y = 0

Definition at line 874 of file Types.h.


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