From 2d447bfeba083e3181adbccd59b163144ec7be4a Mon Sep 17 00:00:00 2001 From: Alexander Krotov Date: Tue, 4 Apr 2017 19:31:26 +0300 Subject: [PATCH] core: Implement Vector{2,3}D::GetLength () --- src/core/model/vector.cc | 13 +++++++++++++ src/core/model/vector.h | 2 ++ 2 files changed, 15 insertions(+) diff --git a/src/core/model/vector.cc b/src/core/model/vector.cc index 42aceb79f..4d6bb2106 100644 --- a/src/core/model/vector.cc +++ b/src/core/model/vector.cc @@ -75,6 +75,19 @@ Vector2D::Vector2D () NS_LOG_FUNCTION (this); } +double +Vector3D::GetLength () const +{ + NS_LOG_FUNCTION (this); + return std::sqrt (x * x + y * y + z * z); +} +double +Vector2D::GetLength () const +{ + NS_LOG_FUNCTION (this); + return std::sqrt (x * x + y * y); +} + double CalculateDistance (const Vector3D &a, const Vector3D &b) { diff --git a/src/core/model/vector.h b/src/core/model/vector.h index 6fe2bae1c..4ff8007d5 100644 --- a/src/core/model/vector.h +++ b/src/core/model/vector.h @@ -63,6 +63,7 @@ public: */ double z; + double GetLength () const; friend double CalculateDistance (const Vector3D &a, const Vector3D &b); friend std::ostream &operator << (std::ostream &os, const Vector3D &vector); friend std::istream &operator >> (std::istream &is, Vector3D &vector); @@ -96,6 +97,7 @@ public: */ double y; + double GetLength () const; friend double CalculateDistance (const Vector2D &a, const Vector2D &b); friend std::ostream &operator << (std::ostream &os, const Vector2D &vector); friend std::istream &operator >> (std::istream &is, Vector2D &vector);