Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import com.runemate.game.api.hybrid.entities.details.Locatable;
- import com.runemate.game.api.hybrid.location.Area;
- import com.runemate.game.api.hybrid.location.Coordinate;
- import com.runemate.game.api.hybrid.util.calculations.Distance;
- import java.util.Arrays;
- import java.util.List;
- /**
- * Created by Viewer on 24/05/2015.
- */
- public class AbsoluteArea extends Area {
- private Coordinate[] coordinates;
- public AbsoluteArea(Coordinate[] coordinates) {
- for (int i = 0; i < coordinates.length - 1; i++) {
- if (Distance.between(coordinates[i], coordinates[i + 1]) >= 2) {
- try {
- throw new Exception("Each coordinate must be contiguous to atleast one another in the array");
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
- this.coordinates = coordinates;
- }
- public boolean contains(Locatable locatable) {
- if (locatable != null) {
- for (Coordinate c : coordinates) {
- if (locatable.getPosition().equals(c)) {
- return true;
- }
- }
- }
- return false;
- }
- private Coordinate getNorthwestern() {
- Coordinate northwestern = null;
- int x = Integer.MAX_VALUE, y = Integer.MAX_VALUE;
- for (Coordinate c : coordinates) {
- if (c.getX() < x && c.getY() < y) {
- northwestern = c;
- x = c.getX();
- y = c.getY();
- }
- }
- return northwestern;
- }
- private Coordinate getSouthwestern() {
- Coordinate southwestern = null;
- int x = 0, y = 0;
- for (Coordinate c : coordinates) {
- if (c.getX() > x && c.getY() > y) {
- southwestern = c;
- x = c.getX();
- y = c.getY();
- }
- }
- return southwestern;
- }
- @Override
- public String toString() {
- return null;
- }
- @Override
- public List<Coordinate> getCoordinates() {
- return Arrays.asList(coordinates);
- }
- @Override
- public Rectangular toRectangular() {
- return new Area.Rectangular(getNorthwestern(), getSouthwestern());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement