Minor changes to conversion result numbers

This commit is contained in:
Thomas Krijnen
2026-06-23 20:25:57 +02:00
parent dad4cc8a3c
commit c592018b3f
6 changed files with 76 additions and 87 deletions
-8
View File
@@ -1,8 +1,6 @@
#include "ConversionResult.h" #include "ConversionResult.h"
#include "IfcGeomRepresentation.h" #include "IfcGeomRepresentation.h"
#include <iomanip>
IfcGeom::Representation::Triangulation* IfcGeom::ConversionResultShape::Triangulate(const ifcopenshell::geometry::Settings& settings, Logger& logger) const IfcGeom::Representation::Triangulation* IfcGeom::ConversionResultShape::Triangulate(const ifcopenshell::geometry::Settings& settings, Logger& logger) const
{ {
auto t = IfcGeom::Representation::Triangulation::empty(settings); auto t = IfcGeom::Representation::Triangulation::empty(settings);
@@ -21,11 +19,5 @@ void IfcGeom::ConversionResult::prepend(ifcopenshell::geometry::taxonomy::matrix
placement_ = make<matrix4>(trsf->ccomponents() * placement_->ccomponents()); placement_ = make<matrix4>(trsf->ccomponents() * placement_->ccomponents());
} }
std::string IfcGeom::NumberNativeDouble::to_string() const {
std::stringstream ss;
ss << std::setprecision(std::numeric_limits<double>::digits10 + 1) << value();
return ss.str();
}
template struct IFC_GEOM_API IfcGeom::OpaqueCoordinate<3>; template struct IFC_GEOM_API IfcGeom::OpaqueCoordinate<3>;
template struct IFC_GEOM_API IfcGeom::OpaqueCoordinate<4>; template struct IFC_GEOM_API IfcGeom::OpaqueCoordinate<4>;
+15 -26
View File
@@ -101,6 +101,12 @@ namespace IfcGeom {
virtual const void* value_ptr() const = 0; virtual const void* value_ptr() const = 0;
}; };
template <typename T, typename = void>
struct has_exact : std::false_type {};
template <typename T>
struct has_exact<T, std::void_t<decltype(std::declval<const T&>().exact())>> : std::true_type {};
template <typename T> template <typename T>
struct NumberModel : NumberConcept { struct NumberModel : NumberConcept {
T value; T value;
@@ -116,26 +122,19 @@ namespace IfcGeom {
return *same; return *same;
} }
template <typename U>
static auto stream_exact(std::ostream& os, const U& v, int) -> decltype(os << v.exact(), void()) {
os << v.exact();
}
template <typename U>
static void stream_exact(std::ostream& os, const U& v, long) {
if constexpr (std::is_floating_point<U>::value) {
os << std::setprecision(std::numeric_limits<U>::digits10 + 1);
}
os << v;
}
virtual double to_double() const { virtual double to_double() const {
return static_cast<double>(value); return static_cast<double>(value);
} }
virtual std::string to_string() const { virtual std::string to_string() const {
std::stringstream ss; std::stringstream ss;
stream_exact(ss, value, 0); if constexpr (has_exact<T>::value) {
ss << value.exact();
} else if constexpr (std::is_floating_point<T>::value) {
ss << std::setprecision(std::numeric_limits<T>::digits10 + 1);
}
ss << value;
}
return ss.str(); return ss.str();
} }
@@ -204,12 +203,14 @@ namespace IfcGeom {
OpaqueNumber() = default; OpaqueNumber() = default;
virtual ~OpaqueNumber() = default; virtual ~OpaqueNumber() = default;
#ifndef SWIG
template < template <
typename T, typename T,
typename Decayed = std::decay_t<T>, typename Decayed = std::decay_t<T>,
typename = std::enable_if_t<!std::is_base_of<OpaqueNumber, Decayed>::value && !is_shared_ptr<Decayed>::value>> typename = std::enable_if_t<!std::is_base_of<OpaqueNumber, Decayed>::value && !is_shared_ptr<Decayed>::value>>
explicit OpaqueNumber(T&& value) explicit OpaqueNumber(T&& value)
: data_(std::make_shared<NumberModel<Decayed>>(std::forward<T>(value))) {} : data_(std::make_shared<NumberModel<Decayed>>(std::forward<T>(value))) {}
#endif
double to_double() const { double to_double() const {
return data().to_double(); return data().to_double();
@@ -292,18 +293,6 @@ namespace IfcGeom {
} }
}; };
class IFC_GEOM_API NumberNativeDouble : public OpaqueNumber {
public:
NumberNativeDouble(double v)
: OpaqueNumber(v) {}
double value() const {
return value_as<double>();
}
std::string to_string() const;
};
template <size_t N> template <size_t N>
struct IFC_GEOM_API OpaqueCoordinate { struct IFC_GEOM_API OpaqueCoordinate {
private: private:
@@ -11,11 +11,10 @@
using IfcGeom::OpaqueNumber; using IfcGeom::OpaqueNumber;
using IfcGeom::OpaqueCoordinate; using IfcGeom::OpaqueCoordinate;
using IfcGeom::NumberNativeDouble;
using IfcGeom::ConversionResultShape; using IfcGeom::ConversionResultShape;
#ifdef IFOPSH_SIMPLE_KERNEL #ifdef IFOPSH_SIMPLE_KERNEL
#define NumberType NumberNativeDouble #define NumberType OpaqueNumber
#else #else
using ifcopenshell::geometry::NumberEpeck; using ifcopenshell::geometry::NumberEpeck;
#define NumberType NumberEpeck #define NumberType NumberEpeck
@@ -103,6 +102,15 @@ namespace {
}); });
} }
void apply_normalized_plane_map(const plane_map<Kernel_>& mp, std::list<cgal_plane_t>& planes) {
for (auto& plane : planes) {
auto it = mp.find(normalized_plane_for_map<Kernel_>(plane));
if (it != mp.end()) {
plane = it->second;
}
}
}
cgal_vector_t wire_normal(const cgal_wire_t& wire) { cgal_vector_t wire_normal(const cgal_wire_t& wire) {
typename Kernel_::FT a(0), b(0), c(0); typename Kernel_::FT a(0), b(0), c(0);
if (wire.size() < 3) { if (wire.size() < 3) {
@@ -1196,6 +1204,7 @@ std::size_t ifcopenshell::geometry::CgalShapeHalfSpaceDecomposition::map(OpaqueC
std::size_t mutated = 0; std::size_t mutated = 0;
auto nw = shape_->map(mp, mutated); auto nw = shape_->map(mp, mutated);
shape_ = std::move(nw); shape_ = std::move(nw);
apply_normalized_plane_map(mp, planes_);
return mutated; return mutated;
} }
@@ -1214,6 +1223,7 @@ std::size_t ifcopenshell::geometry::CgalShapeHalfSpaceDecomposition::map(const s
std::size_t mutated = 0; std::size_t mutated = 0;
auto nw = shape_->map(mp, mutated); auto nw = shape_->map(mp, mutated);
shape_ = std::move(nw); shape_ = std::move(nw);
apply_normalized_plane_map(mp, planes_);
return mutated; return mutated;
} }
@@ -31,7 +31,6 @@
using IfcGeom::OpaqueNumber; using IfcGeom::OpaqueNumber;
using IfcGeom::OpaqueCoordinate; using IfcGeom::OpaqueCoordinate;
using IfcGeom::NumberNativeDouble;
using IfcGeom::ConversionResultShape; using IfcGeom::ConversionResultShape;
namespace { namespace {
@@ -390,7 +389,7 @@ OpaqueNumber ifcopenshell::geometry::OpenCascadeShape::OpenCascadeShape::length(
GProp_GProps prop; GProp_GProps prop;
BRepGProp::LinearProperties(shape_, prop); BRepGProp::LinearProperties(shape_, prop);
double l = prop.Mass(); double l = prop.Mass();
return NumberNativeDouble(l); return OpaqueNumber(l);
} }
OpaqueNumber ifcopenshell::geometry::OpenCascadeShape::area() OpaqueNumber ifcopenshell::geometry::OpenCascadeShape::area()
@@ -398,7 +397,7 @@ OpaqueNumber ifcopenshell::geometry::OpenCascadeShape::area()
GProp_GProps prop; GProp_GProps prop;
BRepGProp::SurfaceProperties(shape_, prop); BRepGProp::SurfaceProperties(shape_, prop);
double l = prop.Mass(); double l = prop.Mass();
return NumberNativeDouble(l); return OpaqueNumber(l);
} }
OpaqueNumber ifcopenshell::geometry::OpenCascadeShape::volume() OpaqueNumber ifcopenshell::geometry::OpenCascadeShape::volume()
@@ -406,7 +405,7 @@ OpaqueNumber ifcopenshell::geometry::OpenCascadeShape::volume()
GProp_GProps prop; GProp_GProps prop;
BRepGProp::VolumeProperties(shape_, prop); BRepGProp::VolumeProperties(shape_, prop);
double l = prop.Mass(); double l = prop.Mass();
return NumberNativeDouble(l); return OpaqueNumber(l);
} }
#include <Geom_Plane.hxx> #include <Geom_Plane.hxx>
@@ -419,9 +418,9 @@ OpaqueCoordinate<3> ifcopenshell::geometry::OpenCascadeShape::position()
if (plane) { if (plane) {
auto loc = plane->Location(); auto loc = plane->Location();
return OpaqueCoordinate<3>( return OpaqueCoordinate<3>(
NumberNativeDouble(loc.X()), OpaqueNumber(loc.X()),
NumberNativeDouble(loc.Y()), OpaqueNumber(loc.Y()),
NumberNativeDouble(loc.Z()) OpaqueNumber(loc.Z())
); );
} }
} }
@@ -436,9 +435,9 @@ OpaqueCoordinate<3> ifcopenshell::geometry::OpenCascadeShape::axis()
if (plane) { if (plane) {
auto dir = plane->Axis().Direction(); auto dir = plane->Axis().Direction();
return OpaqueCoordinate<3>( return OpaqueCoordinate<3>(
NumberNativeDouble(dir.X()), OpaqueNumber(dir.X()),
NumberNativeDouble(dir.Y()), OpaqueNumber(dir.Y()),
NumberNativeDouble(dir.Z()) OpaqueNumber(dir.Z())
); );
} }
} }
@@ -454,10 +453,10 @@ OpaqueCoordinate<4> ifcopenshell::geometry::OpenCascadeShape::plane_equation()
double a, b, c, d; double a, b, c, d;
plane->Pln().Coefficients(a, b, c, d); plane->Pln().Coefficients(a, b, c, d);
return OpaqueCoordinate<4>( return OpaqueCoordinate<4>(
NumberNativeDouble(a), OpaqueNumber(a),
NumberNativeDouble(b), OpaqueNumber(b),
NumberNativeDouble(c), OpaqueNumber(c),
NumberNativeDouble(d) OpaqueNumber(d)
); );
} }
} }
-1
View File
@@ -59,7 +59,6 @@
%} %}
%template(DoubleArray3) std::array<double, 3>; %template(DoubleArray3) std::array<double, 3>;
%ignore IfcGeom::NumberNativeDouble;
%ignore ifcopenshell::geometry::Converter; %ignore ifcopenshell::geometry::Converter;
// Not relevant for python: new_IfcBaseClass() calls instantiate() // Not relevant for python: new_IfcBaseClass() calls instantiate()