X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fobject%2Fpath.cpp;h=5d7e88a7da8e0cca8a2401e17b3e32cadbc2a711;hb=a98f7cee9f6a2593c0e1f3442800f159bad410df;hp=b7a34af8ef2b03688099e985da49e655a5f081fa;hpb=7c579d3ef0a6667c18b53dad84c63c05d2760a84;p=supertux.git diff --git a/src/object/path.cpp b/src/object/path.cpp index b7a34af8e..5d7e88a7d 100644 --- a/src/object/path.cpp +++ b/src/object/path.cpp @@ -134,3 +134,36 @@ Path::get_base() const return nodes[0].position; } + +int +Path::get_nearest_node_no(Vector reference_point) const +{ + int nearest_node_id = -1; + float nearest_node_dist = 0; + int id = 0; + for (std::vector::const_iterator i = nodes.begin(); i != nodes.end(); i++, id++) { + float dist = (i->position - reference_point).norm(); + if ((nearest_node_id == -1) || (dist < nearest_node_dist)) { + nearest_node_id = id; + nearest_node_dist = dist; + } + } + return nearest_node_id; +} + +int +Path::get_farthest_node_no(Vector reference_point) const +{ + int farthest_node_id = -1; + float farthest_node_dist = 0; + int id = 0; + for (std::vector::const_iterator i = nodes.begin(); i != nodes.end(); i++, id++) { + float dist = (i->position - reference_point).norm(); + if ((farthest_node_id == -1) || (dist > farthest_node_dist)) { + farthest_node_id = id; + farthest_node_dist = dist; + } + } + return farthest_node_id; +} +