Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public boolean isPolygonSquare(RSTile[] array) {
- //we will check if it has atleast 4 points
- if (array.length != 4) {
- return false;
- }
- // we will now simply calculate the centre of the square.
- int totalX = 0;
- int totalY = 0;
- // I'm going to store them as seperate ints for future reference upon expansion
- for (RSTile tile : array) {
- totalX = totalX + tile.getX();
- totalY = totalY + tile.getY();
- }
- //I'm assuming plane is 0 at this point, I'll edit this later
- RSTile centreTile = new RSTile(totalX / array.length, totalY / array.length, 0);
- // we are going to check if all points are equal to the same distance
- int distance = -1;
- for (RSTile tile: array) {
- if (distance < 0{
- if (distance != centreTile.distanceTo(tile)){
- return false;
- }
- } else {
- distance = centreTile.distanceTo(tile);
- }
- }
- //return true since it surpassed all checks
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement