returns -1.0 (opposite directions) .. +1.0 (same direction) returns 1.0 if either vector is (0,0)
| 160 | // returns -1.0 (opposite directions) .. +1.0 (same direction) |
| 161 | // returns 1.0 if either vector is (0,0) |
| 162 | float Coord::raySameness(Coord other) const |
| 163 | { |
| 164 | int64_t mag = ((int64_t)x * x + y * y) * (other.x * other.x + other.y * other.y); |
| 165 | if (mag == 0) { |
| 166 | return 1.0; // anything is "same" as zero vector |
| 167 | } |
| 168 | |
| 169 | return (x * other.x + y * other.y) / std::sqrt(mag); |
| 170 | } |
| 171 | |
| 172 | |
| 173 | // returns -1.0 (opposite directions) .. +1.0 (same direction) |