예제 #1
0
void
test_coords_and_neighbors( const Triangul& T, const  typename
			   Triangul::Geom_traits::Point_3& p,
			   const typename Triangul::Geom_traits::Vector_3& n,
			   const typename  Triangul::Geom_traits::FT&
			   tolerance, const int& version )
{
  CGAL::Set_ieee_double_precision pfr;

  typedef std::pair<typename Triangul::Geom_traits::Point_3,
                    typename Triangul::Geom_traits::FT >    Point_coord_pair;

  std::vector<Point_coord_pair  >  coords;
  typename Triangul::Geom_traits::FT  norm;
  norm = test_coords(T, p, n,version, std::back_inserter(coords)).second;
  assert(test_norm( coords.begin(), coords.end(),norm));
  assert(test_barycenter(coords.begin(), coords.end(),norm,p,
			 tolerance));
  //All function testing surface neighbors are
  // grouped together:
  std::vector< typename Triangul::Geom_traits::Point_3 >  neighbors;
  test_neighbors(T, p, n,version, std::back_inserter(neighbors));
  assert(compare_neighbors(coords.begin(),
			   coords.end(),neighbors.begin(),
			   neighbors.end(), T.geom_traits()));
  //done
}
예제 #2
0
파일: AStarPath.cpp 프로젝트: nuvie/nuvie
#include <vector>
#include "nuvieDefs.h"
#include "DirFinder.h"
#include "AStarPath.h"
AStarPath::AStarPath() : final_node(0)
{}void AStarPath::create_path()
{    astar_node *i = final_node; // iterator through steps, from back
    delete_path();
    std::vector<astar_node *> reverse_list;
    while(i)
    {
        reverse_list.push_back(i);
        i = i->parent;
    }
    while(!reverse_list.empty())
    {
        i = reverse_list.back();
        add_step(i->loc);
        reverse_list.pop_back();
    }
    set_path_size(step_count);
}/* Get a new neighbor to nnode and score it, returning true if it's usable. */
bool AStarPath::score_to_neighbor(sint8 dir, astar_node *nnode, astar_node *neighbor,
                                  sint32 &nnode_to_neighbor)
{    sint8 sx = -1, sy = -1;
    DirFinder::get_adjacent_dir(sx, sy, dir); // sx,sy = neighbor -1,-1 + dir
    // get neighbor of nnode towards sx,sy, and cost to that neighbor
    neighbor->loc = nnode->loc.abs_coords(sx, sy);
    nnode_to_neighbor = step_cost(nnode->loc, neighbor->loc);
    if(nnode_to_neighbor == -1)
    {
        delete neighbor; // this neighbor is blocked
        return false;
    }
    return true;
}/* Compare a node's score to the start node to already scored neighbors. */
bool AStarPath::compare_neighbors(astar_node *nnode, astar_node *neighbor,
                                  sint32 nnode_to_neighbor, astar_node *in_open,
                                  astar_node *in_closed)
{    neighbor->to_start = nnode->to_start + nnode_to_neighbor;
     // ignore this neighbor if already checked and closer to start
    if((in_open && in_open->to_start <= neighbor->to_start)
       || (in_closed && in_closed->to_start <= neighbor->to_start))
    {
        delete neighbor;
        return false;
    }
    return true;
}/* Check all neighbors of a node (location) and save them to the "seen" list. */
bool AStarPath::search_node_neighbors(astar_node *nnode, MapCoord &goal,
                                      const uint32 max_score)
{    for(uint32 dir = 1; dir < 8; dir += 2)
    {
        astar_node *neighbor = new astar_node;
        sint32 nnode_to_neighbor = -1;
        if(!score_to_neighbor(dir, nnode, neighbor, nnode_to_neighbor))
            continue; // this neighbor is blocked
        astar_node *in_open = find_open_node(neighbor),
                   *in_closed = find_closed_node(neighbor);
        if(!compare_neighbors(nnode, neighbor, nnode_to_neighbor, in_open, in_closed))
            continue;
        neighbor->parent = nnode;
        neighbor->to_goal = path_cost_est(neighbor->loc, goal);
        neighbor->score = neighbor->to_start + neighbor->to_goal;
        neighbor->len = nnode->len + 1;
        if(neighbor->score > max_score)
        {
            delete neighbor; // too far away
            continue;
        }
        // take neighbor out of closed list and put into open list
        if(in_closed)
            remove_closed_node(in_closed);
        if(!in_open)
            push_open_node(neighbor);
    }
    return true;
}/* Do A* search of tiles to create a path from `start' to `goal'.