Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Rect
  8. {
  9. public class Rectangle
  10. {
  11. public double x, y;
  12. public double width, height;
  13.  
  14. //Конструктор
  15. public Rectangle(double p_x, double p_y, double p_width, double p_height)
  16. {
  17. x = p_x; y = p_y; width = p_width; height = p_height;
  18. }
  19.  
  20. //Проверка пересечения прямоугольника
  21. public bool Intersects(Rectangle r)
  22. {
  23. double a1 = this.x + this.width;
  24. double b1 = this.y + this.height;
  25. double a2 = r.x + r.width;
  26. double b2 = r.y + r.height;
  27.  
  28. if (((b2 >= y) & (b1 >= r.y)) &
  29. (((r.x <= x) & (a2 >= x)) || ((r.x >= x) & (r.x <= a1))))
  30. {
  31. return true;
  32.  
  33. }
  34. else return false;
  35. }
  36.  
  37. //Данный прямоугольник содержит второй
  38. public bool Contains(Rectangle r)
  39. {
  40. if (((r.x >= x) & ((r.x + r.width) <= (x + width))) & ((r.y >= y) &
  41. (r.y + r.height) <= (y + height)))
  42. {
  43. return true;
  44. }
  45. else return false;
  46. }
  47.  
  48. //Площадь данного п. больше, чем площадь второго
  49. public bool GreaterThan(Rectangle r)
  50. {
  51. double area1 = this.width * this.height;
  52. double area2 = r.width * r.height;
  53. return (area1 > area2);
  54. }
  55. }
  56. class Program
  57. {
  58. static void Main(string[] args)
  59. {
  60.  
  61. }
  62. }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement