template class EE::Math::Polygon2¶
Overview¶
Utility template class for manipulating polygons. More…
#include <polygon2.hpp> template <typename T> class Polygon2 { public: // construction Polygon2(); Polygon2(const Polygon2<T>& fromPoly); Polygon2(const Triangle2<T>& fromTrig); Polygon2(const Quad2<T>& fromQuad); Polygon2(const tRECT<T>& fromRect); Polygon2(const std::vector<Vector2<T>>& theVecs); ~Polygon2(); // methods Uint32 pushBack(const Vector2<T>& V); void popBack(); void clear(); const Vector2<T>& operator[](const Uint32& Pos) const; Vector2<T>& getAt(const Uint32& Pos); Vector2<T>& setAt(const Uint32& Pos, Vector2<T> newPos); std::size_t getSize() const; Vector2<T> getPosition() const; void move(Vector2<T> dist); void setPosition(const Vector2<T>& pos); bool intersect(const Polygon2<T>& p1); void rotate(const T& angle, const Vector2<T>& center); void scale(const T& scale, const Vector2<T>& center); void scale(const Vector2<T>& scale, const Vector2<T>& center); bool pointInside(const Vector2<T>& point); tRECT<T> getBounds(); Uint32 closestPoint(const Vector2<T>& to, T* distance = NULL); static Polygon2<T> createRoundedRectangle(const T& x, const T& y, const T& width, const T& height, const unsigned int& Radius = 8); static bool intersectQuad2(const Quad2<T>& q0, const Quad2<T>& q1, const Vector2<T>& q0Pos = Vector2<T>(0, 0), const Vector2<T>& q1Pos = Vector2<T>(0, 0)); };
Detailed Documentation¶
Utility template class for manipulating polygons.
Construction¶
Polygon2()
Default constructor. Creates an empty object.
Polygon2(const Polygon2<T>& fromPoly)
Creates a polygon from other polygon
Polygon2(const Triangle2<T>& fromTrig)
Creates a polygon from a triangle
Polygon2(const Quad2<T>& fromQuad)
Creates a polygon from a quad
Polygon2(const tRECT<T>& fromRect)
Creates a polygon from a rectangle
Polygon2(const std::vector<Vector2<T>>& theVecs)
Creates a polygon from a vector of Vector2 ( 2D vector )
Methods¶
Uint32 pushBack(const Vector2<T>& V)
Adds a new Vector2 to the polygon
void popBack()
Removes the las Vector2 from the polygon
void clear()
Clear the polygon vectors
const Vector2<T>& operator[](const Uint32& Pos) const
Returns:
The polygon Vector2 from the position ( from 0 to polygon size -1 )
Vector2<T>& getAt(const Uint32& Pos)
Returns:
The polygon Vector2 from the position ( from 0 to polygon size -1 )
Vector2<T>& setAt(const Uint32& Pos, Vector2<T> newPos)
Change the polygon vector in the position specified
Returns:
The Vector2 changed
std::size_t getSize() const
Returns:
The number of vectors of the polygon
Vector2<T> getPosition() const
Returns:
The position of the polygon ( also known as the offset of the polygon )
void move(Vector2<T> dist)
Move the polygon Vector2s, add to every point the distance specified
void setPosition(const Vector2<T>& pos)
Returns:
The position of the polygon ( the offset )
bool intersect(const Polygon2<T>& p1)
Polygon Polygon Collision ( SAT )
Returns:
True if the polygons intersect
void rotate(const T& angle, const Vector2<T>& center)
Rotates the polygon from a rotation center
void scale(const T& scale, const Vector2<T>& center)
Scale the polygon from a center point
void scale(const Vector2<T>& scale, const Vector2<T>& center)
Scale the polygon from a center point
bool pointInside(const Vector2<T>& point)
Copyright (c) 1970-2003, Wm. Randolph Franklin
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimers. Redistributions in binary form must reproduce the above copyright notice in the documentation and/or other materials provided with the distribution. The name of W. Randolph Franklin may not be used to endorse or promote products derived from this Software without specific prior written permission. THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Returns:
True if the point is inside the polygon
tRECT<T> getBounds()
Returns:
The polygon axis-aligned bounding box
Uint32 closestPoint(const Vector2<T>& to, T* distance = NULL)
Parameters:
to |
The point |
distance |
A pointer that returns the distance between the point and the closest point to the point |
Returns:
Th closest polygon point to the point (to).
static Polygon2<T> createRoundedRectangle(const T& x, const T& y, const T& width, const T& height, const unsigned int& Radius = 8)
Creates a rounded rectangle polygon
static bool intersectQuad2(const Quad2<T>& q0, const Quad2<T>& q1, const Vector2<T>& q0Pos = Vector2<T>(0, 0), const Vector2<T>& q1Pos = Vector2<T>(0, 0))
Intersect to Quads Convert the two quads in two polygons, and execute a polygon to polygon collition.
Quad Quad Collision
Parameters:
q0 |
First quad |
q1 |
Second quad |
q0Pos |
The q0 quad polygon offset |
q1Pos |
The q1 quad polygon offset |