Пример #1
0
        public bool HasContainment(RectanglePair rectanglePair)
        {
            if ((rectanglePair.rectangle1.xVertex1 <= rectanglePair.rectangle2.xVertex1 && rectanglePair.rectangle1.yVertex1 >= rectanglePair.rectangle2.yVertex1 && rectanglePair.rectangle1.xVertex2 >= rectanglePair.rectangle2.xVertex2 && rectanglePair.rectangle1.yVertex2 <= rectanglePair.rectangle2.yVertex2) || (rectanglePair.rectangle2.xVertex1 <= rectanglePair.rectangle1.xVertex1 && rectanglePair.rectangle2.yVertex1 >= rectanglePair.rectangle1.yVertex1 && rectanglePair.rectangle2.xVertex2 >= rectanglePair.rectangle1.xVertex2 && rectanglePair.rectangle2.yVertex2 <= rectanglePair.rectangle1.yVertex2))
                return true;

            return false;
        }
Пример #2
0
        public ActionResult CheckRectangles(string rectangle1Vertices,  string rectangle2Vertices)
        {
            RectanglePair rectanglePair = new RectanglePair(Newtonsoft.Json.JsonConvert.DeserializeObject<Rectangle>(rectangle1Vertices), Newtonsoft.Json.JsonConvert.DeserializeObject<Rectangle>(rectangle2Vertices));

            RectangleProperties pairProperties = new RectangleProperties();

            pairProperties.hasContainment = HasContainment(rectanglePair);
            pairProperties.hasAdjacency = (pairProperties.hasContainment ? HasAdjacency(rectanglePair, true) : HasAdjacency(rectanglePair));
            pairProperties.hasIntersection = (pairProperties.hasContainment ? false : HasIntersection(rectanglePair));

            rectanglePair.rectangleProperties = pairProperties;
            return Json(rectanglePair);
        }
Пример #3
0
 public bool HasAdjacency(RectanglePair rectanglePair, bool hasContainment = false)
 {
     if (!hasContainment)
     {
         //Right alignment
         if (rectanglePair.rectangle1.xVertex2 == rectanglePair.rectangle2.xVertex1 && ((rectanglePair.rectangle1.yVertex2 >= rectanglePair.rectangle2.yVertex2 && rectanglePair.rectangle1.yVertex2 <= rectanglePair.rectangle2.yVertex1) || (rectanglePair.rectangle1.yVertex1 >= rectanglePair.rectangle2.yVertex2 && rectanglePair.rectangle1.yVertex1 <= rectanglePair.rectangle2.yVertex1)))
         {
             return true;
         }
         //Top alignment
         else if (rectanglePair.rectangle1.yVertex1 == rectanglePair.rectangle2.yVertex2 && ((rectanglePair.rectangle1.xVertex2 >= rectanglePair.rectangle2.xVertex1 && rectanglePair.rectangle1.xVertex2 <= rectanglePair.rectangle2.xVertex2) || (rectanglePair.rectangle1.xVertex1 >= rectanglePair.rectangle2.xVertex1 && rectanglePair.rectangle1.xVertex1 <= rectanglePair.rectangle2.xVertex2)))
         {
             return true;
         }
         //Bottom alignment
         else if (rectanglePair.rectangle1.yVertex2 == rectanglePair.rectangle2.yVertex1 && ((rectanglePair.rectangle1.xVertex2 >= rectanglePair.rectangle2.xVertex1 && rectanglePair.rectangle1.xVertex2 <= rectanglePair.rectangle2.xVertex2) || (rectanglePair.rectangle1.xVertex1 >= rectanglePair.rectangle2.xVertex1 && rectanglePair.rectangle1.xVertex1 <= rectanglePair.rectangle2.xVertex2)))
         {
             return true;
         }
         return false;
     }
     //else we need to check the edges for alignment
     else
     {
         //Right alignment
         if (rectanglePair.rectangle1.xVertex2 == rectanglePair.rectangle2.xVertex2)
         {
             return true;
         }
         //Left alignment
         else if (rectanglePair.rectangle1.xVertex1 == rectanglePair.rectangle2.xVertex1)
         {
             return true;
         }
         //Top alignment
         else if (rectanglePair.rectangle1.yVertex1 == rectanglePair.rectangle2.yVertex1)
         {
             return true;
         }
         //Bottom alignment
         else if (rectanglePair.rectangle1.yVertex2 == rectanglePair.rectangle2.yVertex2)
         {
             return true;
         }
         return false;
     }
 }
Пример #4
0
 public bool HasIntersection(RectanglePair rectanglePair)
 {
     if (rectanglePair.rectangle1.xVertex1 < rectanglePair.rectangle2.xVertex2 && rectanglePair.rectangle1.xVertex2 > rectanglePair.rectangle2.xVertex1 && rectanglePair.rectangle1.yVertex1 > rectanglePair.rectangle2.yVertex2 && rectanglePair.rectangle1.yVertex2 < rectanglePair.rectangle2.yVertex1)
         return true;
     return false;
 }