Package general.datastructures

Examples of general.datastructures.Waypoint


  }
 
  @Test
  public void testWaypoint()
  {
    Waypoint wp1, wp2, wp3, wp4, wp5;
    wp1 = new Waypoint(new Vector2f(3, 4), 0);
    assertNotNull(wp1);
    assertNull(wp1.getPredecessor());
    assertEquals(new Vector2f(3,4),wp1.getVector2f());
    assertEquals(0.0,wp1.getDistance(),1e-4);
   
    wp2 = new Waypoint(new Vector2f(3,8), 4, wp1);
    assertNotNull(wp2);
    assertEquals(wp1,wp2.getPredecessor());
   
    wp3 = new Waypoint(new Vector2f(1,8), 2, wp2);
   
    assertEquals(6, wp3.getDistance(),1e-4);
   
    Vector<Vector2f> points = new Vector<Vector2f>();
    Vector<Vector2f> actual_points = new Vector<Vector2f>();
    points = wp3.getRouteList(points);
    assertNotSame(actual_points,points);
   
    actual_points.add(wp3.getVector2f());
    actual_points.add(wp2.getVector2f());
    actual_points.add(wp1.getVector2f());
   
    assertEquals(actual_points, points);
   
    wp4 = new Waypoint(new Vector2f(3,4), 1, wp2);
    wp5 = new Waypoint(new Vector2f(2,4), 0);
   
    assertTrue(wp1.equals(wp1));
    assertTrue(wp1.equals(wp4));
    assertFalse(wp1.equals(wp2));
    assertFalse(wp1.equals(wp5));   
   
   
  }
View Full Code Here


  }
 
  @Test
  public void testPriorityNode()
  {
    Waypoint wp1,wp2,wp3,wp4;
    wp1 = new Waypoint(new Vector2f(1, 1), 1);
    wp2 = new Waypoint(new Vector2f(2, 2), 2);
    wp3 = new Waypoint(new Vector2f(3, 3), 3);
    wp4 = new Waypoint(new Vector2f(4, 4), 4);
   
    PriorityNode n1, n2, n3, n4;
    n1 = new PriorityNode(2, wp1);
     
    assertNotNull(n1);
View Full Code Here

 
  @Test
  public void testPriorityQueueInsert() throws EmptyListException
  {
    PriorityQueue pq = new PriorityQueue();
    Waypoint wp1, wp2, wp3, wp4, wp5;
    wp1 = new Waypoint(new Vector2f(1,1), 1);
    wp2 = new Waypoint(new Vector2f(2,2), 2);
    wp3 = new Waypoint(new Vector2f(3,3), 3);
    wp4 = new Waypoint(new Vector2f(4,4), 4);
    wp5 = new Waypoint(new Vector2f(5,5), 5);
   
    pq.insert(wp2, 2);
    assertFalse(pq.isEmpty());
    pq.insert(wp4, 4);
    assertFalse(pq.isEmpty());
View Full Code Here

 
  @Test
  public void testPriorityQueueDublicates() throws EmptyListException
  {
    PriorityQueue pq = new PriorityQueue();
    Waypoint wp1, wp2, wp3;
    wp1 = new Waypoint(new Vector2f(1,1), 1);
    wp2 = new Waypoint(new Vector2f(2,2), 2);
    wp3 = new Waypoint(new Vector2f(3,3), 3);
   
    pq.insert(wp1, 10);
    pq.insert(wp1, 9);
    pq.insert(wp2, 8);
    pq.insert(wp2, 7);
View Full Code Here

    boolean routeFound = false;

    PriorityQueue openlist = new PriorityQueue();
    Vector<Waypoint> closedlist = new Vector<Waypoint>();

    Waypoint wp_to = new Waypoint(mc_to,0);
    Waypoint currentWP;

    Vector<Waypoint> newWaypoints;

    //System.err.println("Fuege Punkt to zu openlist hinzu: " + to.toString());
    openlist.insert(wp_to, 0);

    do{
      //System.err.println(openlist.toString());

      currentWP = openlist.getFirst();
      //System.err.println("Hole Node von der openlist: " + currentWP.toString());


      //if (currentWP.getVector2f().equals(from))
      if (currentWP.getVector2f().isInRange(mc_from, 0.707f))
      {
        System.out.println("Weg gefunden!!");
        routeFound = true;
        break;
      }

      closedlist.add(currentWP);

      // Expand Node
      Vector2f currentpoint = currentWP.getVector2f();

      newWaypoints = new Vector<Waypoint>(8);

      //8er Nachbarschaft hinzufuegen
      newWaypoints.add(new Waypoint(new Vector2f(currentpoint.x()-1 , currentpoint.y()-1 ),   Math.sqrt(2,currentWP));
      newWaypoints.add(new Waypoint(new Vector2f(currentpoint.x()-1 , currentpoint.y() ),     1      ,currentWP));
      newWaypoints.add(new Waypoint(new Vector2f(currentpoint.x()-1 , currentpoint.y()+1 ),   Math.sqrt(2,currentWP));
      newWaypoints.add(new Waypoint(new Vector2f(currentpoint.x() , currentpoint.y()-1 ),     1      ,currentWP));
      newWaypoints.add(new Waypoint(new Vector2f(currentpoint.x() , currentpoint.y()+1 ),     1      ,currentWP));
      newWaypoints.add(new Waypoint(new Vector2f(currentpoint.x()+1 , currentpoint.y()-1 ),   Math.sqrt(2,currentWP));
      newWaypoints.add(new Waypoint(new Vector2f(currentpoint.x()+1 , currentpoint.y() ),     1      ,currentWP));
      newWaypoints.add(new Waypoint(new Vector2f(currentpoint.x()+1 , currentpoint.y()+1 ),   Math.sqrt(2,currentWP));

      //System.err.println("Alle punkte zum vektor hinzugefuegt");

      for(Waypoint wp : newWaypoints)
      {
        if ( (closedlist.contains(wp)) || (!map.isInMap(wp.getVector2f())) || (!map.isPassable(vehicletype, wp.getVector2f())) )
        {
          continue;
        }

        double estimatedDistance = wp.getDistance()+wp.getVector2f().getDistanceTo(mc_from);

        openlist.insert(wp, estimatedDistance);
      }

    }
    while (!openlist.isEmpty());

    if (routeFound)
    {   
      Vector<Vector2f> mc_wps = new Vector<Vector2f>();
      Vector<Vector2f> wc_waypoints = new Vector<Vector2f>();
      currentWP.getRouteList(mc_wps);
      for(Vector2f wp:mc_wps)
      {
        wc_waypoints.add(general.helperclasses.Math.mapToWorld(wp, map.getTilesize()));
      }
      wc_waypoints.remove(0);
View Full Code Here

TOP

Related Classes of general.datastructures.Waypoint

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.