Guest User

Untitled

a guest
Jun 23rd, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.01 KB | None | 0 0
  1. using System;
  2. using System.Diagnostics;
  3. using System.Drawing;
  4. using System.Collections.Generic;
  5.  
  6. namespace Identifier
  7. {
  8.     public static class Points
  9.     {
  10.         private static bool ContainsPoint(Point p, Point[] pts)
  11.         {
  12.             foreach (Point pp in pts)
  13.             {
  14.                 if (pp.X == p.X && pp.Y == p.Y)
  15.                 {
  16.                     return true;
  17.                 }
  18.             }
  19.             return false;
  20.         }
  21.        
  22.         private static bool PointsInPoints(Point[] a, Point[] b)
  23.         {
  24.             foreach (Point p in a)
  25.             {
  26.                 if (!ContainsPoint(p, b))
  27.                     return false;
  28.             }
  29.             return true;
  30.         }
  31.        
  32.         private static bool Unique(Point[] a, Point[][] b, int skip)
  33.         {
  34.             for(int i = 0; i < b.Length; i++)
  35.             {
  36.                 if (i <= skip) {
  37.                     continue;  
  38.                 }
  39.                 if (PointsInPoints(a, b[i]))
  40.                     return false;
  41.             }
  42.             return true;
  43.         }
  44.        
  45.         public static bool TPAsEqual(Point[] a, Point[] b)
  46.         {
  47.             if (a.Length == b.Length)
  48.             {
  49.                 for (int i = 0; i < a.Length; i++)
  50.                 {
  51.                     if (!(a[i].X == b[i].X && a[i].Y == b[i].Y))
  52.                         return false;
  53.                 }
  54.                 return true;
  55.             }
  56.             return false;
  57.         }
  58.        
  59.         public static Point[] FindUniqueSet(Point[] arr, Point[][] total, int max, int skip)
  60.         {
  61.             for (int i = 1; i < max; i++)
  62.             {
  63.                 Combination<Point> c = new Combination<Point>(arr, i);
  64.                 int cc = 0;
  65.                 foreach (Point[] pts in c)
  66.                 {
  67.                     if (Unique(pts, total, skip))
  68.                     {
  69.                         Debug.WriteLine("Succesful Combination - Length: "+pts.Length);
  70.                         foreach (Point p in pts)
  71.                         {
  72.                             Debug.WriteLine("--> X: "+p.X+ " "+" Y: "+p.Y);
  73.                         }
  74.                         return pts;
  75.                     }
  76.                     cc++;
  77.                     if (cc > 50)
  78.                         break;
  79.                 }
  80.             }
  81.             return new Point[] {};
  82.         }
  83.        
  84.         private static Point[] Crop(Point[] p)
  85.         {
  86.             int minX = p[0].X;
  87.             int minY = p[0].Y;
  88.             foreach (Point point in p)
  89.             {
  90.                 if (point.X < minX)
  91.                     minX = point.X;
  92.                 if (point.Y < minY)
  93.                     minY = point.Y;
  94.             }
  95.             List<Point> n = new List<Point>();
  96.             foreach (Point point in p)
  97.             {
  98.                 n.Add(new Point(point.X - minX, point.Y - minY));
  99.             }
  100.             return n.ToArray();
  101.         }
  102.     }
  103. }
Add Comment
Please, Sign In to add comment