Advertisement
Aborigenius

RectangleInside

Aug 19th, 2017
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.59 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 Rectangle
  8. {
  9.  
  10.  
  11.     class Program
  12.     {
  13.         static void Main(string[] args)
  14.         {
  15.             Rectangle r1 = ReadRectangle(), r2 = ReadRectangle();
  16.             Console.WriteLine(r1.IsInside(r2) ? "Inside" :
  17.               "Not inside");
  18.  
  19.         }
  20.  
  21.         public static Rectangle ReadRectangle()
  22.         {
  23.             var sizes = Console.ReadLine().Split().Select(int.Parse);
  24.             Rectangle rectangle = new Rectangle()
  25.             {
  26.                 Left = sizes.First(),
  27.                 Top = sizes.Skip(1).First(),
  28.                 Width = sizes.Skip(2).First(),
  29.                 Height = sizes.Skip(3).First()
  30.             };
  31.             return rectangle;
  32.         }
  33.     }
  34.     public class Rectangle
  35.     {
  36.         public int Top { get; set; }
  37.         public int Left { get; set; }
  38.         public int Width { get; set; }
  39.         public int Height { get; set; }
  40.  
  41.         public int Right { get { return Left + Width; } }
  42.         public int Bottom { get { return Top + Height; } }
  43.         public bool IsInside(Rectangle other)
  44.         {
  45.             var isInLeft = Left >= other.Left;
  46.             var isInRight = Right <= other.Right;
  47.             var isInsideHorizontal = isInLeft && isInRight;
  48.             var isInTop = Top >= other.Top;
  49.             var isInBottom = Bottom <= other.Bottom;
  50.             var isInsideVertical = isInTop && isInBottom;
  51.             return isInsideHorizontal && isInsideVertical;
  52.         }
  53.  
  54.  
  55.     }
  56.  
  57.  
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement