public void IntersectConvexTest() { var intersect = Intersector.IntersectConvex(m_diamond, m_squarePoly); Assert.AreEqual(0.5f, intersect.Area); Assert.Throws <GeomException>(() => Intersector.IntersectConvex(m_diamond, m_arrow)); }
/// <summary> /// Calculates total area owned by each player separately. /// </summary> private void UpdatePlayerAreaOwned() { m_playerArea = new float[2] { 0, 0 }; foreach (var inputNode in m_delaunay.Vertices) { // get dcel face containing input node var face = m_DCEL.GetContainingFace(inputNode); if (m_ownership[inputNode] != EOwnership.UNOWNED) { // update player area with face that intersects with window var playerIndex = m_ownership[inputNode] == EOwnership.PLAYER1 ? 0 : 1; m_playerArea[playerIndex] += Intersector.IntersectConvex(m_meshRect, face.Polygon.Outside).Area; } } // update GUI to reflect new player area owned m_GUIManager.SetPlayerAreaOwned(m_playerArea[0], m_playerArea[1]); }
/// <summary> /// Find cut line through the intersection of dcel faces. /// Each dcel face is bounded by lines in the dual plane, representing the points to separate equally. /// </summary> /// <param name="a_region1"></param> /// <param name="a_region2"></param> /// <param name="a_region3"></param> /// <returns></returns> public static List <Line> FindCutlinesInDual(List <Face> a_region1, List <Face> a_region2, List <Face> a_region3) { a_region1.Sort((f1, f2) => f1.BoundingBox().xMin.CompareTo(f2.BoundingBox().xMin)); a_region2.Sort((f1, f2) => f1.BoundingBox().xMin.CompareTo(f2.BoundingBox().xMin)); a_region3.Sort((f1, f2) => f1.BoundingBox().xMin.CompareTo(f2.BoundingBox().xMin)); var region1 = a_region1.Select(x => x.Polygon.Outside).ToList(); var region2 = a_region2.Select(x => x.Polygon.Outside).ToList(); var region3 = a_region3.Select(x => x.Polygon.Outside).ToList(); var intermediateList = new List <Polygon2D>(); //Intersect first two lists var list1index = 0; var list2index = 0; while (list1index < region1.Count && list2index < region2.Count) { //progress trough y coordinates var intersection = Intersector.IntersectConvex(region1[list1index], region2[list2index]); if (intersection != null) { intermediateList.Add(intersection); } if (region2[list2index].BoundingBox().xMax < region1[list1index].BoundingBox().xMax) { list2index++; } else { list1index++; } } var result = new List <Polygon2D>(); //Intersect intermediate list and last list var intermediateIndex = 0; var list3index = 0; while (intermediateIndex < intermediateList.Count && list3index < region3.Count) { //progress trough y coordinates var intersection = Intersector.IntersectConvex(intermediateList[intermediateIndex], region3[list3index]); if (intersection != null) { result.Add(intersection); } if (region3[list3index].BoundingBox().xMax < intermediateList[intermediateIndex].BoundingBox().xMax) { list3index++; } else { intermediateIndex++; } } //Convert polygons to lines return(FindCutLinesInDual(result)); }