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 385 of file Types.h.

Constructor & Destructor Documentation

◆ Float2() [1/3]

DLLEXPORT Leviathan::Float2::Float2 ( )
inline

Definition at line 387 of file Types.h.

388  {
389  X = Y = 0;
390  };

◆ Float2() [2/3]

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

Definition at line 391 of file Types.h.

392  {
393  X = x;
394  Y = y;
395  DO_NAN_CHECK;
396  }
#define DO_NAN_CHECK
Definition: Types.h:21

◆ Float2() [3/3]

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

Definition at line 397 of file Types.h.

398  {
399  X = Y = both;
400  DO_NAN_CHECK;
401  }
#define DO_NAN_CHECK
Definition: Types.h:21

Member Function Documentation

◆ CheckForNans()

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

Definition at line 412 of file Types.h.

413  {
414  if(HasInvalidValues()) {
415  DEBUG_BREAK;
416  throw std::runtime_error("Float2 has NaNs (or infinites in it) in it!");
417  }
418  }
DLLEXPORT bool HasInvalidValues() const
Definition: Types.h:403

◆ Clamp()

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

Definition at line 549 of file Types.h.

550  {
551  const Float2 minval = this->MinElements(max);
552  return min.MaxElements(minval);
553  }
DLLEXPORT Float2()
Definition: Types.h:387
DLLEXPORT Float2 MinElements(const Float2 &other) const
Definition: Types.h:540

◆ Compare()

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

Definition at line 599 of file Types.h.

600  {
601  const Float2 difference = (*this) - other;
602  return difference.Dot(difference) < tolerance * tolerance;
603  }
DLLEXPORT Float2()
Definition: Types.h:387

◆ Dot()

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

Definition at line 557 of file Types.h.

558  {
559  return X * val.X + Y * val.Y;
560  }

◆ GetX()

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

Definition at line 510 of file Types.h.

511  {
512  return X;
513  }

◆ GetY()

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

Definition at line 514 of file Types.h.

515  {
516  return Y;
517  }

◆ HAdd()

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

Definition at line 530 of file Types.h.

531  {
532  return X + Y;
533  }

◆ HAddAbs()

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

Definition at line 535 of file Types.h.

536  {
537  return std::fabs(X) + std::fabs(Y);
538  }

◆ HasInvalidValues()

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

Definition at line 403 of file Types.h.

404  {
405  if(!std::isfinite(X) || !std::isfinite(Y)) {
406  return true;
407  }
408 
409  return false;
410  }
#define isfinite
Definition: jsoncpp.cpp:4247

◆ IsNormalized()

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

Definition at line 587 of file Types.h.

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

◆ Length()

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

Definition at line 562 of file Types.h.

563  {
564  return sqrt(X * X + Y * Y);
565  }

◆ Lerp()

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

Definition at line 594 of file Types.h.

595  {
596  return Float2((other.X - X) * f + X, (other.Y - Y) * f + Y);
597  }
DLLEXPORT Float2()
Definition: Types.h:387

◆ MaxElements()

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

Definition at line 544 of file Types.h.

545  {
546  return Float2(X > other.X ? X : other.X, Y > other.Y ? Y : other.Y);
547  }
DLLEXPORT Float2()
Definition: Types.h:387

◆ MinElements()

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

Definition at line 540 of file Types.h.

541  {
542  return Float2(X < other.X ? X : other.X, Y < other.Y ? Y : other.Y);
543  }
DLLEXPORT Float2()
Definition: Types.h:387

◆ Normalize()

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

Definition at line 567 of file Types.h.

568  {
569  const float length = Length();
570  if(length == 0)
571  return Float2(0, 0);
572  return Float2(X / length, Y / length);
573  }
DLLEXPORT Float2()
Definition: Types.h:387
DLLEXPORT float Length() const
Definition: Types.h:562

◆ NormalizeSafe()

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

Definition at line 575 of file Types.h.

576  {
577  // security //
578  LEVIATHAN_ASSERT(safer.IsNormalized(), "safer not normalized");
579  const float len = X * X + Y * Y;
580  if(len == 0) {
581  return safer;
582  }
583  const float length = sqrt(len);
584  return Float2(X / length, Y / length);
585  }
DLLEXPORT Float2()
Definition: Types.h:387
#define LEVIATHAN_ASSERT(x, msg)
Definition: Define.h:92

◆ one()

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

Definition at line 612 of file Types.h.

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

◆ operator!=()

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

Definition at line 505 of file Types.h.

506  {
507  return X != other.X && Y != other.Y;
508  };

◆ operator*() [1/2]

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

Definition at line 456 of file Types.h.

457  {
458  return Float2(X * val.X, Y * val.Y);
459  }
DLLEXPORT Float2()
Definition: Types.h:387

◆ operator*() [2/2]

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

Definition at line 461 of file Types.h.

462  {
463  return Float2(X * f, Y * f);
464  }
DLLEXPORT Float2()
Definition: Types.h:387

◆ operator*=()

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

Definition at line 466 of file Types.h.

467  {
468  X *= f;
469  Y *= f;
470  DO_NAN_CHECK;
471  return *this;
472  }
#define DO_NAN_CHECK
Definition: Types.h:21

◆ operator+()

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

Definition at line 434 of file Types.h.

435  {
436  return Float2(X + val.X, Y + val.Y);
437  }
DLLEXPORT Float2()
Definition: Types.h:387

◆ operator+=()

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

Definition at line 439 of file Types.h.

440  {
441  X += val.X;
442  Y += val.Y;
443  return this;
444  }

◆ operator-() [1/2]

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

Definition at line 446 of file Types.h.

447  {
448  return Float2(X - val.X, Y - val.Y);
449  }
DLLEXPORT Float2()
Definition: Types.h:387

◆ operator-() [2/2]

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

Definition at line 451 of file Types.h.

452  {
453  return Float2(-X, -Y);
454  }
DLLEXPORT Float2()
Definition: Types.h:387

◆ operator/() [1/2]

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

Definition at line 474 of file Types.h.

475  {
476  return Float2(X / val.X, Y / val.Y);
477  }
DLLEXPORT Float2()
Definition: Types.h:387

◆ operator/() [2/2]

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

Definition at line 479 of file Types.h.

480  {
481  return Float2(X / f, Y / f);
482  }
DLLEXPORT Float2()
Definition: Types.h:387

◆ operator<()

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

Definition at line 485 of file Types.h.

486  {
487  return X < other.X && Y < other.Y;
488  };

◆ operator<=()

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

Definition at line 489 of file Types.h.

490  {
491  return X <= other.X && Y <= other.Y;
492  };

◆ operator==()

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

Definition at line 501 of file Types.h.

502  {
503  return X == other.X && Y == other.Y;
504  };

◆ operator>()

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

Definition at line 493 of file Types.h.

494  {
495  return X > other.X && Y > other.Y;
496  };

◆ operator>=()

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

Definition at line 497 of file Types.h.

498  {
499  return X >= other.X && Y >= other.Y;
500  };

◆ operator[]()

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

Definition at line 421 of file Types.h.

422  {
423  switch(nindex) {
424  case 0: return X;
425  case 1: return Y;
426  }
427 
428  LEVIATHAN_ASSERT(0, "invalid [] access");
429  return X;
430  }
#define LEVIATHAN_ASSERT(x, msg)
Definition: Define.h:92

◆ SetX()

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

Definition at line 518 of file Types.h.

519  {
520  X = val;
521  DO_NAN_CHECK;
522  };
#define DO_NAN_CHECK
Definition: Types.h:21

◆ SetY()

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

Definition at line 523 of file Types.h.

524  {
525  Y = val;
526  DO_NAN_CHECK;
527  };
#define DO_NAN_CHECK
Definition: Types.h:21

◆ VALUE_TYPE()

Leviathan::Float2::VALUE_TYPE ( Float2  )

◆ x_asix()

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

Definition at line 618 of file Types.h.

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

◆ y_axis()

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

Definition at line 623 of file Types.h.

624  {
625  return Float2(0.f, 1.f);
626  }
DLLEXPORT Float2()
Definition: Types.h:387

◆ zero()

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

Definition at line 607 of file Types.h.

608  {
609  return Float2(0.f, 0.f);
610  }
DLLEXPORT Float2()
Definition: Types.h:387

Member Data Documentation

◆ X

float Leviathan::Float2::X

Definition at line 636 of file Types.h.

◆ Y

float Leviathan::Float2::Y

Definition at line 636 of file Types.h.


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