Advertisement
iRedBull

Untitled

Nov 17th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. public class Rect {
  2. private double left, top, right, bottom;
  3. private static final double DEFAULT_SIZE = 0.5;
  4.  
  5. public Rect() {
  6. left = -DEFAULT_SIZE;
  7. top = DEFAULT_SIZE;
  8. right = DEFAULT_SIZE;
  9. bottom = -DEFAULT_SIZE;
  10. }
  11.  
  12. public Rect(double left, double top, double right, double bottom) {
  13. this.left = left;
  14. this.top = top;
  15. this.right = right;
  16. this.bottom = bottom;
  17. }
  18.  
  19. public void translateRect(double vx, double vy) {
  20. left += vx;
  21. top += vy;
  22. right += vx;
  23. bottom += vy;
  24. }
  25.  
  26. public void rotateRect90graus() {
  27. double halfWidth = this.getWidth() / 2;
  28. double halfHeight = this.getHeight() / 2;
  29. double cx = this.getXCenter();
  30. double cy = this.getYCenter();
  31.  
  32. left = cx - halfHeight;
  33. top = cy + halfWidth;
  34. right = cx + halfHeight;
  35. bottom = cy - halfWidth;
  36.  
  37. }
  38.  
  39. /*
  40. * public void rotateRect90graus() { left = this.getXCenter() -
  41. * (this.getHeight()/2); top = this.getYCenter() + (this.getWidth()/2);
  42. * right = this.getXCenter() + (this.getHeight()/2); bottom =
  43. * this.getYCenter() - (this.getWidth()/2); }
  44. */
  45.  
  46. public double getLeft() {
  47. return left;
  48. }
  49.  
  50. public double getRight() {
  51. return right;
  52. }
  53.  
  54. public double getTop() {
  55. return top;
  56. }
  57.  
  58. public double getBottom() {
  59. return bottom;
  60. }
  61.  
  62. public double getHeight() {
  63. return top - bottom;
  64. }
  65.  
  66. public double getWidth() {
  67. return right - left;
  68. }
  69.  
  70. public double getPerimeter() {
  71. double width = getWidth();
  72. double height = getHeight();
  73.  
  74. return (2 * width) + (2 * height);
  75. }
  76.  
  77. public double getArea() {
  78. return this.getWidth() * this.getHeight();
  79. }
  80.  
  81. public double getXCenter() {
  82. return left + (this.getWidth() / 2);
  83. }
  84.  
  85. public double getYCenter() {
  86. return bottom + (this.getHeight() / 2);
  87. }
  88.  
  89. public boolean ptInRect(double x, double y) {
  90. return x >= left && x <= right && y <= top && y >= bottom;
  91. }
  92.  
  93. public boolean rectInRect(Rect b) {
  94. return b.getLeft() >= left && b.getRight() <= right && b.getTop() <= top && b.getBottom() >= bottom;
  95. }
  96.  
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement