| @@ -156,6 +156,9 @@ struct Vec { | |||||
| Vec() {} | Vec() {} | ||||
| Vec(float x, float y) : x(x), y(y) {} | Vec(float x, float y) : x(x), y(y) {} | ||||
| /** Negates the vector | |||||
| Equivalent to a reflection across the y=-x line. | |||||
| */ | |||||
| Vec neg() const { | Vec neg() const { | ||||
| return Vec(-x, -y); | return Vec(-x, -y); | ||||
| } | } | ||||
| @@ -183,6 +186,15 @@ struct Vec { | |||||
| float norm() const { | float norm() const { | ||||
| return std::hypotf(x, y); | return std::hypotf(x, y); | ||||
| } | } | ||||
| /** Rotates counterclockwise in radians */ | |||||
| Vec rotate(float angle) { | |||||
| float sin = std::sin(angle); | |||||
| float cos = std::cos(angle); | |||||
| return Vec(x * cos - y * sin, x * sin + y * cos); | |||||
| } | |||||
| /** Swaps the coordinates | |||||
| Equivalent to a reflection across the y=x line. | |||||
| */ | |||||
| Vec flip() const { | Vec flip() const { | ||||
| return Vec(y, x); | return Vec(y, x); | ||||
| } | } | ||||