Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2016
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. public boolean isPolygonSquare(RSTile[] array) {
  2.  
  3. //we will check if it has atleast 4 points
  4. if (array.length != 4) {
  5. return false;
  6. }
  7. // we will now simply calculate the centre of the square.
  8. int totalX = 0;
  9. int totalY = 0;
  10. // I'm going to store them as seperate ints for future reference upon expansion
  11.  
  12. for (RSTile tile : array) {
  13. totalX = totalX + tile.getX();
  14. totalY = totalY + tile.getY();
  15. }
  16.  
  17. //I'm assuming plane is 0 at this point, I'll edit this later
  18. RSTile centreTile = new RSTile(totalX / array.length, totalY / array.length, 0);
  19.  
  20. // we are going to check if all points are equal to the same distance
  21. int distance = -1;
  22. for (RSTile tile: array) {
  23. if (distance < 0{
  24. if (distance != centreTile.distanceTo(tile)){
  25. return false;
  26. }
  27. } else {
  28. distance = centreTile.distanceTo(tile);
  29. }
  30. }
  31. //return true since it surpassed all checks
  32. return true;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement