Skip to content

Merge Rect and Rectf classes. #3236

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions src/badguy/crusher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,34 +426,34 @@ Crusher::spawn_roots(Direction direction)
vertical = true;
origin.x = m_col.m_bbox.get_middle().x - 16.f;
origin.y = m_col.m_bbox.get_bottom();
test_empty_offset = Rectf(Vector(4, -4), Size(16, 1));
test_solid_offset_1 = Rectf(Vector(6, 8), Size(1, 1));
test_solid_offset_2 = Rectf(Vector(16, 8), Size(1, 1));
test_empty_offset = Rectf(Vector(4, -4), Sizef(16, 1));
test_solid_offset_1 = Rectf(Vector(6, 8), Sizef(1, 1));
test_solid_offset_2 = Rectf(Vector(16, 8), Sizef(1, 1));
break;

case Direction::UP:
vertical = true;
origin.x = m_col.m_bbox.get_middle().x - 16.f;
origin.y = m_col.m_bbox.get_top() - 6.f;
test_empty_offset = Rectf(Vector(4, 4), Size(16, 1));
test_solid_offset_1 = Rectf(Vector(6, -8), Size(1, 1));
test_solid_offset_2 = Rectf(Vector(16, -8), Size(1, 1));
test_empty_offset = Rectf(Vector(4, 4), Sizef(16, 1));
test_solid_offset_1 = Rectf(Vector(6, -8), Sizef(1, 1));
test_solid_offset_2 = Rectf(Vector(16, -8), Sizef(1, 1));
break;

case Direction::LEFT:
origin.x = m_col.m_bbox.get_left() - 6.f;
origin.y = m_col.m_bbox.get_middle().y - 16.f;
test_empty_offset = Rectf(Vector(8, 0), Size(1, 16));
test_solid_offset_1 = Rectf(Vector(0, 4), Size(1, 1));
test_solid_offset_2 = Rectf(Vector(0, 12), Size(1, 1));
test_empty_offset = Rectf(Vector(8, 0), Sizef(1, 16));
test_solid_offset_1 = Rectf(Vector(0, 4), Sizef(1, 1));
test_solid_offset_2 = Rectf(Vector(0, 12), Sizef(1, 1));
break;

case Direction::RIGHT:
origin.x = m_col.m_bbox.get_right() + 12.f;
origin.y = m_col.m_bbox.get_middle().y - 16.f;
test_empty_offset = Rectf(Vector(-16, 0), Size(1, 16));
test_solid_offset_1 = Rectf(Vector(0, 4), Size(1, 1));
test_solid_offset_2 = Rectf(Vector(0, 12), Size(1, 1));
test_empty_offset = Rectf(Vector(-16, 0), Sizef(1, 16));
test_solid_offset_1 = Rectf(Vector(0, 4), Sizef(1, 1));
test_solid_offset_2 = Rectf(Vector(0, 12), Sizef(1, 1));
break;
}

Expand Down
6 changes: 2 additions & 4 deletions src/badguy/root_sapling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,10 +277,8 @@ RootSapling::should_summon_root(const Rectf& bbox)
// Test with all tiles in the root's hitbox
const Rect test_tiles = solids->get_tiles_overlapping(bbox);

for (int x = test_tiles.left; x < test_tiles.right; ++x)
{
for (int y = test_tiles.top; y < test_tiles.bottom; ++y)
{
for (int x = test_tiles.get_left(); x < test_tiles.get_right(); ++x) {
for (int y = test_tiles.get_top(); y < test_tiles.get_bottom(); ++y) {
const Tile& tile = solids->get_tile(x, y);

if (!(tile.get_attributes() & Tile::SOLID))
Expand Down
2 changes: 1 addition & 1 deletion src/collision/collision.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <algorithm>

#include "math/aatriangle.hpp"
#include "math/rectf.hpp"
#include "math/rect.hpp"

namespace collision {

Expand Down
1 change: 0 additions & 1 deletion src/collision/collision.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include "collision/collision_hit.hpp"
#include "math/fwd.hpp"

class Rectf;
class AATriangle;

namespace collision {
Expand Down
2 changes: 1 addition & 1 deletion src/collision/collision_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

#include "collision/collision_group.hpp"
#include "collision/collision_hit.hpp"
#include "math/rectf.hpp"
#include "math/rect.hpp"

class CollisionGroundMovementManager;
class MovingObject;
Expand Down
16 changes: 7 additions & 9 deletions src/collision/collision_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,8 @@ CollisionSystem::collision_tilemap(collision::Constraints* constraints,

bool hits_bottom = false;

for (int x = test_tiles.left; x < test_tiles.right; ++x)
{
for (int y = test_tiles.top; y < test_tiles.bottom; ++y)
{
for (int x = test_tiles.get_left(); x < test_tiles.get_right(); ++x) {
for (int y = test_tiles.get_top(); y < test_tiles.get_bottom(); ++y) {
const Tile& tile = solids->get_tile(x, y);

// Skip non-solid tiles.
Expand Down Expand Up @@ -306,16 +304,16 @@ CollisionSystem::collision_tile_attributes(const Rectf& dest, const Vector& mov)
// For ice (only), add a little fudge to recognize tiles Tux is standing on.
const Rect test_tiles_ice = solids->get_tiles_overlapping(Rectf(x1, y1, x2, y2 + SHIFT_DELTA));

for (int x = test_tiles.left; x < test_tiles.right; ++x) {
for (int x = test_tiles.get_left(); x < test_tiles.get_right(); ++x) {
int y;
for (y = test_tiles.top; y < test_tiles.bottom; ++y) {
for (y = test_tiles.get_top(); y < test_tiles.get_bottom(); ++y) {
const Tile& tile = solids->get_tile(x, y);

if ( tile.is_collisionful( solids->get_tile_bbox(x, y), dest, mov) ) {
result |= tile.get_attributes();
}
}
for (; y < test_tiles_ice.bottom; ++y) {
for (; y < test_tiles_ice.get_bottom(); ++y) {
const Tile& tile = solids->get_tile(x, y);
if ( tile.is_collisionful( solids->get_tile_bbox(x, y), dest, mov) ) {
result |= (tile.get_attributes() & Tile::ICE);
Expand Down Expand Up @@ -682,8 +680,8 @@ CollisionSystem::is_free_of_tiles(const Rectf& rect, const bool ignoreUnisolid,
// Test with all tiles in this rectangle.
const Rect test_tiles = solids->get_tiles_overlapping(rect);

for (int x = test_tiles.left; x < test_tiles.right; ++x) {
for (int y = test_tiles.top; y < test_tiles.bottom; ++y) {
for (int x = test_tiles.get_left(); x < test_tiles.get_right(); ++x) {
for (int y = test_tiles.get_top(); y < test_tiles.get_bottom(); ++y) {
const Tile& tile = solids->get_tile(x, y);

if (!(tile.get_attributes() & tiletype))
Expand Down
1 change: 0 additions & 1 deletion src/collision/collision_system.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
class CollisionObject;
class CollisionGroundMovementManager;
class DrawingContext;
class Rectf;
class Sector;

class CollisionSystem final
Expand Down
3 changes: 1 addition & 2 deletions src/control/mobile_controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@

#include "config.h"


#include "math/rectf.hpp"
#include "math/rect.hpp"
#include "math/vector.hpp"
#include "video/surface_ptr.hpp"

Expand Down
2 changes: 1 addition & 1 deletion src/editor/button_widget.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

#include <functional>

#include "math/rectf.hpp"
#include "math/rect.hpp"
#include "sprite/sprite.hpp"
#include "sprite/sprite_manager.hpp"

Expand Down
4 changes: 2 additions & 2 deletions src/editor/object_icon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@

#include "editor/object_icon.hpp"

#include "math/rectf.hpp"
#include "math/rect.hpp"
#include "util/reader_mapping.hpp"
#include "video/surface.hpp"
#include "video/drawing_context.hpp"
#include "video/surface.hpp"

ObjectIcon::ObjectIcon(const std::string& object_class, const std::string& icon) :
m_object_class(object_class),
Expand Down
1 change: 0 additions & 1 deletion src/editor/overlay_widget.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ class GameObject;
class MovingObject;
class NodeMarker;
class Path;
class Rectf;
class Tip;

/** A widget that is drawn on top of the current sector and handles
Expand Down
6 changes: 4 additions & 2 deletions src/editor/particle_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -662,8 +662,10 @@ ParticleEditor::draw(Compositor& compositor)

if (m_in_texture_tab)
{
context.color().draw_surface_scaled((m_particles->m_textures.begin() + m_texture_current)->texture,
Rect(75, 200, 275, 400), LAYER_GUI);
context.color()
.draw_surface_scaled((m_particles->m_textures.begin() + m_texture_current)->texture,
Rectf(75, 200, 275, 400),
LAYER_GUI);
context.color().draw_text(Resources::control_font,
std::to_string(m_texture_current + 1) + "/"
+ std::to_string(m_particles->m_textures.size()),
Expand Down
3 changes: 1 addition & 2 deletions src/editor/tilebox.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,13 @@

#include "editor/tip.hpp"
#include "interface/control_scrollbar.hpp"
#include "math/rectf.hpp"
#include "math/rect.hpp"
#include "math/vector.hpp"
#include "supertux/tile_set.hpp"

class Editor;
class ObjectGroup;
class ObjectInfo;
class Rectf;
class TileSelection;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/editor/toolbox_widget.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#include <memory>

#include "math/rectf.hpp"
#include "math/rect.hpp"
#include "math/vector.hpp"
#include "video/surface_ptr.hpp"

Expand Down
2 changes: 1 addition & 1 deletion src/gui/dialog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include <vector>

#include "gui/menu_manager.hpp"
#include "math/sizef.hpp"
#include "math/size.hpp"
#include "util/gettext.hpp"

class Controller;
Expand Down
2 changes: 1 addition & 1 deletion src/gui/item_horizontalmenu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

#include <vector>

#include "math/rectf.hpp"
#include "math/rect.hpp"
#include "video/surface_ptr.hpp"

class DrawingContext;
Expand Down
2 changes: 1 addition & 1 deletion src/gui/menu_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include "control/controller.hpp"
#include "gui/menu_action.hpp"
#include "gui/menu_transition.hpp"
#include "math/rectf.hpp"
#include "math/rect.hpp"

class Controller;
class Dialog;
Expand Down
2 changes: 1 addition & 1 deletion src/gui/menu_transition.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#ifndef HEADER_SUPERTUX_GUI_MENU_TRANSITION_HPP
#define HEADER_SUPERTUX_GUI_MENU_TRANSITION_HPP

#include "math/rectf.hpp"
#include "math/rect.hpp"

class DrawingContext;

Expand Down
2 changes: 1 addition & 1 deletion src/gui/notification.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include <string>

#include "control/controller.hpp"
#include "math/sizef.hpp"
#include "math/size.hpp"
#include "video/drawing_context.hpp"

class Notification
Expand Down
2 changes: 1 addition & 1 deletion src/interface/container.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include <SDL.h>

#include "interface/control.hpp"
#include "math/rectf.hpp"
#include "math/rect.hpp"
#include "video/drawing_context.hpp"

/** Class that's designed to contain other controls */
Expand Down
2 changes: 1 addition & 1 deletion src/interface/control_scrollbar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

#include "editor/widget.hpp"

#include "math/rectf.hpp"
#include "math/rect.hpp"
#include "math/vector.hpp"

/** A scrollbar, which manages a scroll progress variable. */
Expand Down
2 changes: 1 addition & 1 deletion src/interface/control_textbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include <SDL.h>

#include "math/vector.hpp"
#include "math/rectf.hpp"
#include "math/rect.hpp"
#include "supertux/resources.hpp"
#include "util/log.hpp"
#include "video/video_system.hpp"
Expand Down
2 changes: 1 addition & 1 deletion src/math/aatriangle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#ifndef HEADER_SUPERTUX_MATH_AATRIANGLE_HPP
#define HEADER_SUPERTUX_MATH_AATRIANGLE_HPP

#include "math/rectf.hpp"
#include "math/rect.hpp"

/**
* An axis-aligned triangle (ie. a triangle where 2 sides are parallel to the x-
Expand Down
2 changes: 1 addition & 1 deletion src/math/anchor_point.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include <stdexcept>
#include <sstream>

#include "math/rectf.hpp"
#include "math/rect.hpp"
#include "util/log.hpp"
#include "util/gettext.hpp"

Expand Down
4 changes: 3 additions & 1 deletion src/math/anchor_point.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@

#include "math/vector.hpp"

class Rectf;
template<typename T>
class Rect_t;
using Rectf = Rect_t<float>;

#ifdef DOXYGEN_SCRIPTING
/**
Expand Down
18 changes: 17 additions & 1 deletion src/math/fwd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,23 @@

#include <glm/fwd.hpp>

using Vector = glm::vec2;
template<typename T>
using Vector_t = glm::vec<2, T, glm::qualifier::defaultp>;

using Vector = Vector_t<float>;
using Vectori = Vector_t<int>;

template<typename T>
class Rect_t;

using Rect = Rect_t<int>;
using Rectf = Rect_t<float>;

template<typename T>
class Size_t;

using Size = Size_t<int>;
using Sizef = Size_t<float>;

#endif

Expand Down
38 changes: 19 additions & 19 deletions src/math/rect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,34 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

#include "math/rect.hpp"
#include "rect.hpp"

#include <ostream>

#include "math/rectf.hpp"

Rect::Rect(const Rectf& other) :
left(static_cast<int>(other.get_left())),
top(static_cast<int>(other.get_top())),
right(static_cast<int>(other.get_right())),
bottom(static_cast<int>(other.get_bottom()))
template<>
Rect::SDL_Rect_Wrapper Rect::to_sdl() const
{
SDL_Rect_Wrapper wrapper;
wrapper.rect_i = {m_pos.x, m_pos.y, m_size.width, m_size.height};
return wrapper;
}

Rectf
Rect::to_rectf() const
template<>
Rectf::SDL_Rect_Wrapper Rectf::to_sdl() const
{
return { static_cast<float>(left), static_cast<float>(top),
static_cast<float>(right), static_cast<float>(bottom) };
SDL_Rect_Wrapper wrapper;
wrapper.rect_f = {m_pos.x, m_pos.y, m_size.width, m_size.height};
return wrapper;
}

std::ostream& operator<<(std::ostream& out, const Rect& rect)
{
out << "Rect("
<< rect.left << ", " << rect.top << ", "
<< rect.right << ", " << rect.bottom
<< ")";
out << "Rect(" << rect.get_left() << ", " << rect.get_top() << ", " << rect.get_right() << ", "
<< rect.get_bottom() << ")";
return out;
}

/* EOF */
std::ostream& operator<<(std::ostream& out, const Rectf& rect)
{
out << "Rectf(" << rect.get_left() << ", " << rect.get_top() << ", " << rect.get_right() << ", "
<< rect.get_bottom() << ")";
return out;
}
Loading
Loading