Add GLM_GTX_area extension

- Includes a function for the area of a triangle
This commit is contained in:
Jesse Talavera-Greenberg 2015-09-28 18:51:12 -04:00
parent 062e1238fa
commit 794de6b651
2 changed files with 110 additions and 0 deletions

65
glm/gtx/area.hpp Normal file
View File

@ -0,0 +1,65 @@
///////////////////////////////////////////////////////////////////////////////////
/// OpenGL Mathematics (glm.g-truc.net)
///
/// Copyright (c) 2015 G-Truc Creation (www.g-truc.net)
/// 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:
///
/// The above copyright notice and this permission notice shall be included in
/// all copies or substantial portions of the Software.
///
/// Restrictions:
/// By making use of the Software for military purposes, you choose to make
/// a Bunny unhappy.
///
/// 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.
///
/// @ref gtx_area
/// @file glm/gtx/area.hpp
/// @date 2015-09-27
/// @author Jesse Talavera-Greenberg
///
/// @see core (dependence)
///
/// @defgroup gtx_area GLM_GTX_area
/// @ingroup gtx
///
/// @brief Functions to compute the area of polygons and other common structures.
/// <glm/gtx/area.hpp> need to be included to use these functionalities.
///////////////////////////////////////////////////////////////////////////////////
#pragma once
// Dependency:
#include <cmath>
#include "../glm.hpp"
#include "../vec2.hpp"
#if(defined(GLM_MESSAGES) && !defined(GLM_EXT_INCLUDED))
# pragma message("GLM: GLM_GTX_area extension included")
#endif
namespace glm
{
/// @addtogroup gtx_area
/// @{
//! Returns the area of the triangle made by the three given vertices.
template<typename T, precision P = defaultp, typename areaType = float>
GLM_FUNC_DECL areaType area(const tvec2<T, P>& a, const tvec2<T, P>& b, const tvec2<T, P>& c);
/// @}
} //namespace glm
#include "area.inl"

45
glm/gtx/area.inl Normal file
View File

@ -0,0 +1,45 @@
///////////////////////////////////////////////////////////////////////////////////
/// OpenGL Mathematics (glm.g-truc.net)
///
/// Copyright (c) 2015 G-Truc Creation (www.g-truc.net)
/// 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:
///
/// The above copyright notice and this permission notice shall be included in
/// all copies or substantial portions of the Software.
///
/// Restrictions:
/// By making use of the Software for military purposes, you choose to make
/// a Bunny unhappy.
///
/// 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.
///
/// @ref gtx_area
/// @file glm/gtx/area.inl
/// @date 2015-09-27
/// @author Jesse Talavera-Greenberg
///////////////////////////////////////////////////////////////////////////////////
namespace glm {
namespace detail {
template<typename T, precision P = defaultp, typename areaType = float>
GLM_FUNC_QUALIFIER areaType area2(const tvec2<T, P>& a, const tvec2<T, P>& b, const tvec2<T, P>& c) {
return (b.x - a.x) * (c.y - a.y) - (c.x - a.x) * (b.y - a.y);
}
}
template<typename T, precision P, typename areaType>
GLM_FUNC_QUALIFIER areaType area(const tvec2<T, P>& a, const tvec2<T, P>& b, const tvec2<T, P>& c) {
return detail::area2(a, b, c) / static_cast<areaType>(2.0);
}
}//namespace glm