Pogosim
Loading...
Searching...
No Matches
RectangleGeometry Class Reference

#include <objects_geometry.h>

Inheritance diagram for RectangleGeometry:
ObjectGeometry

Public Member Functions

 RectangleGeometry (float _width, float _height)
 Construct a RectangleGeometry.
virtual void create_box2d_shape (b2BodyId body_id, b2ShapeDef &shape_def) override
 Create a Box2D shape based on this geometry.
virtual std::vector< std::vector< bool > > export_geometry_grid (size_t num_bins_x, size_t num_bins_y, float bin_width, float bin_height, float obj_x, float obj_y) const override
 Exports a boolean 2D grid showing which bins are covered by the rectangle.
virtual void render (SDL_Renderer *renderer, b2WorldId world_id, float x, float y, float theta, uint8_t r, uint8_t g, uint8_t b, uint8_t alpha=255) const override
 Renders the rectangle on the given SDL renderer.
float get_width () const
 Returns the width of the rectangle.
float get_height () const
 Returns the height of the rectangle.
virtual BoundingDisk compute_bounding_disk () const override
 Computes the bounding disk that completely encloses the geometry.
virtual BoundingBox compute_bounding_box () const override
 Computes the axis-aligned bounding box that completely encloses the geometry.
virtual arena_polygons_t generate_contours (std::size_t points_per_contour=0, b2Vec2 position={0.0f, 0.0f}) const override
 Return one or more polygonal contours that approximate / represent this geometry.
Public Member Functions inherited from ObjectGeometry
 ObjectGeometry ()
 Construct an ObjectGeometry.
virtual ~ObjectGeometry ()
 Destructor.
b2ShapeId get_shape_id () const
 Return Box2D shape_id.
virtual float get_distance_to (b2Vec2 orig, b2Vec2 point) const
 Compute the distance from a given point to the geometry.

Protected Attributes

float width
 Width of the rectangle.
float height
 Height of the rectangle.
Protected Attributes inherited from ObjectGeometry
bool shape_created = false
b2ShapeId shape_id
 Box2D shape identifier.

Constructor & Destructor Documentation

◆ RectangleGeometry()

RectangleGeometry::RectangleGeometry ( float _width,
float _height )
inline

Construct a RectangleGeometry.

Parameters
_widthThe width of the rectangle.
_heightThe height of the rectangle.

Member Function Documentation

◆ compute_bounding_box()

BoundingBox RectangleGeometry::compute_bounding_box ( ) const
overridevirtual

Computes the axis-aligned bounding box that completely encloses the geometry.

Returns
A BoundingBox with top-left corner (x,y) and width and height.

Implements ObjectGeometry.

◆ compute_bounding_disk()

BoundingDisk RectangleGeometry::compute_bounding_disk ( ) const
overridevirtual

Computes the bounding disk that completely encloses the geometry.

Returns
A BoundingDisk with center (x,y) and radius.

Implements ObjectGeometry.

◆ create_box2d_shape()

void RectangleGeometry::create_box2d_shape ( b2BodyId body_id,
b2ShapeDef & shape_def )
overridevirtual

Create a Box2D shape based on this geometry.

Implements ObjectGeometry.

◆ export_geometry_grid()

std::vector< std::vector< bool > > RectangleGeometry::export_geometry_grid ( size_t num_bins_x,
size_t num_bins_y,
float bin_width,
float bin_height,
float obj_x,
float obj_y ) const
overridevirtual

Exports a boolean 2D grid showing which bins are covered by the rectangle.

Parameters
num_bins_xNumber of bins along the X-axis.
num_bins_yNumber of bins along the Y-axis.
bin_widthWidth (size) of each bin.
bin_heightHeight (size) of each bin.
obj_xThe x-coordinate of the object (geometry center).
obj_yThe y-coordinate of the object (geometry center).
Returns
A 2D vector of booleans. True in a given cell indicates that the geometry covers that bin.

Implements ObjectGeometry.

◆ generate_contours()

arena_polygons_t RectangleGeometry::generate_contours ( std::size_t points_per_contour = 0,
b2Vec2 position = {0.0f, 0.0f} ) const
overridevirtual

Return one or more polygonal contours that approximate / represent this geometry.

Parameters
points_per_contourDesired number of vertices for each contour (a rectangle has one contour, a disk has one, an arena may have many – one per wall).
Returns
arena_polygons_t A vector of closed polygons (counter‑clockwise, last vertex different from the first – the caller may close the loop if needed).

Implements ObjectGeometry.

◆ get_height()

float RectangleGeometry::get_height ( ) const
inline

Returns the height of the rectangle.

◆ get_width()

float RectangleGeometry::get_width ( ) const
inline

Returns the width of the rectangle.

◆ render()

void RectangleGeometry::render ( SDL_Renderer * renderer,
b2WorldId world_id,
float x,
float y,
float theta,
uint8_t r,
uint8_t g,
uint8_t b,
uint8_t alpha = 255 ) const
overridevirtual

Renders the rectangle on the given SDL renderer.

Parameters
rendererPointer to the SDL_Renderer.
world_idThe Box2D world identifier (unused in rendering).
xX coordinate of the rectangle center.
yY coordinate of the rectangle center.
rRed color component.
gGreen color component.
bBlue color component.
alphaAlpha color component.

Implements ObjectGeometry.

Member Data Documentation

◆ height

float RectangleGeometry::height
protected

Height of the rectangle.

◆ width

float RectangleGeometry::width
protected

Width of the rectangle.


The documentation for this class was generated from the following files: