.. index:: pair: class; EE::Math::Polygon2 .. _doxid-class_e_e_1_1_math_1_1_polygon2: template class EE::Math::Polygon2 ================================= .. toctree:: :hidden: Overview ~~~~~~~~ Utility template class for manipulating polygons. :ref:`More...` .. ref-code-block:: cpp :class: doxyrest-overview-code-block #include template class Polygon2 { public: // construction :ref:`Polygon2`(); :ref:`Polygon2`(const Polygon2& fromPoly); :ref:`Polygon2`(const :ref:`Triangle2`& fromTrig); :ref:`Polygon2`(const :ref:`Quad2`& fromQuad); :ref:`Polygon2`(const :ref:`tRECT`& fromRect); :ref:`Polygon2`(const std::vector<:ref:`Vector2`>& theVecs); :target:`~Polygon2`(); // methods :ref:`Uint32` :ref:`pushBack`(const :ref:`Vector2`& V); void :ref:`popBack`(); void :ref:`clear`(); const :ref:`Vector2`& :ref:`operator[]`(const :ref:`Uint32`& Pos) const; :ref:`Vector2`& :ref:`getAt`(const :ref:`Uint32`& Pos); :ref:`Vector2`& :ref:`setAt`(const :ref:`Uint32`& Pos, :ref:`Vector2` newPos); std::size_t :ref:`getSize`() const; :ref:`Vector2` :ref:`getPosition`() const; void :ref:`move`(:ref:`Vector2` dist); void :ref:`setPosition`(const :ref:`Vector2`& pos); bool :ref:`intersect`(const Polygon2& p1); void :ref:`rotate`(const T& angle, const :ref:`Vector2`& center); void :ref:`scale`(const T& scale, const :ref:`Vector2`& center); void :ref:`scale`(const :ref:`Vector2`& scale, const :ref:`Vector2`& center); bool :ref:`pointInside`(const :ref:`Vector2`& point); :ref:`tRECT` :ref:`getBounds`(); :ref:`Uint32` :ref:`closestPoint`(const :ref:`Vector2`& to, T* distance = NULL); static Polygon2 :ref:`createRoundedRectangle`(const T& x, const T& y, const T& width, const T& height, const unsigned int& Radius = 8); static bool :ref:`intersectQuad2`(const :ref:`Quad2`& q0, const :ref:`Quad2`& q1, const :ref:`Vector2`& q0Pos = :ref:`Vector2`(0, 0), const :ref:`Vector2`& q1Pos = :ref:`Vector2`(0, 0)); }; .. _details-class_e_e_1_1_math_1_1_polygon2: Detailed Documentation ~~~~~~~~~~~~~~~~~~~~~~ Utility template class for manipulating polygons. Construction ------------ .. index:: pair: function; Polygon2 .. _doxid-class_e_e_1_1_math_1_1_polygon2_1a56ea085ab994c881b5ccfd646e1911e8: .. ref-code-block:: cpp :class: doxyrest-title-code-block Polygon2() Default constructor. Creates an empty object. .. index:: pair: function; Polygon2 .. _doxid-class_e_e_1_1_math_1_1_polygon2_1a13a19e1e2ea6d72595216834a656eba2: .. ref-code-block:: cpp :class: doxyrest-title-code-block Polygon2(const Polygon2& fromPoly) Creates a polygon from other polygon .. index:: pair: function; Polygon2 .. _doxid-class_e_e_1_1_math_1_1_polygon2_1a9c6fd495c401cfdeafa80a4d8fe2d9a9: .. ref-code-block:: cpp :class: doxyrest-title-code-block Polygon2(const :ref:`Triangle2`& fromTrig) Creates a polygon from a triangle .. index:: pair: function; Polygon2 .. _doxid-class_e_e_1_1_math_1_1_polygon2_1aa815c69cd146d4db99e37c90d88d7fbc: .. ref-code-block:: cpp :class: doxyrest-title-code-block Polygon2(const :ref:`Quad2`& fromQuad) Creates a polygon from a quad .. index:: pair: function; Polygon2 .. _doxid-class_e_e_1_1_math_1_1_polygon2_1ab452c1f507aeb84261bc5bf3112050f6: .. ref-code-block:: cpp :class: doxyrest-title-code-block Polygon2(const :ref:`tRECT`& fromRect) Creates a polygon from a rectangle .. index:: pair: function; Polygon2 .. _doxid-class_e_e_1_1_math_1_1_polygon2_1a2d5745c18743bed61a5a9c459dbb8d1a: .. ref-code-block:: cpp :class: doxyrest-title-code-block Polygon2(const std::vector<:ref:`Vector2`>& theVecs) Creates a polygon from a vector of :ref:`Vector2 ` ( 2D vector ) Methods ------- .. index:: pair: function; pushBack .. _doxid-class_e_e_1_1_math_1_1_polygon2_1ab6fcde7e258b871c4fddbc95ee863ffb: .. ref-code-block:: cpp :class: doxyrest-title-code-block :ref:`Uint32` pushBack(const :ref:`Vector2`& V) Adds a new :ref:`Vector2 ` to the polygon .. index:: pair: function; popBack .. _doxid-class_e_e_1_1_math_1_1_polygon2_1a2cd7655f0f0310c11d3e12c9c13ee3bc: .. ref-code-block:: cpp :class: doxyrest-title-code-block void popBack() Removes the las :ref:`Vector2 ` from the polygon .. index:: pair: function; clear .. _doxid-class_e_e_1_1_math_1_1_polygon2_1a521fc6f242befb9293db98500e12283a: .. ref-code-block:: cpp :class: doxyrest-title-code-block void clear() Clear the polygon vectors .. index:: pair: function; operator[] .. _doxid-class_e_e_1_1_math_1_1_polygon2_1aa1f74d9537bd85a87243aef23882096c: .. ref-code-block:: cpp :class: doxyrest-title-code-block const :ref:`Vector2`& operator[](const :ref:`Uint32`& Pos) const .. rubric:: Returns: The polygon :ref:`Vector2 ` from the position ( from 0 to polygon size -1 ) .. index:: pair: function; getAt .. _doxid-class_e_e_1_1_math_1_1_polygon2_1a95c71a4ebdc7f7a14fd019bba335c06e: .. ref-code-block:: cpp :class: doxyrest-title-code-block :ref:`Vector2`& getAt(const :ref:`Uint32`& Pos) .. rubric:: Returns: The polygon :ref:`Vector2 ` from the position ( from 0 to polygon size -1 ) .. index:: pair: function; setAt .. _doxid-class_e_e_1_1_math_1_1_polygon2_1ad7f29803cec683a4ea85a393adc790cc: .. ref-code-block:: cpp :class: doxyrest-title-code-block :ref:`Vector2`& setAt(const :ref:`Uint32`& Pos, :ref:`Vector2` newPos) Change the polygon vector in the position specified .. rubric:: Returns: The :ref:`Vector2 ` changed .. index:: pair: function; getSize .. _doxid-class_e_e_1_1_math_1_1_polygon2_1a3d2568a2062af04ed38289b3b159bc44: .. ref-code-block:: cpp :class: doxyrest-title-code-block std::size_t getSize() const .. rubric:: Returns: The number of vectors of the polygon .. index:: pair: function; getPosition .. _doxid-class_e_e_1_1_math_1_1_polygon2_1af3fe15785cd3590fbce2c2f0bb6d7f02: .. ref-code-block:: cpp :class: doxyrest-title-code-block :ref:`Vector2` getPosition() const .. rubric:: Returns: The position of the polygon ( also known as the offset of the polygon ) .. index:: pair: function; move .. _doxid-class_e_e_1_1_math_1_1_polygon2_1a25dd463e4c3fd79590c9d41964e5d2cf: .. ref-code-block:: cpp :class: doxyrest-title-code-block void move(:ref:`Vector2` dist) Move the polygon Vector2s, add to every point the distance specified .. index:: pair: function; setPosition .. _doxid-class_e_e_1_1_math_1_1_polygon2_1afda4466f8a12c6a70993ad31c9fcd1c5: .. ref-code-block:: cpp :class: doxyrest-title-code-block void setPosition(const :ref:`Vector2`& pos) .. rubric:: Returns: The position of the polygon ( the offset ) .. index:: pair: function; intersect .. _doxid-class_e_e_1_1_math_1_1_polygon2_1ae77fb8a09bd196bf5dcd87eb5e987c98: .. ref-code-block:: cpp :class: doxyrest-title-code-block bool intersect(const Polygon2& p1) Polygon Polygon Collision ( SAT ) .. rubric:: Returns: True if the polygons intersect .. index:: pair: function; rotate .. _doxid-class_e_e_1_1_math_1_1_polygon2_1ac4dec37ac753e71330e3a756be9d3b70: .. ref-code-block:: cpp :class: doxyrest-title-code-block void rotate(const T& angle, const :ref:`Vector2`& center) Rotates the polygon from a rotation center .. index:: pair: function; scale .. _doxid-class_e_e_1_1_math_1_1_polygon2_1a5089c1ec9fc25c264a72b5091fd4f11c: .. ref-code-block:: cpp :class: doxyrest-title-code-block void scale(const T& scale, const :ref:`Vector2`& center) Scale the polygon from a center point .. index:: pair: function; scale .. _doxid-class_e_e_1_1_math_1_1_polygon2_1af6543de1d883552ff128a240cef56388: .. ref-code-block:: cpp :class: doxyrest-title-code-block void scale(const :ref:`Vector2`& scale, const :ref:`Vector2`& center) Scale the polygon from a center point .. index:: pair: function; pointInside .. _doxid-class_e_e_1_1_math_1_1_polygon2_1a9834b6f59a69b160ab1f99164d992c65: .. ref-code-block:: cpp :class: doxyrest-title-code-block bool pointInside(const :ref:`Vector2`& 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. .. rubric:: Returns: True if the point is inside the polygon .. index:: pair: function; getBounds .. _doxid-class_e_e_1_1_math_1_1_polygon2_1a4ebde9b72712352a6042ccb349f6d07e: .. ref-code-block:: cpp :class: doxyrest-title-code-block :ref:`tRECT` getBounds() .. rubric:: Returns: The polygon axis-aligned bounding box .. index:: pair: function; closestPoint .. _doxid-class_e_e_1_1_math_1_1_polygon2_1a73c67ef31846d7b12df9bf96e20cdde2: .. ref-code-block:: cpp :class: doxyrest-title-code-block :ref:`Uint32` closestPoint(const :ref:`Vector2`& to, T* distance = NULL) .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - to - The point * - distance - A pointer that returns the distance between the point and the closest point to the point .. rubric:: Returns: Th closest polygon point to the point (to). .. index:: pair: function; createRoundedRectangle .. _doxid-class_e_e_1_1_math_1_1_polygon2_1a24f8b71114740d7326d7fd78b02d1342: .. ref-code-block:: cpp :class: doxyrest-title-code-block static Polygon2 createRoundedRectangle(const T& x, const T& y, const T& width, const T& height, const unsigned int& Radius = 8) Creates a rounded rectangle polygon .. index:: pair: function; intersectQuad2 .. _doxid-class_e_e_1_1_math_1_1_polygon2_1ab0bae83f5cbf5c1cfdf187951166fc62: .. ref-code-block:: cpp :class: doxyrest-title-code-block static bool intersectQuad2(const :ref:`Quad2`& q0, const :ref:`Quad2`& q1, const :ref:`Vector2`& q0Pos = :ref:`Vector2`(0, 0), const :ref:`Vector2`& q1Pos = :ref:`Vector2`(0, 0)) Intersect to Quads Convert the two quads in two polygons, and execute a polygon to polygon collition. Quad Quad Collision .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - q0 - First quad * - q1 - Second quad * - q0Pos - The q0 quad polygon offset * - q1Pos - The q1 quad polygon offset