From 27757fc246cdfd674fff192c7f56ab0885624aa3 Mon Sep 17 00:00:00 2001 From: wmayer Date: Thu, 4 Aug 2022 11:46:38 +0200 Subject: [PATCH] Base: add Transform/Transformed to Line3<> and Polygon3<> --- src/Base/Tools3D.cpp | 90 ++++++++++++++++++++++++++++++++++++++++++++ src/Base/Tools3D.h | 24 +++++++++--- 2 files changed, 108 insertions(+), 6 deletions(-) diff --git a/src/Base/Tools3D.cpp b/src/Base/Tools3D.cpp index 8f2c4a4ed9..eb2a842a3c 100644 --- a/src/Base/Tools3D.cpp +++ b/src/Base/Tools3D.cpp @@ -109,6 +109,51 @@ Vector3 Line3::GetDirection() const return p2 - p1; } +template +void Line3::Transform(const Base::Matrix4D& mat) +{ + mat.multVec(p1, p1); + mat.multVec(p2, p2); +} + +template +void Line3::Transform(const Base::Placement& plm) +{ + plm.multVec(p1, p1); + plm.multVec(p2, p2); +} + +template +void Line3::Transform(const Base::Rotation& rot) +{ + rot.multVec(p1, p1); + rot.multVec(p2, p2); +} + +template +Line3 Line3::Transformed(const Base::Matrix4D& mat) const +{ + Line3 line(*this); + line.Transform(mat); + return line; +} + +template +Line3 Line3::Transformed(const Base::Placement& plm) const +{ + Line3 line(*this); + line.Transform(plm); + return line; +} + +template +Line3 Line3::Transformed(const Base::Rotation& rot) const +{ + Line3 line(*this); + line.Transform(rot); + return line; +} + template bool Line3::Contains(const Vector3& pt) const { @@ -201,6 +246,51 @@ BoundBox3 Polygon3::CalcBoundBox() const return box; } +template +void Polygon3::Transform(const Base::Matrix4D& mat) +{ + for (auto& it : points) + mat.multVec(it, it); +} + +template +void Polygon3::Transform(const Base::Placement& plm) +{ + for (auto& it : points) + plm.multVec(it, it); +} + +template +void Polygon3::Transform(const Base::Rotation& rot) +{ + for (auto& it : points) + rot.multVec(it, it); +} + +template +Polygon3 Polygon3::Transformed(const Base::Matrix4D& mat) const +{ + Polygon3 poly(*this); + poly.Transform(mat); + return poly; +} + +template +Polygon3 Polygon3::Transformed(const Base::Placement& plm) const +{ + Polygon3 poly(*this); + poly.Transform(plm); + return poly; +} + +template +Polygon3 Polygon3::Transformed(const Base::Rotation& rot) const +{ + Polygon3 poly(*this); + poly.Transform(rot); + return poly; +} + // explicit template instantiation namespace Base { template class BaseExport Line3; diff --git a/src/Base/Tools3D.h b/src/Base/Tools3D.h index b6511d6e15..cc9a891d05 100644 --- a/src/Base/Tools3D.h +++ b/src/Base/Tools3D.h @@ -33,7 +33,7 @@ #include #include -#include +#include #ifndef FC_GLOBAL_H #include #endif @@ -58,14 +58,14 @@ public: Line3() = default; ~Line3() = default; - Line3(const Line3& line); - Line3(Line3&& line); + Line3(const Line3& line); + Line3(Line3&& line); Line3(const Vector3& p1, const Vector3& p2); // operators - Line3& operator= (const Line3& line); - Line3& operator= (Line3&& line); - bool operator== (const Line3& line) const; + Line3& operator= (const Line3& line); + Line3& operator= (Line3&& line); + bool operator== (const Line3& line) const; // methods double Length () const; @@ -73,6 +73,12 @@ public: BoundBox3 CalcBoundBox() const; Vector3 GetBase() const; Vector3 GetDirection() const; + void Transform(const Base::Matrix4D&); + void Transform(const Base::Placement&); + void Transform(const Base::Rotation&); + Line3 Transformed(const Base::Matrix4D&) const; + Line3 Transformed(const Base::Placement&) const; + Line3 Transformed(const Base::Rotation&) const; /*! * \brief Contains @@ -119,6 +125,12 @@ public: // misc BoundBox3 CalcBoundBox() const; + void Transform(const Base::Matrix4D&); + void Transform(const Base::Placement&); + void Transform(const Base::Rotation&); + Polygon3 Transformed(const Base::Matrix4D&) const; + Polygon3 Transformed(const Base::Placement&) const; + Polygon3 Transformed(const Base::Rotation&) const; private: std::vector> points;