// $Id$
-//
+//
// SuperTux Path
// Copyright (C) 2005 Philipp <balinor@pnxs.de>
// Copyright (C) 2006 Christoph Sommer <christoph.sommer@2006.expires.deltadevelopment.de>
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
-//
+//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
#include "path.hpp"
+#include "lisp/writer.hpp"
#include "lisp/lisp.hpp"
#include "lisp/list_iterator.hpp"
#include "object_factory.hpp"
}
continue;
}
-
+
if(iter.item() != "node") {
log_warning << "unknown token '" << iter.item() << "' in Path nodes list. Ignored." << std::endl;
continue;
{
if(nodes.empty())
return Vector(0, 0);
-
+
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<Node>::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<Node>::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;
+}
+