Merge branch 'ahmed' into 'main'

This commit is contained in:
Nguyen Quy Anh
2026-05-08 11:04:20 +02:00
parent f74fbe46d7
commit ae1c64af05
10 changed files with 1194 additions and 157 deletions
+12 -8
View File
@@ -4,19 +4,23 @@
struct Obstacle {
Vector2d start;
Vector2d end;
Vector2d obstacle_v;
Obstacle() : start(0, 0), end(0, 0) {}
Obstacle(Vector2d s, Vector2d e) : start(s), end(e) {}
double length_sq_inv;
Obstacle() : start(0, 0), end(0, 0), obstacle_v(0, 0), length_sq_inv(0.0) {}
Obstacle(Vector2d s, Vector2d e) : start(s), end(e) {
obstacle_v = end - start;
double length_sq = obstacle_v.dot(obstacle_v);
length_sq_inv = length_sq != 0 ? 1.0 / length_sq : 0.0;
}
// Find the point of the obstacle that is closest to p
// # 8 ADDs, 6 MULTs, 1 DIV
// # 5 ADDs, 5 MULTs
Vector2d find_nearest_obstacle_point(Vector2d p) {
// # 2 ADDs
Vector2d obstacle_v = end - start;
// # 4 ADDs, 4 MULTs, 1 DIV
double projection = (p - start).dot(obstacle_v) / obstacle_v.dot(obstacle_v);
// # 3 ADDs, 3 MULTs
double projection = (p - start).dot(obstacle_v) * length_sq_inv;
if (projection < 0.0)
projection = 0.0;