package ca.recrown.islandsurvivalcraft.utilities.datatypes;

import java.util.Objects;

public class Point2 {
    public final int x, y;
    private final int hash;

    public Point2(int x, int y) {
        this.x = x;
        this.y = y;
        this.hash = Objects.hash(x, y);
    }

    @Override
    public boolean equals(Object obj) {
        if (obj instanceof Point2) {
            Point2 p = (Point2) obj;
            return p.x == this.x && p.y == this.y;
        }
        return false;
    }

    public boolean fastEquals(Point2 point) {
        return point.hashCode() == this.hash && x == point.x && y == point.y;
    }

    @Override
    public int hashCode() {
        return hash;
    }

    @Override
    public String toString() {
        return String.format("(%d, %d)", x, y);
    }
}