From 6c5b17c90ca342b86e6aedd6e2625e9b31010d10 Mon Sep 17 00:00:00 2001 From: hwinkel Date: Fri, 4 Aug 2023 12:34:38 +0200 Subject: [PATCH] FIX: fixed a issue where copied positions are alway valid --- include/SimCore/Position.hpp | 2 +- src/SimCore/Position.cpp | 35 +++++++++++++++++++++++------------ 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/include/SimCore/Position.hpp b/include/SimCore/Position.hpp index b87fc0a..dce0804 100644 --- a/include/SimCore/Position.hpp +++ b/include/SimCore/Position.hpp @@ -63,7 +63,7 @@ namespace SimCore { mutable std::mutex mx; - std::atomic_bool valid_; + std::atomic_bool valid_ = false; }; diff --git a/src/SimCore/Position.cpp b/src/SimCore/Position.cpp index f1c6d3f..88fb54c 100644 --- a/src/SimCore/Position.cpp +++ b/src/SimCore/Position.cpp @@ -6,33 +6,38 @@ namespace SimCore { Position::Position():mx() { + valid_ = false; earth_ = std::make_unique(GeographicLib::Constants::WGS84_a(), GeographicLib::Constants::WGS84_f()); geod_ = std::make_unique(GeographicLib::Constants::WGS84_a(), GeographicLib::Constants::WGS84_f()); wgs84_ = std::make_unique(GeographicLib::Constants::WGS84_a(), GeographicLib::Constants::WGS84_f()); - valid_ = false; } Position::Position(double X, double Y, double Z):mx() { + valid_ = false; earth_ = std::make_unique(GeographicLib::Constants::WGS84_a(), GeographicLib::Constants::WGS84_f()); geod_ = std::make_unique(GeographicLib::Constants::WGS84_a(), GeographicLib::Constants::WGS84_f()); wgs84_ = std::make_unique(GeographicLib::Constants::WGS84_a(), GeographicLib::Constants::WGS84_f()); setGeocentricPos( X, Y, Z); - valid_ = true; } Position::Position(const Position& other){ - std::lock_guard lock(other.mx); - GeocentricPos_ = other.GeocentricPos_; - GeodesicPos_ = other.GeodesicPos_; + std::lock_guard lock(other.mx); - earth_ = std::make_unique(GeographicLib::Constants::WGS84_a(), GeographicLib::Constants::WGS84_f()); - geod_ = std::make_unique(GeographicLib::Constants::WGS84_a(), GeographicLib::Constants::WGS84_f()); - wgs84_ = std::make_unique(GeographicLib::Constants::WGS84_a(), GeographicLib::Constants::WGS84_f()); - valid_ = true; + valid_ = false; + if (other.valid_ == true) + { + this->setGeocentricPos(other.GeocentricPos_[X],other.GeocentricPos_[Y],other.GeocentricPos_[Z]); + } + // GeocentricPos_ = other.GeocentricPos_; + // GeodesicPos_ = other.GeodesicPos_; + + earth_ = std::make_unique(GeographicLib::Constants::WGS84_a(), GeographicLib::Constants::WGS84_f()); + geod_ = std::make_unique(GeographicLib::Constants::WGS84_a(), GeographicLib::Constants::WGS84_f()); + wgs84_ = std::make_unique(GeographicLib::Constants::WGS84_a(), GeographicLib::Constants::WGS84_f()); } Eigen::Vector3d Position::getGeocentricPos() @@ -129,9 +134,15 @@ namespace SimCore { Position& Position::operator=(const Position other) { std::lock_guard lock(other.mx); - GeocentricPos_ = other.GeocentricPos_; - GeodesicPos_ = other.GeodesicPos_; - valid_ = true; + if (other.valid_ == true) + { + this->setGeocentricPos(other.GeocentricPos_[X],other.GeocentricPos_[Y],other.GeocentricPos_[Z]); + } + + // GeocentricPos_ = other.GeocentricPos_; + + // GeodesicPos_ = other.GeodesicPos_; + // valid_ = true; return *this; }