Class cse491::GridPosition
ClassList > cse491 > GridPosition
Represents a position within a 2D grid of cells. This class provides utilities to manage a position in 2D space. The position is stored as floating-point values (to allow for smooth motion through a grid), but is easily converted to size_t for grid-cell identification.
#include <GridPosition.hpp>
Inherits the following classes: cse491::CoreObject
Public Functions
Type | Name |
---|---|
GridPosition | Above (double dist=1.0) const Return a grid position above this one (by default, directly above) |
GridPosition | Below (double dist=1.0) const Return a grid position below this one (by default, directly below) |
size_t | CellX () const |
size_t | CellY () const |
virtual void | Deserialize_impl (std::istream &) override Override to restore the state of this object from the provided stream. |
double | Distance (GridPosition pos2) const |
GridPosition & | FromStream (std::istream & ss) |
GridPosition & | FromString (std::string in_str) |
GridPosition | GetOffset (double offset_x, double offset_y) const Return a the GridPosition at the requested offset. |
virtual std::string | GetTypeName_impl () override const Override to allow access the derived name for this type. |
double | GetX () const |
double | GetY () const |
GridPosition () = default |
|
GridPosition (double x, double y) |
|
GridPosition (const std::string & str) |
|
GridPosition (const GridPosition &) = default |
|
bool | IsInvalid () const |
bool | IsNear (GridPosition pos2, double max_dist=1.0) const |
bool | IsValid () const |
double | MDistance (GridPosition pos2) const Manhattan distance between grid positions. |
GridPosition & | MakeInvalid () Make this grid position invalid, by setting both coords to "not-a-number". |
virtual void | Serialize_impl (std::ostream &) override const Override to store the current state of this object for later extraction. |
GridPosition & | Set (double in_x, double in_y) |
GridPosition & | SetX (double in) |
GridPosition & | SetY (double in) |
GridPosition & | Shift (double shift_x, double shift_y) |
GridPosition | ToLeft (double dist=1.0) const Return a grid position to the left of this one (by default, directly left) |
GridPosition | ToRight (double dist=1.0) const Return a grid position to the right of this one (by default, directly right) |
std::string | ToString () const |
GridPosition | operator+ (GridPosition in) const Add together two grid positions and return the result. |
GridPosition & | operator+= (const GridPosition & in) |
GridPosition & | operator-= (const GridPosition & in) |
auto | operator<=> (const GridPosition &) const Enable all comparison operators (==, !=, <, <=, >, >=) |
GridPosition & | operator= (const GridPosition &) = default |
~GridPosition () = default |
Public Functions inherited from cse491::CoreObject
Type | Name |
---|---|
void | Deserialize (std::istream & is) Restore the state of this object, extracting it from the provided stream. |
bool | Deserialize (std::string filename) A version of Deserialize that accepts a filename to read this object from. |
std::string | GetTypeName () const Access the derived name for this type. |
void | Serialize (std::ostream & os) const Store the current state of this object for later extraction. |
bool | Serialize (std::string filename) const A version of Serialize that accepts a filename for saving just this object. |
auto | operator<=> (const CoreObject &) const |
virtual | ~CoreObject () |
Public Static Functions
Type | Name |
---|---|
const GridPosition & | Invalid () |
Protected Functions inherited from cse491::CoreObject
Type | Name |
---|---|
virtual void | Deserialize_impl (std::istream &) = 0 Override to restore the state of this object from the provided stream. |
bool | EndDeserialize (std::istream & is) Set up end of the deserialization for this class (does type checking) |
void | EndSerialize (std::ostream & os) const Set up end of the serialization for this class (allows checking later) |
virtual std::string | GetTypeName_impl () const = 0 Override to allow access the derived name for this type. |
virtual void | Serialize_impl (std::ostream &) const = 0 Override to store the current state of this object for later extraction. |
bool | StartDeserialize (std::istream & is) Set up beginning of the deserialization for this class (does type checking) |
void | StartSerialize (std::ostream & os) const Set up beginning of the serialization for this class (allows checking later) |
Public Functions Documentation
function Above
inline GridPosition cse491::GridPosition::Above (
double dist=1.0
) const
function Below
inline GridPosition cse491::GridPosition::Below (
double dist=1.0
) const
function CellX
inline size_t cse491::GridPosition::CellX () const
function CellY
inline size_t cse491::GridPosition::CellY () const
function Deserialize_impl
Override to restore the state of this object from the provided stream.
inline virtual void cse491::GridPosition::Deserialize_impl (
std::istream &
) override
Parameters:
input_stream
The istream with full details about this object.
Implements cse491::CoreObject::Deserialize_impl
function Distance
inline double cse491::GridPosition::Distance (
GridPosition pos2
) const
function FromStream
inline GridPosition & cse491::GridPosition::FromStream (
std::istream & ss
)
function FromString
inline GridPosition & cse491::GridPosition::FromString (
std::string in_str
)
function GetOffset
inline GridPosition cse491::GridPosition::GetOffset (
double offset_x,
double offset_y
) const
function GetTypeName_impl
Override to allow access the derived name for this type.
inline virtual std::string cse491::GridPosition::GetTypeName_impl () override const
Returns:
A unique typename, ideally the exact name for this class (with scope) This member function will be helpful for serialization and debugging. It should return a fully scoped typename, such as "cse491::WorldGrid".
Implements cse491::CoreObject::GetTypeName_impl
function GetX
inline double cse491::GridPosition::GetX () const
function GetY
inline double cse491::GridPosition::GetY () const
function GridPosition [1/4]
cse491::GridPosition::GridPosition () = default
function GridPosition [2/4]
inline cse491::GridPosition::GridPosition (
double x,
double y
)
function GridPosition [3/4]
inline cse491::GridPosition::GridPosition (
const std::string & str
)
function GridPosition [4/4]
cse491::GridPosition::GridPosition (
const GridPosition &
) = default
function IsInvalid
inline bool cse491::GridPosition::IsInvalid () const
function IsNear
inline bool cse491::GridPosition::IsNear (
GridPosition pos2,
double max_dist=1.0
) const
function IsValid
inline bool cse491::GridPosition::IsValid () const
function MDistance
Manhattan distance between grid positions.
inline double cse491::GridPosition::MDistance (
GridPosition pos2
) const
Parameters:
pos2
Position to compare to
Returns:
Manhattan distance
function MakeInvalid
Make this grid position invalid, by setting both coords to "not-a-number".
inline GridPosition & cse491::GridPosition::MakeInvalid ()
Returns:
This object.
function Serialize_impl
Override to store the current state of this object for later extraction.
inline virtual void cse491::GridPosition::Serialize_impl (
std::ostream &
) override const
Parameters:
output_stream
An ostream that the required information should be stored in.
Implements cse491::CoreObject::Serialize_impl
function Set
inline GridPosition & cse491::GridPosition::Set (
double in_x,
double in_y
)
function SetX
inline GridPosition & cse491::GridPosition::SetX (
double in
)
function SetY
inline GridPosition & cse491::GridPosition::SetY (
double in
)
function Shift
inline GridPosition & cse491::GridPosition::Shift (
double shift_x,
double shift_y
)
function ToLeft
inline GridPosition cse491::GridPosition::ToLeft (
double dist=1.0
) const
function ToRight
inline GridPosition cse491::GridPosition::ToRight (
double dist=1.0
) const
function ToString
inline std::string cse491::GridPosition::ToString () const
function operator+
inline GridPosition cse491::GridPosition::operator+ (
GridPosition in
) const
function operator+=
inline GridPosition & cse491::GridPosition::operator+= (
const GridPosition & in
)
function operator-=
inline GridPosition & cse491::GridPosition::operator-= (
const GridPosition & in
)
function operator<=>
auto cse491::GridPosition::operator<=> (
const GridPosition &
) const
function operator=
GridPosition & cse491::GridPosition::operator= (
const GridPosition &
) = default
function ~GridPosition
cse491::GridPosition::~GridPosition () = default
Public Static Functions Documentation
function Invalid
static inline const GridPosition & cse491::GridPosition::Invalid ()
The documentation for this class was generated from the following file source/core/GridPosition.hpp