Commit ab339ad6 authored by Dennis Gläser's avatar Dennis Gläser
Browse files

[containedmagnitude] use helper structs for dimension and ctype

parent 81c25f9e
......@@ -25,6 +25,7 @@
#define FRACKIT_COMMON_EXTRACT_DIMENSION_HH
#include <utility>
#include <memory>
#include <TopoDS_Shape.hxx>
#include <TopoDS_Vertex.hxx>
......@@ -35,6 +36,8 @@
#include <TopoDS_Solid.hxx>
#include <Standard.hxx>
#include <frackit/geometry/geometry.hh>
namespace Frackit {
/*!
......@@ -109,6 +112,13 @@ struct DimensionalityTraits<TopoDS_Solid>
: public DimensionalityTraits<TopoDS_Shape>
{ static constexpr int geometryDimension() { return 3; } };
/*!
* \brief The dimension of the abstract base class is not known.
* Thus, we provoke compiler errors when this is uses.
*/
template<> struct DimensionalityTraits<Geometry> {};
template<> struct DimensionalityTraits<std::shared_ptr<Geometry>> {};
/*!
* \brief Free function to return the dimension of a geometry.
*/
......
......@@ -30,6 +30,7 @@
#include <frackit/occ/breputilities.hh>
#include <frackit/common/extractctype.hh>
#include <frackit/common/extractdimension.hh>
#include <frackit/precision/defaultepsilon.hh>
#include <frackit/geometry/geometry.hh>
......@@ -45,7 +46,8 @@ namespace Frackit {
* \note The magnitude of points is always zero independent on if they
* are contained in the geometry or not.
*/
template<class Geometry, class Domain, std::enable_if_t<Geometry::myDimension() == 0, int> = 0>
template<class Geometry, class Domain,
std::enable_if_t<DimensionalityTraits<Geometry>::geometryDimension() == 0, int> = 0>
typename CoordinateTypeTraits<Geometry>::type
computeContainedMagnitude(const Geometry& geometry,
const Domain& domain)
......@@ -56,7 +58,8 @@ computeContainedMagnitude(const Geometry& geometry,
* \brief Returns the length of the part of a one-dimensional
* geometry that is contained in a domain geometry.
*/
template<class Geometry, class Domain, std::enable_if_t<Geometry::myDimension() == 1, int> = 0>
template<class Geometry, class Domain,
std::enable_if_t<DimensionalityTraits<Geometry>::geometryDimension() == 1, int> = 0>
typename CoordinateTypeTraits<Geometry>::type
computeContainedMagnitude(const Geometry& geometry,
const Domain& domain)
......@@ -69,7 +72,7 @@ computeContainedMagnitude(const Geometry& geometry,
if (isEdges.empty())
return 0.0;
typename Geometry::ctype size = 0.0;
typename CoordinateTypeTraits<Geometry>::type size = 0.0;
for (const auto& edge : isEdges)
size += computeMagnitude(edge);
return size;
......@@ -80,7 +83,8 @@ computeContainedMagnitude(const Geometry& geometry,
* \brief Returns the surface area of the part of a two-dimensional
* geometry that is contained in a domain geometry.
*/
template<class Geometry, class Domain, std::enable_if_t<Geometry::myDimension() == 2, int> = 0>
template<class Geometry, class Domain,
std::enable_if_t<DimensionalityTraits<Geometry>::geometryDimension() == 2, int> = 0>
typename CoordinateTypeTraits<Geometry>::type
computeContainedMagnitude(const Geometry& geometry,
const Domain& domain)
......@@ -93,11 +97,18 @@ computeContainedMagnitude(const Geometry& geometry,
if (isFaces.empty())
return 0.0;
typename Geometry::ctype size = 0.0;
typename CoordinateTypeTraits<Geometry>::type size = 0.0;
for (const auto& face : isFaces)
size += computeMagnitude(face,
defaultEpsilon(domain),
OCCUtilities::point(geometry.center()));
{
// TODO: Compute center point for TopoDS_Face?
if constexpr (std::is_same_v<Geometry, TopoDS_Face>)
size += computeMagnitude(face);
else
size += computeMagnitude(face,
defaultEpsilon(domain),
OCCUtilities::point(geometry.center()));
}
return size;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment