diff --git a/src/modules/graphics/Geometry.cpp b/src/modules/graphics/Geometry.cpp index bf69c0505..8c5bf65ce 100644 --- a/src/modules/graphics/Geometry.cpp +++ b/src/modules/graphics/Geometry.cpp @@ -40,13 +40,12 @@ Geometry::Geometry(const std::vector &polygon, const std::vector , vertexCount(polygon.size()) , elementArray(NULL) , elementCount(elements.size()) - , x_min(std::numeric_limits::max()) - , x_max(std::numeric_limits::min()) - , y_min(std::numeric_limits::max()) - , y_max(std::numeric_limits::min()) , vertexColors(false) , drawMode(mode) { + if (polygon.size() < 3) + throw love::Exception("At least 3 vertices are needed to create a Geometry."); + for (size_t i = 0; i < elementCount; i++) { // All values in the element array need to be a valid vertex index. @@ -55,15 +54,7 @@ Geometry::Geometry(const std::vector &polygon, const std::vector } vertexArray = new vertex[vertexCount]; - for (size_t i = 0; i < vertexCount; ++i) - { - const vertex &v = polygon[i]; - vertexArray[i] = v; - x_min = v.x < x_min ? v.x : x_min; - x_max = v.x > x_max ? v.x : x_max; - y_min = v.y < y_min ? v.y : y_min; - y_max = v.y > y_max ? v.y : y_max; - } + memcpy(vertexArray, &polygon[0], vertexCount * sizeof(vertex)); if (elementCount > 0) { @@ -77,10 +68,6 @@ Geometry::Geometry(float x, float y, float w, float h, float sw, float sh) , vertexCount(4) , elementArray(NULL) , elementCount(0) - , x_min(0) - , x_max(w) - , y_min(0) - , y_max(h) , vertexColors(false) , drawMode(DRAW_MODE_FAN) { @@ -95,10 +82,6 @@ Geometry::Geometry(float x, float y, float w, float h, float sw, float sh) Geometry::Geometry(const Geometry &other) : vertexCount(other.vertexCount) , elementCount(other.elementCount) - , x_min(other.x_min) - , x_max(other.x_max) - , y_min(other.y_min) - , y_max(other.y_max) , vertexColors(other.vertexColors) , drawMode(other.drawMode) { @@ -122,14 +105,11 @@ Geometry &Geometry::operator=(const Geometry &other) vertexCount = temp.vertexCount; elementCount = temp.elementCount; - x_min = temp.x_min; - x_max = temp.x_max; - y_min = temp.y_min; - y_max = temp.y_max; vertexColors = other.vertexColors; drawMode = other.drawMode; } + return *this; } @@ -143,6 +123,7 @@ const vertex &Geometry::getVertex(size_t i) const { if (i >= vertexCount) throw Exception("Invalid vertex index"); + return vertexArray[i]; } @@ -151,26 +132,9 @@ void Geometry::setVertex(size_t i, const vertex &v) if (i >= vertexCount) throw Exception("Invalid vertex index"); - if (vertexArray[i].x != v.x || vertexArray[i].y != v.y) - { - x_min = v.x < x_min ? v.x : x_min; - x_max = v.x > x_max ? v.x : x_max; - y_min = v.y < y_min ? v.y : y_min; - y_max = v.y > y_max ? v.y : y_max; - } - vertexArray[i] = v; } -void Geometry::flip(bool x, bool y) -{ - for (size_t i = 0; i < vertexCount; ++i) - { - vertex &v = vertexArray[i]; - if (x) v.x = x_max + x_min - v.x; - if (y) v.y = y_max + y_min - v.y; - } -} void Geometry::setElementArray(const uint16 *elements, size_t count) { diff --git a/src/modules/graphics/Geometry.h b/src/modules/graphics/Geometry.h index 94b227529..6c6cabf53 100644 --- a/src/modules/graphics/Geometry.h +++ b/src/modules/graphics/Geometry.h @@ -72,8 +72,6 @@ public: const vertex &getVertex(size_t i) const; void setVertex(size_t i, const vertex &v); - void flip(bool x, bool y); - /** * Returns a pointer to the vertex array. **/ @@ -134,12 +132,6 @@ private: uint16 *elementArray; size_t elementCount; - float x_min; - float x_max; - - float y_min; - float y_max; - bool vertexColors; DrawMode drawMode; diff --git a/src/modules/graphics/opengl/wrap_Geometry.cpp b/src/modules/graphics/opengl/wrap_Geometry.cpp index 1f362ba13..a92ebeaf8 100644 --- a/src/modules/graphics/opengl/wrap_Geometry.cpp +++ b/src/modules/graphics/opengl/wrap_Geometry.cpp @@ -115,13 +115,6 @@ int w_Geometry_setVertex(lua_State *L) return 0; } -int w_Geometry_flip(lua_State *L) -{ - Geometry *geom = luax_checkgeometry(L, 1); - geom->flip(luax_toboolean(L, 2), luax_toboolean(L, 3)); - return 0; -} - int w_Geometry_setVertexColors(lua_State *L) { Geometry *geom = luax_checkgeometry(L, 1); @@ -217,7 +210,6 @@ static const luaL_Reg w_Geometry_functions[] = { "getVertexCount", w_Geometry_getVertexCount }, { "getVertex", w_Geometry_getVertex }, { "setVertex", w_Geometry_setVertex }, - { "flip", w_Geometry_flip }, { "setVertexColors", w_Geometry_setVertexColors }, { "hasVertexColors", w_Geometry_hasVertexColors }, { "getDrawMode", w_Geometry_getDrawMode }, diff --git a/src/modules/graphics/opengl/wrap_Geometry.h b/src/modules/graphics/opengl/wrap_Geometry.h index 381d4609e..b6f800e78 100644 --- a/src/modules/graphics/opengl/wrap_Geometry.h +++ b/src/modules/graphics/opengl/wrap_Geometry.h @@ -36,7 +36,6 @@ Geometry *luax_checkgeometry(lua_State *L, int idx); int w_Geometry_getVertexCount(lua_State *L); int w_Geometry_getVertex(lua_State *L); int w_Geometry_setVertex(lua_State *L); -int w_Geometry_flip(lua_State *L); int w_Geometry_setVertexColors(lua_State *L); int w_Geometry_hasVertexColors(lua_State *L); int w_Geometry_getDrawMode(lua_State *L);