X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fobject%2Fpath.cpp;h=5d7e88a7da8e0cca8a2401e17b3e32cadbc2a711;hb=555d1b7bebb45326d82d934e07463209837309b0;hp=6529cf33855bfc7f0260904edc62e7f34683cafc;hpb=a113d3bd1feddd510e3b2852b0d42522735eee40;p=supertux.git diff --git a/src/object/path.cpp b/src/object/path.cpp index 6529cf338..5d7e88a7d 100644 --- a/src/object/path.cpp +++ b/src/object/path.cpp @@ -23,6 +23,7 @@ #include "path.hpp" +#include "lisp/writer.hpp" #include "lisp/lisp.hpp" #include "lisp/list_iterator.hpp" #include "object_factory.hpp" @@ -133,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; +} +