添加马哈顿距离判断

This commit is contained in:
aozhiwei 2020-05-28 19:05:03 +08:00
parent 8303f98fe3
commit 51e1820242
2 changed files with 7 additions and 0 deletions

View File

@ -98,6 +98,12 @@ namespace a8
return v.Norm();
}
float Vec2::ManhattanDistance(const Vec2& b)
{
float distance = std::fabs(x - b.x) + std::fabs(y - b.y);
return distance;
}
Vec2 Vec2::Perp()
{
return Vec2(y, -x);

View File

@ -16,6 +16,7 @@ namespace a8
float CalcAngleEx(const Vec2& b);
static Vec2 FromAngle(float angle);
float Distance(const Vec2& b);
float ManhattanDistance(const Vec2& b);
bool operator == (const Vec2& b) const;
Vec2 operator + (const Vec2& b) const;