001package org.woehlke.simulation.cyclic.cellular.automaton.model;
002
003import java.io.Serializable;
004
005/**
006 * (C) 2006 - 2013 Thomas Woehlke.
007 * http://thomas-woehlke.de/p/cyclic-cellular-automaton/
008 * @author Thomas Woehlke
009 * Date: 04.02.2006
010 * Time: 23:47:05
011 */
012public class Point implements Serializable {
013
014    private int x = 0;
015    private int y = 0;
016
017    public Point(Point p) {
018        this.x = p.getX();
019        this.y = p.getY();
020    }
021
022    public Point(int x, int y) {
023        this.x = x;
024        this.y = y;
025    }
026
027    public int getX() {
028        return x;
029    }
030
031    public void setX(int x) {
032        this.x = x;
033    }
034
035    public int getY() {
036        return y;
037    }
038
039    public void setY(int y) {
040        this.y = y;
041    }
042
043    public void killNagative() {
044        if (y < 0) {
045            y *= -1;
046        }
047        if (x < 0) {
048            x *= -1;
049        }
050    }
051
052    public void add(Point p) {
053        this.x += p.getX();
054        this.y += p.getY();
055    }
056
057    public void normalize(Point p) {
058        this.x %= p.getX();
059        this.y %= p.getY();
060    }
061
062    public Point[] getNeighbourhood(Point max){
063        Point neighbourhood[] = new Point[9];
064        int maxX = max.getX();
065        int maxY = max.getY();
066        neighbourhood[0]= new Point((this.x+maxX-1) % maxX,(this.y+maxY-1) % maxY);
067        neighbourhood[1]= new Point((this.x+maxX-1) % maxX,this.y);
068        neighbourhood[2]= new Point((this.x+maxX-1) % maxX,(this.y+maxY+1) % maxY);
069        neighbourhood[3]= new Point(this.x,(this.y+maxY-1) % maxY);
070        neighbourhood[4]= new Point(this.x,this.y);
071        neighbourhood[5]= new Point(this.x,(this.y+maxY+1) % maxY);
072        neighbourhood[6]= new Point((this.x+maxX+1) % maxX,(this.y+maxY-1) % maxY);
073        neighbourhood[7]= new Point((this.x+maxX+1) % maxX,this.y);
074        neighbourhood[8]= new Point((this.x+maxX+1) % maxX,(this.y+maxY+1) % maxY);
075        return neighbourhood;
076    }
077}