From bef32983b00855cee8f304c1cb7daf6f49b165be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Br=C3=A6strup=20Sayoc?= Date: Mon, 17 Jul 2023 14:19:25 +0200 Subject: [PATCH] [TechDraw] Improve CosmeticVertex.cpp typing Make type safe by using const keywords when appropriate and improve memory handling by using references when appropriate. --- src/Mod/TechDraw/App/CosmeticVertex.cpp | 12 ++++++------ src/Mod/TechDraw/App/CosmeticVertex.h | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Mod/TechDraw/App/CosmeticVertex.cpp b/src/Mod/TechDraw/App/CosmeticVertex.cpp index 7e02cc5518..256c37428b 100644 --- a/src/Mod/TechDraw/App/CosmeticVertex.cpp +++ b/src/Mod/TechDraw/App/CosmeticVertex.cpp @@ -71,7 +71,7 @@ CosmeticVertex::CosmeticVertex(const TechDraw::CosmeticVertex* cv) : TechDraw::V createNewTag(); } -CosmeticVertex::CosmeticVertex(Base::Vector3d loc) : TechDraw::Vertex(loc) +CosmeticVertex::CosmeticVertex(const Base::Vector3d& loc) : TechDraw::Vertex(loc) { permaPoint = loc; linkGeom = -1; @@ -87,12 +87,12 @@ CosmeticVertex::CosmeticVertex(Base::Vector3d loc) : TechDraw::Vertex(loc) } -void CosmeticVertex::move(Base::Vector3d newPos) +void CosmeticVertex::move(const Base::Vector3d& newPos) { permaPoint = newPos; } -void CosmeticVertex::moveRelative(Base::Vector3d movement) +void CosmeticVertex::moveRelative(const Base::Vector3d& movement) { permaPoint += movement; } @@ -172,7 +172,7 @@ void CosmeticVertex::Restore(Base::XMLReader &reader) tag = u1; } -Base::Vector3d CosmeticVertex::scaled(double factor) +Base::Vector3d CosmeticVertex::scaled(const double factor) { return permaPoint * factor; } @@ -202,7 +202,7 @@ void CosmeticVertex::createNewTag() tag = gen(); } -void CosmeticVertex::assignTag(const TechDraw::CosmeticVertex * cv) +void CosmeticVertex::assignTag(const TechDraw::CosmeticVertex* cv) { if(cv->getTypeId() == this->getTypeId()) this->tag = cv->tag; @@ -233,7 +233,7 @@ PyObject* CosmeticVertex::getPyObject() return Py::new_reference_to(PythonObject); } - +// To do: make const void CosmeticVertex::dump(const char* title) { Base::Console().Message("CV::dump - %s \n", title); diff --git a/src/Mod/TechDraw/App/CosmeticVertex.h b/src/Mod/TechDraw/App/CosmeticVertex.h index 659a42468b..5545113415 100644 --- a/src/Mod/TechDraw/App/CosmeticVertex.h +++ b/src/Mod/TechDraw/App/CosmeticVertex.h @@ -44,15 +44,15 @@ class TechDrawExport CosmeticVertex: public Base::Persistence, public TechDraw:: public: CosmeticVertex(); CosmeticVertex(const CosmeticVertex* cv); - CosmeticVertex(Base::Vector3d loc); + CosmeticVertex(const Base::Vector3d& loc); ~CosmeticVertex() override = default; - void move(Base::Vector3d newPos); - void moveRelative(Base::Vector3d movement); + void move(const Base::Vector3d& newPos); + void moveRelative(const Base::Vector3d& movement); std::string toString() const; void dump(const char* title) override; - Base::Vector3d scaled(double factor); + Base::Vector3d scaled(const double factor); static bool restoreCosmetic();