From 079d0a0bbbca7471817ec3151efe01d3b6799bee Mon Sep 17 00:00:00 2001 From: Nomango <569629550@qq.com> Date: Fri, 1 Jun 2018 15:46:55 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0Point::distance=E5=87=BD?= =?UTF-8?q?=E6=95=B0=E6=B1=82=E4=B8=A4=E7=82=B9=E9=97=B4=E8=B7=9D=E7=A6=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/Common/Point.cpp | 9 +++++++++ core/e2dcommon.h | 3 +++ 2 files changed, 12 insertions(+) diff --git a/core/Common/Point.cpp b/core/Common/Point.cpp index c22cd854..15920994 100644 --- a/core/Common/Point.cpp +++ b/core/Common/Point.cpp @@ -1,4 +1,5 @@ #include "..\e2dcommon.h" +#include e2d::Point::Point() @@ -44,6 +45,14 @@ e2d::Point::operator e2d::Size() const return Size(x, y); } +double e2d::Point::distance(const Point &p1, const Point &p2) +{ + return sqrt( + (p1.x - p2.x) * (p1.x - p2.x) + + (p1.y - p2.y) * (p1.y - p2.y) + ); +} + e2d::Point e2d::Point::operator-() const { return Point(-x, -y); diff --git a/core/e2dcommon.h b/core/e2dcommon.h index 900c679f..e5cf4ecc 100644 --- a/core/e2dcommon.h +++ b/core/e2dcommon.h @@ -48,6 +48,9 @@ public: bool operator== (const Point& point) const; operator e2d::Size() const; + + // ÅжÏÁ½µã¼ä¾àÀë + static double distance(const Point&, const Point&); };