View Javadoc
1   package org.woehlke.simulation.evolution.model;
2   
3   import java.io.Serializable;
4   
5   /**
6    * (C) 2006 - 2008 Thomas Woehlke.
7    * http://thomas-woehlke.de/p/simulated-evolution/
8    * @author Thomas Woehlke
9    * Date: 04.02.2006
10   * Time: 23:47:05
11   */
12  public class Point implements Serializable {
13  
14      private int x = 0;
15      private int y = 0;
16  
17      public Point(Point p) {
18          this.x = p.getX();
19          this.y = p.getY();
20      }
21  
22      public Point(int x, int y) {
23          this.x = x;
24          this.y = y;
25      }
26  
27      public int getX() {
28          return x;
29      }
30  
31      public void setX(int x) {
32          this.x = x;
33      }
34  
35      public int getY() {
36          return y;
37      }
38  
39      public void setY(int y) {
40          this.y = y;
41      }
42  
43      public void killNagative() {
44          if (y < 0) {
45              y *= -1;
46          }
47          if (x < 0) {
48              x *= -1;
49          }
50      }
51  
52      public void add(Point p) {
53          this.x += p.getX();
54          this.y += p.getY();
55      }
56  
57      public void normalize(Point p) {
58          this.x %= p.getX();
59          this.y %= p.getY();
60      }
61  
62      public Point[] getNeighbourhood(Point max){
63          Point neighbourhood[] = new Point[9];
64          int maxX = max.getX();
65          int maxY = max.getY();
66          neighbourhood[0]= new Point((this.x+maxX-1) % maxX,(this.y+maxY-1) % maxY);
67          neighbourhood[1]= new Point((this.x+maxX-1) % maxX,this.y);
68          neighbourhood[2]= new Point((this.x+maxX-1) % maxX,(this.y+maxY+1) % maxY);
69          neighbourhood[3]= new Point(this.x,(this.y+maxY-1) % maxY);
70          neighbourhood[4]= new Point(this.x,this.y);
71          neighbourhood[5]= new Point(this.x,(this.y+maxY+1) % maxY);
72          neighbourhood[6]= new Point((this.x+maxX+1) % maxX,(this.y+maxY-1) % maxY);
73          neighbourhood[7]= new Point((this.x+maxX+1) % maxX,this.y);
74          neighbourhood[8]= new Point((this.x+maxX+1) % maxX,(this.y+maxY+1) % maxY);
75          return neighbourhood;
76      }
77  }