header_utils
Loading...
Searching...
No Matches
Squares

Operations on positions in a 2D square grid. More...

Topics

 Grid
 Container for, and operations on, a 2D grid.

Concepts

concept  ghassanpl::geometry::squares::metric
 Any type that meets the criteria of a metric - specifying the adjacency/distances between squares.

Classes

struct  ghassanpl::geometry::squares::manhattan_metric
 Metric in which only neighbors are adjacent. More...
struct  ghassanpl::geometry::squares::chebyshev_metric
 Metric in which the entire surrounding is adjacent. More...
struct  ghassanpl::geometry::squares::ttile_space< I, F, METRIC >
 Combines a metric and tile size into a single type. More...

Typedefs

using ghassanpl::geometry::squares::neighbor_metric
using ghassanpl::geometry::squares::surrounding_metric
using ghassanpl::geometry::squares::chebyshev_tile_space
using ghassanpl::geometry::squares::manhattan_tile_space
using ghassanpl::geometry::squares::tile_pos
 Tile position with int values.
using ghassanpl::geometry::squares::world_pos
 World position with float values.
using ghassanpl::geometry::squares::tile_rec
 Tile rectangle with int values.
using ghassanpl::geometry::squares::world_rec
 World rectangle with float values.

Functions

template<std::integral T>
constexpr bool ghassanpl::geometry::squares::is_surrounding (glm::tvec2< T > a, glm::tvec2< T > b)
template<std::integral T>
constexpr bool ghassanpl::geometry::squares::is_neighbor (glm::tvec2< T > a, glm::tvec2< T > b)
template<std::integral T>
constexpr bool ghassanpl::geometry::squares::is_diagonal_neighbor (glm::tvec2< T > a, glm::tvec2< T > b)
template<std::integral T>
constexpr auto ghassanpl::geometry::squares::manhattan_distance (glm::tvec2< T > a, glm::tvec2< T > b)
template<std::integral T>
constexpr auto ghassanpl::geometry::squares::neighbor_distance (glm::tvec2< T > a, glm::tvec2< T > b)
template<std::integral T>
constexpr auto ghassanpl::geometry::squares::chebyshev_distance (glm::tvec2< T > a, glm::tvec2< T > b)
template<std::integral T>
constexpr auto ghassanpl::geometry::squares::surrounding_distance (glm::tvec2< T > a, glm::tvec2< T > b)
template<std::integral I, std::floating_point F>
constexpr glm::tvec2< F > ghassanpl::geometry::squares::tile_pos_to_world_pos (glm::tvec2< I > tile_pos, glm::tvec2< F > tile_size)
template<std::integral I, std::floating_point F>
constexpr glm::tvec2< F > ghassanpl::geometry::squares::tile_pos_to_world_pos (glm::tvec2< I > tile_pos, F tile_size)
template<std::integral I, std::floating_point F>
constexpr trec2< F > ghassanpl::geometry::squares::world_rect_for_tile (glm::tvec2< I > pos, glm::tvec2< F > tile_size)
template<std::integral I, std::floating_point F>
constexpr trec2< F > ghassanpl::geometry::squares::world_rect_for_tile (glm::tvec2< I > pos, F tile_size)
template<std::integral I = int, std::floating_point F>
glm::tvec2< I > ghassanpl::geometry::squares::world_pos_to_tile_pos (glm::tvec2< F > world_pos, glm::tvec2< F > tile_size)
template<std::integral I = int, std::floating_point F>
glm::tvec2< I > ghassanpl::geometry::squares::world_pos_to_tile_pos (glm::tvec2< F > world_pos, F tile_size)
template<std::integral I = int, std::floating_point F>
trec2< I > ghassanpl::geometry::squares::world_rect_to_tile_rect (trec2< F > const &world_rect, glm::tvec2< F > tile_size)
template<std::integral I = int, std::floating_point F>
trec2< I > ghassanpl::geometry::squares::world_rect_to_tile_rect (trec2< F > const &world_rect, F tile_size)
template<std::floating_point F>
glm::tvec2< F > ghassanpl::geometry::squares::snap_world_pos_to_tile_grid (glm::tvec2< F > world_pos, glm::tvec2< F > tile_size)

Detailed Description

Operations on positions in a 2D square grid.

Square positions are defined as two integers x and y, in the primary position type glm::ivec2. The distances between these positions are dependent on the metric chosen.

Definitions:

  • grid - a bounded or unbounded integer coordinate space that bijects a position in the space to an object called a square or tile
  • tile - another name for square
  • metric - the means to calculate distances between two squares
  • adjacency - in a specified metric, two squares are considered "adjacent" if the distance between their positions is 1
  • neighbor of S - a square N is considered the neighbor of square S if it shares an edge with S
  • diagonal neighbor of S - a square N is considered the diagonal neighbor of square S if it shares a vertex with S
  • square surrounding S - a square N is considered in the surrounding of square S if it shares an edge OR vertex with S
  • the surrounding of S - all squares that are considered to be surrounding S
  • tile space - a combination of a metric and a tile size; usually defined as part of a world
  • world - a set of unique squares that form a grid within a tile space, either unbounded, or bounded by a rectangle edge; the squares have integral positions, and every position within the bounds refers to a unique square, but world can have non-integral "world" positions defined on it as well
  • tile position - the integral position of a single tile in a world; every position within world bounds refers to a unique square in the world
  • tile size - a world can define the geometrical extents of a single square/tile; these can then be used to define the world positions
  • world position - the real-number, euclidean position inside a world; in general, the originating world position of a tile is given by: tile_position * tile_size

The tile space and world concepts may, in some cases, be used interchangeably, as they have similar properties in this context. In general, a world is both the container of all the squares and their data (as the grid type represents) and the set of properties (like the tile space) to operate within it.

Typedef Documentation

◆ chebyshev_tile_space

using ghassanpl::geometry::squares::chebyshev_tile_space

Definition at line 197 of file squares.h.

◆ manhattan_tile_space

using ghassanpl::geometry::squares::manhattan_tile_space

Definition at line 198 of file squares.h.

◆ neighbor_metric

using ghassanpl::geometry::squares::neighbor_metric

Definition at line 81 of file squares.h.

◆ surrounding_metric

using ghassanpl::geometry::squares::surrounding_metric

Definition at line 104 of file squares.h.

◆ tile_pos

Tile position with int values.

Definition at line 201 of file squares.h.

◆ tile_rec

Tile rectangle with int values.

Definition at line 206 of file squares.h.

◆ world_pos

World position with float values.

Definition at line 203 of file squares.h.

◆ world_rec

World rectangle with float values.

Definition at line 208 of file squares.h.

Function Documentation

◆ chebyshev_distance()

template<std::integral T>
auto ghassanpl::geometry::squares::chebyshev_distance ( glm::tvec2< T > a,
glm::tvec2< T > b )
constexpr

Definition at line 119 of file squares.h.

◆ is_diagonal_neighbor()

template<std::integral T>
bool ghassanpl::geometry::squares::is_diagonal_neighbor ( glm::tvec2< T > a,
glm::tvec2< T > b )
constexpr

Definition at line 45 of file squares.h.

◆ is_neighbor()

template<std::integral T>
bool ghassanpl::geometry::squares::is_neighbor ( glm::tvec2< T > a,
glm::tvec2< T > b )
constexpr

Definition at line 43 of file squares.h.

◆ is_surrounding()

template<std::integral T>
bool ghassanpl::geometry::squares::is_surrounding ( glm::tvec2< T > a,
glm::tvec2< T > b )
constexpr

Definition at line 41 of file squares.h.

◆ manhattan_distance()

template<std::integral T>
auto ghassanpl::geometry::squares::manhattan_distance ( glm::tvec2< T > a,
glm::tvec2< T > b )
constexpr

Definition at line 108 of file squares.h.

◆ neighbor_distance()

template<std::integral T>
auto ghassanpl::geometry::squares::neighbor_distance ( glm::tvec2< T > a,
glm::tvec2< T > b )
constexpr

Definition at line 113 of file squares.h.

◆ snap_world_pos_to_tile_grid()

template<std::floating_point F>
glm::tvec2< F > ghassanpl::geometry::squares::snap_world_pos_to_tile_grid ( glm::tvec2< F > world_pos,
glm::tvec2< F > tile_size )
inline

Definition at line 154 of file squares.h.

◆ surrounding_distance()

template<std::integral T>
auto ghassanpl::geometry::squares::surrounding_distance ( glm::tvec2< T > a,
glm::tvec2< T > b )
constexpr

Definition at line 124 of file squares.h.

◆ tile_pos_to_world_pos() [1/2]

template<std::integral I, std::floating_point F>
glm::tvec2< F > ghassanpl::geometry::squares::tile_pos_to_world_pos ( glm::tvec2< I > tile_pos,
F tile_size )
constexpr

Definition at line 133 of file squares.h.

◆ tile_pos_to_world_pos() [2/2]

template<std::integral I, std::floating_point F>
glm::tvec2< F > ghassanpl::geometry::squares::tile_pos_to_world_pos ( glm::tvec2< I > tile_pos,
glm::tvec2< F > tile_size )
constexpr

Definition at line 130 of file squares.h.

◆ world_pos_to_tile_pos() [1/2]

template<std::integral I = int, std::floating_point F>
glm::tvec2< I > ghassanpl::geometry::squares::world_pos_to_tile_pos ( glm::tvec2< F > world_pos,
F tile_size )
inline

Definition at line 145 of file squares.h.

◆ world_pos_to_tile_pos() [2/2]

template<std::integral I = int, std::floating_point F>
glm::tvec2< I > ghassanpl::geometry::squares::world_pos_to_tile_pos ( glm::tvec2< F > world_pos,
glm::tvec2< F > tile_size )
inline

Definition at line 142 of file squares.h.

◆ world_rect_for_tile() [1/2]

template<std::integral I, std::floating_point F>
trec2< F > ghassanpl::geometry::squares::world_rect_for_tile ( glm::tvec2< I > pos,
F tile_size )
constexpr

Definition at line 139 of file squares.h.

◆ world_rect_for_tile() [2/2]

template<std::integral I, std::floating_point F>
trec2< F > ghassanpl::geometry::squares::world_rect_for_tile ( glm::tvec2< I > pos,
glm::tvec2< F > tile_size )
constexpr

Definition at line 136 of file squares.h.

◆ world_rect_to_tile_rect() [1/2]

template<std::integral I = int, std::floating_point F>
trec2< I > ghassanpl::geometry::squares::world_rect_to_tile_rect ( trec2< F > const & world_rect,
F tile_size )
inline

Definition at line 151 of file squares.h.

◆ world_rect_to_tile_rect() [2/2]

template<std::integral I = int, std::floating_point F>
trec2< I > ghassanpl::geometry::squares::world_rect_to_tile_rect ( trec2< F > const & world_rect,
glm::tvec2< F > tile_size )
inline

Definition at line 148 of file squares.h.