From dd3a4d2a43d31984704ba0013dd294a24cfbda5a Mon Sep 17 00:00:00 2001 From: Alexander Krotov Date: Wed, 5 Apr 2017 10:56:05 +0300 Subject: [PATCH] Use Vector{2,3}D.GetLength () --- src/antenna/model/angles.cc | 2 +- src/core/model/vector.cc | 11 ++--------- src/mobility/model/mobility-model.cc | 5 +---- 3 files changed, 4 insertions(+), 14 deletions(-) diff --git a/src/antenna/model/angles.cc b/src/antenna/model/angles.cc index 8387e8976..97092e970 100644 --- a/src/antenna/model/angles.cc +++ b/src/antenna/model/angles.cc @@ -73,7 +73,7 @@ Angles::Angles (double p, double t) Angles::Angles (Vector v) : phi (std::atan2 (v.y, v.x)), - theta (std::acos (v.z / sqrt (v.x*v.x + v.y*v.y + v.z*v.z))) + theta (std::acos (v.z / v.GetLength ())) { } diff --git a/src/core/model/vector.cc b/src/core/model/vector.cc index ccbad830f..5467ae709 100644 --- a/src/core/model/vector.cc +++ b/src/core/model/vector.cc @@ -92,20 +92,13 @@ double CalculateDistance (const Vector3D &a, const Vector3D &b) { NS_LOG_FUNCTION (a << b); - double dx = b.x - a.x; - double dy = b.y - a.y; - double dz = b.z - a.z; - double distance = std::sqrt (dx * dx + dy * dy + dz * dz); - return distance; + return (b - a).GetLength (); } double CalculateDistance (const Vector2D &a, const Vector2D &b) { NS_LOG_FUNCTION (a << b); - double dx = b.x - a.x; - double dy = b.y - a.y; - double distance = std::sqrt (dx * dx + dy * dy); - return distance; + return (b - a).GetLength (); } std::ostream &operator << (std::ostream &os, const Vector3D &vector) diff --git a/src/mobility/model/mobility-model.cc b/src/mobility/model/mobility-model.cc index 895aca508..022f3d77f 100644 --- a/src/mobility/model/mobility-model.cc +++ b/src/mobility/model/mobility-model.cc @@ -88,10 +88,7 @@ MobilityModel::GetDistanceFrom (Ptr other) const double MobilityModel::GetRelativeSpeed (Ptr other) const { - double x = GetVelocity().x - other->GetVelocity().x; - double y = GetVelocity().y - other->GetVelocity().y; - double z = GetVelocity().z - other->GetVelocity().z; - return sqrt( (x*x) + (y*y) + (z*z) ); + return (GetVelocity () - other->GetVelocity ()).GetLength (); } void