package org.vostan.banvor.model;

import static java.lang.Math.abs;

public class XYPair
{
    public static final XYPair UP = new XYPair(0, 1);
    public static final XYPair DOWN = new XYPair(0, -1);
    public static final XYPair LEFT = new XYPair(-1, 0);
    public static final XYPair RIGHT = new XYPair(1, 0);
    public static final XYPair ZERO = new XYPair(0, 0);
    private int _x = 0;
    private int _y = 0;

    public XYPair(){
        _x = 0;
        _y = 0;
    }

    public XYPair(int x, int y){
        _x = x;
        _y = y;
    }

    public XYPair(XYPair op){
        _x = op.x();
        _y = op.y();
    }

    public final int x(){
        return _x;
    }

    public final int y(){
        return _y;
    }

    public void set(int x, int y){
        _x = x;
        _y = y;
    }

    public void set(XYPair xy){
        _x = xy.x();
        _y = xy.y();
    }

    public static XYPair add(XYPair op1, XYPair op2){
        return new XYPair(op1._x+op2._x, op1._y+op2._y);
    }

    public static XYPair sub(XYPair op1, XYPair op2){
        return new XYPair(op1._x-op2._x, op1._y-op2._y);
    }

    public static XYPair mul(XYPair op1, int scaliar){
        return new XYPair(op1._x*scaliar, op1._y*scaliar);
    }

    public final XYPair mul(int scaliar){
        return mul(this, scaliar);
    }

    public final XYPair sub(XYPair op){
        return sub(this, op);
    }

    public final XYPair add(XYPair op){
        return add(this, op);
    }

    public final int l1_norm(){
        return abs(_x)+abs(_y);
    }

    public final boolean isEqual(XYPair op){
        return _x == op._x && _y == op._y;
    }

    public final boolean isInside(XYPair op1, XYPair op2){
        return op1.x() <= this.x() && this.x() < op2.x()
                && op1.y() <= this.y() && this.y() < op2.y();
    }

    public final XYPair left(){
        return this.add(LEFT);
    }

    public final XYPair right(){
        return this.add(RIGHT);
    }

    public final XYPair up(){
        return this.add(UP);
    }

    public final XYPair down(){
        return this.add(DOWN);
    }
}
