_point_set.c
上传用户:gzelex
上传日期:2007-01-07
资源大小:707k
文件大小:2k
开发平台:

MultiPlatform

  1. /*******************************************************************************
  2. +
  3. +  LEDA-R  3.2.3
  4. +
  5. +  _point_set.c
  6. +
  7. +  Copyright (c) 1995  by  Max-Planck-Institut fuer Informatik
  8. +  Im Stadtwald, 66123 Saarbruecken, Germany     
  9. +  All rights reserved.
  10. *******************************************************************************/
  11. #include <LEDA/point_set.h>
  12. #include <LEDA/d2_dictionary.h>
  13. typedef d2_dictionary<double,double,DT_item>* d2_dic_ptr;
  14. #define TTT (*d2_dic_ptr(ptr))
  15. ps_item  Point_Set::insert(point p, void* i) 
  16. { ps_item it = delaunay_tree::insert(p,i);
  17.   TTT.insert(p.xcoord(),p.ycoord(),it);
  18.   return it;
  19.  }
  20. list<point> Point_Set::all_points()
  21. { list<point> result;
  22.   list<ps_item>  L = all_items();
  23.   ps_item it;
  24.   forall(it,L) result.append(key(it));
  25.   return result;
  26. }
  27. ps_item Point_Set::lookup(point p)
  28. { double    x  = p.xcoord();
  29.   double    y  = p.ycoord();
  30.   dic2_item it = TTT.lookup(x,y);
  31.   return (it!=nil) ? TTT.inf(it) : nil;
  32. }
  33. list<ps_item> Point_Set::range_search(double x0, double x1, double y0, double y1)
  34. {
  35.   list<dic2_item> Lr = TTT.range_search(x0,x1,y0,y1);
  36.   list<ps_item> Lp;
  37.   dic2_item it;
  38.   forall(it,Lr) Lp.append(TTT.inf(it));
  39.   return Lp;
  40. }
  41. list<ps_item> Point_Set::all_items()          
  42. { list<DT_item> L; 
  43.   delaunay_tree::all_items(L); 
  44.   return *(list<ps_item>*)&L;
  45.  }
  46. list<ps_item> Point_Set::convex_hull()
  47. { list<DT_item> L; 
  48.   delaunay_tree::convex_hull(L);
  49.   return *(list<ps_item>*)&L;
  50.  }
  51. void Point_Set::del(point p)
  52. { delaunay_tree::del(p);
  53.   TTT.del(p.xcoord(),p.ycoord());
  54.  }
  55. void Point_Set::clear() { TTT.clear(); delaunay_tree::clear();  }
  56. int  Point_Set::size()  { return TTT.size(); }
  57. Point_Set::Point_Set()  { ptr = new d2_dictionary<double,double,DT_item>; }
  58. Point_Set::~Point_Set() { delete d2_dic_ptr(ptr); }