Leviathan  0.8.0.0
Leviathan game engine
Leviathan::Float2 Struct Reference

#include <Types.h>

Public Member Functions

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

Static Public Member Functions

static DLLEXPORT Float2 zero ()
 
static DLLEXPORT Float2 one ()
 
static DLLEXPORT Float2 x_asix ()
 
static DLLEXPORT Float2 y_axis ()
 

Public Attributes

float X
 
float Y
 

Detailed Description

Definition at line 379 of file Types.h.

Constructor & Destructor Documentation

◆ Float2() [1/3]

DLLEXPORT Leviathan::Float2::Float2 ( )
inline

Definition at line 381 of file Types.h.

382  {
383  X = Y = 0;
384  };

◆ Float2() [2/3]

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

Definition at line 385 of file Types.h.

386  {
387  X = x;
388  Y = y;
389  DO_NAN_CHECK;
390  }
#define DO_NAN_CHECK
Definition: Types.h:18

◆ Float2() [3/3]

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

Definition at line 391 of file Types.h.

392  {
393  X = Y = both;
394  DO_NAN_CHECK;
395  }
#define DO_NAN_CHECK
Definition: Types.h:18

Member Function Documentation

◆ CheckForNans()

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

Definition at line 406 of file Types.h.

407  {
408  if(HasInvalidValues()) {
409  DEBUG_BREAK;
410  throw std::runtime_error("Float2 has NaNs (or infinites in it) in it!");
411  }
412  }
DLLEXPORT bool HasInvalidValues() const
Definition: Types.h:397

◆ Clamp()

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

Definition at line 543 of file Types.h.

544  {
545  const Float2 minval = this->MinElements(max);
546  return min.MaxElements(minval);
547  }
DLLEXPORT Float2()
Definition: Types.h:381
DLLEXPORT Float2 MinElements(const Float2 &other) const
Definition: Types.h:534

◆ Compare()

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

Definition at line 593 of file Types.h.

594  {
595  const Float2 difference = (*this) - other;
596  return difference.Dot(difference) < tolerance * tolerance;
597  }
DLLEXPORT Float2()
Definition: Types.h:381

◆ Dot()

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

Definition at line 551 of file Types.h.

552  {
553  return X * val.X + Y * val.Y;
554  }

◆ GetX()

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

Definition at line 504 of file Types.h.

505  {
506  return X;
507  }

◆ GetY()

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

Definition at line 508 of file Types.h.

509  {
510  return Y;
511  }

◆ HAdd()

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

Definition at line 524 of file Types.h.

525  {
526  return X + Y;
527  }

◆ HAddAbs()

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

Definition at line 529 of file Types.h.

530  {
531  return std::fabs(X) + std::fabs(Y);
532  }

◆ HasInvalidValues()

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

Definition at line 397 of file Types.h.

398  {
399  if(!std::isfinite(X) || !std::isfinite(Y)) {
400  return true;
401  }
402 
403  return false;
404  }
#define isfinite
Definition: jsoncpp.cpp:4247

◆ IsNormalized()

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

Definition at line 581 of file Types.h.

582  {
583  // is absolute -1.f under normalization tolerance //
584  return fabs(X * X + Y * Y - 1.0f) < NORMALIZATION_TOLERANCE;
585  }
constexpr float NORMALIZATION_TOLERANCE
For checking vector normalization.
Definition: Define.h:43

◆ Length()

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

Definition at line 556 of file Types.h.

557  {
558  return sqrt(X * X + Y * Y);
559  }

◆ Lerp()

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

Definition at line 588 of file Types.h.

589  {
590  return Float2((other.X - X) * f + X, (other.Y - Y) * f + Y);
591  }
DLLEXPORT Float2()
Definition: Types.h:381

◆ MaxElements()

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

Definition at line 538 of file Types.h.

539  {
540  return Float2(X > other.X ? X : other.X, Y > other.Y ? Y : other.Y);
541  }
DLLEXPORT Float2()
Definition: Types.h:381

◆ MinElements()

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

Definition at line 534 of file Types.h.

535  {
536  return Float2(X < other.X ? X : other.X, Y < other.Y ? Y : other.Y);
537  }
DLLEXPORT Float2()
Definition: Types.h:381

◆ Normalize()

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

Definition at line 561 of file Types.h.

562  {
563  const float length = Length();
564  if(length == 0)
565  return Float2(0, 0);
566  return Float2(X / length, Y / length);
567  }
DLLEXPORT Float2()
Definition: Types.h:381
DLLEXPORT float Length() const
Definition: Types.h:556

◆ NormalizeSafe()

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

Definition at line 569 of file Types.h.

570  {
571  // security //
572  LEVIATHAN_ASSERT(safer.IsNormalized(), "safer not normalized");
573  const float len = X * X + Y * Y;
574  if(len == 0) {
575  return safer;
576  }
577  const float length = sqrt(len);
578  return Float2(X / length, Y / length);
579  }
DLLEXPORT Float2()
Definition: Types.h:381

◆ one()

static DLLEXPORT Float2 Leviathan::Float2::one ( )
inlinestatic

Definition at line 606 of file Types.h.

607  {
608  return Float2(1.f, 1.f);
609  }
DLLEXPORT Float2()
Definition: Types.h:381

◆ operator!=()

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

Definition at line 499 of file Types.h.

500  {
501  return X != other.X && Y != other.Y;
502  };

◆ operator*() [1/2]

DLLEXPORT Float2 Leviathan::Float2::operator* ( const Float2 val) const
inline

Definition at line 450 of file Types.h.

451  {
452  return Float2(X * val.X, Y * val.Y);
453  }
DLLEXPORT Float2()
Definition: Types.h:381

◆ operator*() [2/2]

DLLEXPORT Float2 Leviathan::Float2::operator* ( float  f) const
inline

Definition at line 455 of file Types.h.

456  {
457  return Float2(X * f, Y * f);
458  }
DLLEXPORT Float2()
Definition: Types.h:381

◆ operator*=()

DLLEXPORT Float2& Leviathan::Float2::operator*= ( float  f)
inline

Definition at line 460 of file Types.h.

461  {
462  X *= f;
463  Y *= f;
464  DO_NAN_CHECK;
465  return *this;
466  }
#define DO_NAN_CHECK
Definition: Types.h:18

◆ operator+()

DLLEXPORT Float2 Leviathan::Float2::operator+ ( const Float2 val) const
inline

Definition at line 428 of file Types.h.

429  {
430  return Float2(X + val.X, Y + val.Y);
431  }
DLLEXPORT Float2()
Definition: Types.h:381

◆ operator+=()

DLLEXPORT Float2* Leviathan::Float2::operator+= ( const Float2 val)
inline

Definition at line 433 of file Types.h.

434  {
435  X += val.X;
436  Y += val.Y;
437  return this;
438  }

◆ operator-() [1/2]

DLLEXPORT Float2 Leviathan::Float2::operator- ( const Float2 val) const
inline

Definition at line 440 of file Types.h.

441  {
442  return Float2(X - val.X, Y - val.Y);
443  }
DLLEXPORT Float2()
Definition: Types.h:381

◆ operator-() [2/2]

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

Definition at line 445 of file Types.h.

446  {
447  return Float2(-X, -Y);
448  }
DLLEXPORT Float2()
Definition: Types.h:381

◆ operator/() [1/2]

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

Definition at line 468 of file Types.h.

469  {
470  return Float2(X / val.X, Y / val.Y);
471  }
DLLEXPORT Float2()
Definition: Types.h:381

◆ operator/() [2/2]

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

Definition at line 473 of file Types.h.

474  {
475  return Float2(X / f, Y / f);
476  }
DLLEXPORT Float2()
Definition: Types.h:381

◆ operator<()

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

Definition at line 479 of file Types.h.

480  {
481  return X < other.X && Y < other.Y;
482  };

◆ operator<=()

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

Definition at line 483 of file Types.h.

484  {
485  return X <= other.X && Y <= other.Y;
486  };

◆ operator==()

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

Definition at line 495 of file Types.h.

496  {
497  return X == other.X && Y == other.Y;
498  };

◆ operator>()

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

Definition at line 487 of file Types.h.

488  {
489  return X > other.X && Y > other.Y;
490  };

◆ operator>=()

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

Definition at line 491 of file Types.h.

492  {
493  return X >= other.X && Y >= other.Y;
494  };

◆ operator[]()

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

Definition at line 415 of file Types.h.

416  {
417  switch(nindex) {
418  case 0: return X;
419  case 1: return Y;
420  }
421 
422  LEVIATHAN_ASSERT(0, "invalid [] access");
423  return X;
424  }

◆ SetX()

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

Definition at line 512 of file Types.h.

513  {
514  X = val;
515  DO_NAN_CHECK;
516  };
#define DO_NAN_CHECK
Definition: Types.h:18

◆ SetY()

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

Definition at line 517 of file Types.h.

518  {
519  Y = val;
520  DO_NAN_CHECK;
521  };
#define DO_NAN_CHECK
Definition: Types.h:18

◆ VALUE_TYPE()

Leviathan::Float2::VALUE_TYPE ( Float2  )

◆ x_asix()

static DLLEXPORT Float2 Leviathan::Float2::x_asix ( )
inlinestatic

Definition at line 612 of file Types.h.

613  {
614  return Float2(1.f, 0.f);
615  }
DLLEXPORT Float2()
Definition: Types.h:381

◆ y_axis()

static DLLEXPORT Float2 Leviathan::Float2::y_axis ( )
inlinestatic

Definition at line 617 of file Types.h.

618  {
619  return Float2(0.f, 1.f);
620  }
DLLEXPORT Float2()
Definition: Types.h:381

◆ zero()

static DLLEXPORT Float2 Leviathan::Float2::zero ( )
inlinestatic

Definition at line 601 of file Types.h.

602  {
603  return Float2(0.f, 0.f);
604  }
DLLEXPORT Float2()
Definition: Types.h:381

Member Data Documentation

◆ X

float Leviathan::Float2::X

Definition at line 630 of file Types.h.

◆ Y

float Leviathan::Float2::Y

Definition at line 630 of file Types.h.


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