Files
runelite/runelite-api/src/main/java/net/runelite/api/Point.java
2018-05-25 13:16:12 -04:00

114 lines
2.6 KiB
Java

/*
* Copyright (c) 2017, Adam <Adam@sigterm.info>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.runelite.api;
/**
* A two-dimensional coordinate on the canvas.
*/
public class Point
{
private final int x;
private final int y;
public Point(int x, int y)
{
this.x = x;
this.y = y;
}
@Override
public String toString()
{
return "Point{" + "x=" + x + ", y=" + y + '}';
}
/**
* Gets the x-axis coordinate of the point.
*
* @return the x-axis coordinate
*/
public int getX()
{
return x;
}
/**
* Gets the y-axis coordinate of the point.
*
* @return the y-axis coordinate
*/
public int getY()
{
return y;
}
/**
* Gets the distance between this point and another.
*
* @param other other point
* @return the distance
*/
public int distanceTo(Point other)
{
return (int) Math.hypot(getX() - other.getX(), getY() - other.getY());
}
@Override
public int hashCode()
{
int hash = 3;
hash = 23 * hash + this.x;
hash = 23 * hash + this.y;
return hash;
}
@Override
public boolean equals(Object obj)
{
if (this == obj)
{
return true;
}
if (obj == null)
{
return false;
}
if (getClass() != obj.getClass())
{
return false;
}
final Point other = (Point) obj;
if (this.x != other.x)
{
return false;
}
if (this.y != other.y)
{
return false;
}
return true;
}
}