From 2a69e3d8788061cb1f5eb81eabcfd316d1ca515f Mon Sep 17 00:00:00 2001 From: Kacper Donat Date: Mon, 11 Nov 2024 17:54:29 +0100 Subject: [PATCH] Base: Add ComplexGeoData::centerOfGravity helper This adds a simple quality of life helper returning center of gravity as std::optional instead of C style method accepting reference and returning bool to indicate method success. --- src/App/ComplexGeoData.cpp | 11 +++++++++++ src/App/ComplexGeoData.h | 3 +++ 2 files changed, 14 insertions(+) diff --git a/src/App/ComplexGeoData.cpp b/src/App/ComplexGeoData.cpp index e8d50030a4..b8a1c67c6a 100644 --- a/src/App/ComplexGeoData.cpp +++ b/src/App/ComplexGeoData.cpp @@ -184,6 +184,17 @@ bool ComplexGeoData::getCenterOfGravity(Base::Vector3d& unused) const return false; } +std::optional ComplexGeoData::centerOfGravity() const +{ + Base::Vector3d centerOfGravity; + + if (getCenterOfGravity(centerOfGravity)) { + return centerOfGravity; + } + + return {}; +} + const std::string& ComplexGeoData::elementMapPrefix() { static std::string prefix(ELEMENT_MAP_PREFIX); diff --git a/src/App/ComplexGeoData.h b/src/App/ComplexGeoData.h index 995b797944..8c0f8dc59b 100644 --- a/src/App/ComplexGeoData.h +++ b/src/App/ComplexGeoData.h @@ -28,6 +28,8 @@ #define APP_COMPLEX_GEO_DATA_H #include +#include + #include #include #include @@ -200,6 +202,7 @@ public: * The default implementation only returns false. */ virtual bool getCenterOfGravity(Base::Vector3d& center) const; + virtual std::optional centerOfGravity() const; //@} static const std::string& elementMapPrefix();