class Points – the code

class Points{
  Point[] points;
  
  Points(){
    points=new Point[0];
  }
  
  Point find(int i){                                    // return point with given index
    return points[i];
  }
  
  Point find(Vector v){                                 // return Point with given vector if exists
    for (int i=0;i<points.length;i++){
      if(points[i].isAt(v)) return points[i];
    }
    Point nothing=null;
    return nothing;
  }
  
  void add(Point p){
    points=(Point[])(append(points,p));
  }
  
  //  for a given vector search for the point or create one, add and return the point
  
  Point findOrCreate(Vector v){
    Point p=find(v);
    if (p==null) {
    p=new Point(v);
    add(p);
    }
    return p;
  }
  
  void show(){
    for (int i=0;i<points.length;i++){
      points[i].show();
    }
  }
  
  void sortConnections(){
    for (int i=0;i<points.length;i++){
      points[i].sortConnections();
    }
  }
  
  void eliminateUndefinedConnections(){
    for (int i=0;i<points.length;i++){
      points[i].eliminateUndefinedConnections();
    }
  }

  void makePolygons(Polygons polygons){
    for (int i=0;i<points.length;i++){
      points[i].makePolygons(polygons);
    }
  }


  void setToCenterOfPolygon(){
    for (int i=0;i<points.length;i++){
      points[i].setToCenterOfPolygon();
    }
  }
  
// finds the point, where we start with finding the coordinates of the dual tiling
  Point closestToOrigin(){        
    float dminSq=1e10,dSq;
    Vector vec;
    int i,imin=-1;
    for (i=0;i<points.length;i++){
      vec=points[i].vec;
      dSq=sq(vec.x)+sq(vec.y);
      if(dSq<dminSq){
        dminSq=dSq;
        imin=i;
      }
    }
    return points[imin];
  }
  
  // for showing results ....
  
  Vector center(){
    Vector result=new Vector(0.,0.);
      for (int i=0;i<points.length;i++){
        result.add(points[i].vec);
      }
    result.mult(1./float(points.length));
    return result;
  }
  
  //  largest component of point vectors
  float maxComponent(){
    float result=0;
    for (int i=0;i<points.length;i++){
      result=max(result,abs(points[i].vec.x),abs(points[i].vec.y));
    }
    return result;
  }
  
  // scale points to scale the grid as needed
    void mult(float s){
    for (int i=0;i<points.length;i++){
      if(points[i].vec!=null) points[i].vec.mult(s); 
    }
  }

  // translate points as needed
    void translation(Vector v){
    for (int i=0;i<points.length;i++){
      if(points[i].vec!=null) points[i].vec.add(v); 
    }
  }
}
This entry was posted in programming, Uncategorized and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s