Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Rect
- {
- public class Rectangle
- {
- public double x, y;
- public double width, height;
- //Конструктор
- public Rectangle(double p_x, double p_y, double p_width, double p_height)
- {
- x = p_x; y = p_y; width = p_width; height = p_height;
- }
- //Проверка пересечения прямоугольника
- public bool Intersects(Rectangle r)
- {
- double a1 = this.x + this.width;
- double b1 = this.y + this.height;
- double a2 = r.x + r.width;
- double b2 = r.y + r.height;
- if (((b2 >= y) & (b1 >= r.y)) &
- (((r.x <= x) & (a2 >= x)) || ((r.x >= x) & (r.x <= a1))))
- {
- return true;
- }
- else return false;
- }
- //Данный прямоугольник содержит второй
- public bool Contains(Rectangle r)
- {
- if (((r.x >= x) & ((r.x + r.width) <= (x + width))) & ((r.y >= y) &
- (r.y + r.height) <= (y + height)))
- {
- return true;
- }
- else return false;
- }
- //Площадь данного п. больше, чем площадь второго
- public bool GreaterThan(Rectangle r)
- {
- double area1 = this.width * this.height;
- double area2 = r.width * r.height;
- return (area1 > area2);
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement