Advertisement
Guest User

Point in figure

a guest
Feb 10th, 2016
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.51 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 Point_in_Figure
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             // inputs
  14.             int h_scale = int.Parse(Console.ReadLine());
  15.             int x = int.Parse(Console.ReadLine());
  16.             int y = int.Parse(Console.ReadLine());
  17.  
  18.             // block definition (left,bottom,right,top)
  19.             int[,] blocks = new int[,]
  20.             {
  21.                 {0, 0, 3, 1},
  22.                 {1, 1, 2, 4}
  23.             };
  24.  
  25.             // apply scaling factor
  26.             for (int i = 0; i < blocks.Rank; i++)
  27.             {
  28.                 for (int j = 0; j < blocks.GetLength(1); j++)
  29.                 {
  30.                     blocks[i, j] *= h_scale;
  31.                 }
  32.             }
  33.  
  34.             string result = String.Empty;
  35.             // check each block
  36.             for (int i = 0; i < blocks.Rank; i++)
  37.             {
  38.                 if (x > blocks[i, 0] && x < blocks[i, 2] && y > blocks[i, 1] && y < blocks[i, 3])
  39.                 {
  40.                     result = "inside";
  41.                     break; // point was found inside a block -> break
  42.                 }
  43.                 else if (x < blocks[i, 0] || x > blocks[i, 2] || y < blocks[i, 1] || y > blocks[i, 3]) // point is outside
  44.                 {
  45.                     if (result != "border") // and is not border to previous rect
  46.                     {
  47.                         result = "outside";
  48.                     }  
  49.                 }
  50.                 else
  51.                 {
  52.                     if (result == "border")
  53.                     {
  54.                         // common SIDE -> either border or inside -> break
  55.                         if (x == blocks[i, 0] && y == blocks[i, 1] ||
  56.                             x == blocks[i, 0] && y == blocks[i, 3] ||
  57.                             x == blocks[i, 2] && y == blocks[i, 1] ||
  58.                             x == blocks[i, 2] && y == blocks[i, 3]
  59.                             )
  60.                         {
  61.                             result = "border"; // vertex -> border
  62.                         }
  63.                         else
  64.                         {
  65.                             result = "inside"; // segment -> inside
  66.                         }
  67.                         break;
  68.                     }
  69.                     result = "border";
  70.                 }
  71.             }
  72.  
  73.             Console.WriteLine(result);
  74.         }
  75.     }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement