]> rtime.felk.cvut.cz Git - hubacji1/bcar.git/commitdiff
Add euclidean distance computation to point
authorJiri Vlasak <hubacji1@fel.cvut.cz>
Thu, 15 Jul 2021 11:56:27 +0000 (13:56 +0200)
committerJiri Vlasak <hubacji1@fel.cvut.cz>
Thu, 15 Jul 2021 14:17:37 +0000 (16:17 +0200)
incl/bcar.hh
src/bcar.cc

index 3cef171b475cb1bd381c0aee62445b2f3044879e..a84053ae6320722d4a89936c5a1397f7d94afca7 100644 (file)
@@ -65,6 +65,9 @@ public:
        */
        void rotate(Point const& c, double const angl);
 
+       /*! Return Euclidean distance to `p`. */
+       double edist(Point const& p) const;
+
        friend std::ostream& operator<<(std::ostream& out, Point const& p);
 };
 
index 7c8dd93f6fab1da00e9f590890a911ef1c14757e..54d30b9ebd40e1912d2ac49e3db1ec885deee151 100644 (file)
@@ -108,6 +108,12 @@ Point::rotate(Point const& c, double const angl)
        this->y(ny + c.y());
 }
 
+double
+Point::edist(Point const& p) const
+{
+       return sqrt(pow(p.x() - this->x_, 2.0) + pow(p.y() - this->y_, 2.0));
+}
+
 std::ostream&
 operator<<(std::ostream& out, Point const& p)
 {