Added measurements
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user