1#ifndef OBJECTS_GEOMETRY_H
2#define OBJECTS_GEOMETRY_H
79 float obj_y)
const = 0;
93 virtual void render(SDL_Renderer* renderer, b2WorldId world_id,
float x,
float y,
float theta,
94 uint8_t r, uint8_t g, uint8_t b, uint8_t alpha = 255)
const = 0;
172 float obj_y)
const override;
186 virtual void render(SDL_Renderer* renderer, b2WorldId world_id,
float x,
float y,
float theta,
187 uint8_t r, uint8_t g, uint8_t b, uint8_t alpha = 255)
const override;
251 float obj_y)
const override;
265 virtual void render(SDL_Renderer* renderer, b2WorldId world_id,
float x,
float y,
float theta,
266 uint8_t r, uint8_t g, uint8_t b, uint8_t alpha = 255)
const override;
336 float obj_y)
const override;
341 void render(SDL_Renderer* renderer, b2WorldId world_id,
float x,
float y,
float theta,
342 uint8_t r, uint8_t g, uint8_t b, uint8_t alpha = 255)
const override;
370 std::array<b2Vec2, 3> get_local_vertices()
const;
408 float obj_y)
const override;
422 virtual void render(SDL_Renderer*, b2WorldId,
float,
float,
float, uint8_t, uint8_t, uint8_t, uint8_t = 255)
const override {}
441 virtual float get_distance_to([[maybe_unused]] b2Vec2 orig, [[maybe_unused]] b2Vec2 point)
const override {
return 0.0f; }
468 : arena_polygons_{arena_polygons} {}
472 void create_box2d_shape([[maybe_unused]] b2BodyId body_id, [[maybe_unused]] b2ShapeDef& shape_def)
override { }
474 std::vector<std::vector<bool>>
476 std::size_t num_bins_y,
480 float obj_y)
const override;
482 void render(SDL_Renderer*, b2WorldId,
float,
float,
float,
483 uint8_t, uint8_t, uint8_t, uint8_t = 255)
const override { }
513 static float distance_point_segment(b2Vec2 p, b2Vec2 a, b2Vec2 b)
noexcept;
514 static bool point_inside_polygon(b2Vec2 p,
const std::vector<b2Vec2>& poly)
noexcept;
void render(SDL_Renderer *, b2WorldId, float, float, float, uint8_t, uint8_t, uint8_t, uint8_t=255) const override
Renders the object on the given SDL renderer.
Definition objects_geometry.h:482
arena_polygons_t const & get_arena_polygons()
Definition objects_geometry.h:496
float get_distance_to(b2Vec2, b2Vec2 point) const override
Return the shortest Euclidean distance between point and all arena walls.
Definition objects_geometry.cpp:536
void create_box2d_shape(b2BodyId body_id, b2ShapeDef &shape_def) override
Create Box2D shape based on this geometry.
Definition objects_geometry.h:472
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.
Definition objects_geometry.cpp:552
BoundingBox compute_bounding_box() const override
Computes the axis-aligned bounding box that completely encloses the geometry.
Definition objects_geometry.cpp:511
ArenaGeometry(arena_polygons_t const &arena_polygons) noexcept
Ctor – keeps a ref to the polygon container that lives elsewhere.
Definition objects_geometry.h:467
BoundingDisk compute_bounding_disk() const override
Computes the bounding disk that completely encloses the geometry.
Definition objects_geometry.cpp:528
std::vector< std::vector< bool > > export_geometry_grid(std::size_t num_bins_x, std::size_t num_bins_y, float bin_width, float bin_height, float obj_x, float obj_y) const override
Definition objects_geometry.cpp:485
Class for managing hierarchical configuration parameters.
Definition configuration.h:64
virtual BoundingDisk compute_bounding_disk() const override
Computes the bounding disk that completely encloses the geometry.
Definition objects_geometry.cpp:69
float get_radius() const
Return radius of the disk.
Definition objects_geometry.h:154
DiskGeometry(float _radius)
Construct an ObjectGeometry.
Definition objects_geometry.h:144
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 geometry.
Definition objects_geometry.cpp:40
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 object on the given SDL renderer.
Definition objects_geometry.cpp:65
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.
Definition objects_geometry.cpp:80
virtual BoundingBox compute_bounding_box() const override
Computes the axis-aligned bounding box that completely encloses the geometry.
Definition objects_geometry.cpp:74
float radius
Radius of the disk.
Definition objects_geometry.h:218
virtual void create_box2d_shape(b2BodyId body_id, b2ShapeDef &shape_def) override
Create Box2D shape based on this geometry.
Definition objects_geometry.cpp:32
virtual void create_box2d_shape(b2BodyId, b2ShapeDef &) override
Create Box2D shape based on this geometry.
Definition objects_geometry.h:390
virtual float get_distance_to(b2Vec2 orig, b2Vec2 point) const override
Compute the distance from a given point to the geometry.
Definition objects_geometry.h:441
virtual BoundingDisk compute_bounding_disk() const override
Computes the bounding disk that completely encloses the geometry.
Definition objects_geometry.cpp:438
GlobalGeometry()
Construct an ObjectGeometry.
Definition objects_geometry.h:385
virtual void render(SDL_Renderer *, b2WorldId, float, float, float, uint8_t, uint8_t, uint8_t, uint8_t=255) const override
Renders the object on the given SDL renderer.
Definition objects_geometry.h:422
virtual BoundingBox compute_bounding_box() const override
Computes the axis-aligned bounding box that completely encloses the geometry.
Definition objects_geometry.cpp:442
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 geometry.
Definition objects_geometry.cpp:429
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.
Definition objects_geometry.h:455
Geometry of an object.
Definition objects_geometry.h:40
virtual BoundingDisk compute_bounding_disk() const =0
Computes the bounding disk that completely encloses the 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 =0
Exports a boolean 2D grid showing which bins are covered by the geometry.
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 =0
Renders the object on the given SDL renderer.
b2ShapeId get_shape_id() const
Return Box2D shape_id.
Definition objects_geometry.h:61
ObjectGeometry()
Construct an ObjectGeometry.
Definition objects_geometry.h:46
b2ShapeId shape_id
Box2D shape identifier.
Definition objects_geometry.h:131
virtual ~ObjectGeometry()
Destructor.
Definition objects_geometry.cpp:21
virtual float get_distance_to(b2Vec2 orig, b2Vec2 point) const
Compute the distance from a given point to the geometry.
Definition objects_geometry.cpp:26
bool shape_created
Definition objects_geometry.h:130
virtual BoundingBox compute_bounding_box() const =0
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 =0
Return one or more polygonal contours that approximate / represent this geometry.
virtual void create_box2d_shape(b2BodyId body_id, b2ShapeDef &shape_def)=0
Create Box2D shape based on this geometry.
float width
Width of the rectangle.
Definition objects_geometry.h:307
virtual BoundingBox compute_bounding_box() const override
Computes the axis-aligned bounding box that completely encloses the geometry.
Definition objects_geometry.cpp:194
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.
Definition objects_geometry.cpp:199
virtual BoundingDisk compute_bounding_disk() const override
Computes the bounding disk that completely encloses the geometry.
Definition objects_geometry.cpp:185
RectangleGeometry(float _width, float _height)
Construct a RectangleGeometry.
Definition objects_geometry.h:228
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.
Definition objects_geometry.cpp:113
float get_width() const
Returns the width of the rectangle.
Definition objects_geometry.h:271
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.
Definition objects_geometry.cpp:147
float get_height() const
Returns the height of the rectangle.
Definition objects_geometry.h:276
virtual void create_box2d_shape(b2BodyId body_id, b2ShapeDef &shape_def) override
Create a Box2D shape based on this geometry.
Definition objects_geometry.cpp:102
float height
Height of the rectangle.
Definition objects_geometry.h:308
Class representing the simulation environment.
Definition simulator.h:43
BoundingDisk compute_bounding_disk() const override
Computes the bounding disk that completely encloses the geometry.
Definition objects_geometry.cpp:364
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 triangle.
Definition objects_geometry.cpp:317
void create_box2d_shape(b2BodyId body_id, b2ShapeDef &shape_def) override
Create a Box2D shape based on this geometry.
Definition objects_geometry.cpp:258
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 triangle on the given SDL renderer.
Definition objects_geometry.cpp:345
BoundingBox compute_bounding_box() const override
Computes the axis-aligned bounding box that completely encloses the geometry.
Definition objects_geometry.cpp:369
TriangleGeometry(float _side_length)
Construct an equilateral TriangleGeometry.
Definition objects_geometry.h:321
float get_side_length() const
Returns the side length of the equilateral triangle.
Definition objects_geometry.h:347
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.
Definition objects_geometry.cpp:383
std::vector< std::vector< b2Vec2 > > arena_polygons_t
Definition geometry.h:13
ObjectGeometry * object_geometry_factory(Configuration const &config, Simulation *simulation)
Factory of ObjectGeometries.
Definition objects_geometry.cpp:611
std::unique_ptr< Simulation > simulation
Global simulation instance.
Definition simulator.cpp:74
Represents an axis-aligned bounding box with top-left corner (x, y) and dimensions width and height.
Definition objects_geometry.h:27
float x
Definition objects_geometry.h:28
float width
Definition objects_geometry.h:30
float height
Definition objects_geometry.h:31
float y
Definition objects_geometry.h:29
Represents a disk with center (x, y) and radius.
Definition objects_geometry.h:18
float center_y
Definition objects_geometry.h:20
float center_x
Definition objects_geometry.h:19
float radius
Definition objects_geometry.h:21