Added measurements

This commit is contained in:
Nguyen Quy Anh
2026-04-24 16:31:42 +02:00
parent aa1daf9149
commit 3d217e7840
7 changed files with 113 additions and 55 deletions
+13 -2
View File
@@ -7,16 +7,27 @@ struct Obstacle {
Obstacle() : start(0, 0), end(0, 0) {}
Obstacle(Vector2d s, Vector2d e) : start(s), end(e) {}
// find the point of the obstacle that is nearest to p
// Find the point of the obstacle that is nearest to p
// # 15 flops
Vector2d find_nearest_obstacle_point(Vector2d p) {
// # 2 ADDs
Vector2d obstacle_v = end - start;
// # 9 flops = 2 ADDs, 2 MULTs, 1 ADD, 1 DIV, 2 MULTs, 1 ADD
double projection = (p - start).dot(obstacle_v) / obstacle_v.dot(obstacle_v);
if (projection < 0.0)
projection = 0.0;
if (projection > 1.0)
else if (projection > 1.0)
projection = 1.0;
// # 4 flops = 2 ADDs, 2 MULTs
return start + obstacle_v * projection;
}
};
struct Board {