double MatchHelpers::distanceToPitch(const Match& m, const Vector3& v) { float r = m.getPitchWidth() * 0.5f; float l = -r; float u = m.getPitchHeight() * 0.5f; float d = -u; if(v.x >= l && v.x <= r && v.y >= d && v.y <= u) return 0.0f; float dhoriz = v.x < l ? l - v.x : v.x - r; float dvert = v.y < d ? d - v.y : v.y - u; if(dvert < 0) return dhoriz; else if(dhoriz < 0) return dvert; else return sqrt(dvert * dvert + dhoriz * dhoriz); }
bool MatchHelpers::onPitch(const Match& m, const Vector3& v) { float pw2 = m.getPitchWidth() / 2.0f; float ph2 = m.getPitchHeight() / 2.0f; return v.x >= -pw2 && v.y >= -ph2 && v.x <= pw2 && v.y <= ph2; }