Advertisement
Guest User

Untitled

a guest
May 24th, 2015
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.29 KB | None | 0 0
  1. import com.runemate.game.api.hybrid.entities.details.Locatable;
  2. import com.runemate.game.api.hybrid.location.Area;
  3. import com.runemate.game.api.hybrid.location.Coordinate;
  4. import com.runemate.game.api.hybrid.util.calculations.Distance;
  5.  
  6. import java.util.Arrays;
  7. import java.util.List;
  8.  
  9. /**
  10.  * Created by Viewer on 24/05/2015.
  11.  */
  12. public class AbsoluteArea extends Area {
  13.  
  14.     private Coordinate[] coordinates;
  15.  
  16.     public AbsoluteArea(Coordinate[] coordinates) {
  17.         for (int i = 0; i < coordinates.length - 1; i++) {
  18.             if (Distance.between(coordinates[i], coordinates[i + 1]) >= 2) {
  19.                 try {
  20.                     throw new Exception("Each coordinate must be contiguous to atleast one another in the array");
  21.                 } catch (Exception e) {
  22.                     e.printStackTrace();
  23.                 }
  24.             }
  25.         }
  26.         this.coordinates = coordinates;
  27.     }
  28.  
  29.     public boolean contains(Locatable locatable) {
  30.         if (locatable != null) {
  31.             for (Coordinate c : coordinates) {
  32.                 if (locatable.getPosition().equals(c)) {
  33.                     return true;
  34.                 }
  35.             }
  36.         }
  37.         return false;
  38.     }
  39.  
  40.     private Coordinate getNorthwestern() {
  41.         Coordinate northwestern = null;
  42.         int x = Integer.MAX_VALUE, y = Integer.MAX_VALUE;
  43.         for (Coordinate c : coordinates) {
  44.             if (c.getX() < x && c.getY() < y) {
  45.                 northwestern = c;
  46.                 x = c.getX();
  47.                 y = c.getY();
  48.             }
  49.         }
  50.         return northwestern;
  51.     }
  52.  
  53.     private Coordinate getSouthwestern() {
  54.         Coordinate southwestern = null;
  55.         int x = 0, y = 0;
  56.         for (Coordinate c : coordinates) {
  57.             if (c.getX() > x && c.getY() > y) {
  58.                 southwestern = c;
  59.                 x = c.getX();
  60.                 y = c.getY();
  61.             }
  62.         }
  63.         return southwestern;
  64.     }
  65.  
  66.     @Override
  67.     public String toString() {
  68.         return null;
  69.     }
  70.  
  71.     @Override
  72.     public List<Coordinate> getCoordinates() {
  73.         return Arrays.asList(coordinates);
  74.     }
  75.  
  76.     @Override
  77.     public Rectangular toRectangular() {
  78.         return new Area.Rectangular(getNorthwestern(), getSouthwestern());
  79.     }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement