Ejemplo n.º 1
0
 internal graphPoint GetInvert(graphPoint graphPoint)
 {
     return p1 == graphPoint ? p2 : p1;
 }
Ejemplo n.º 2
0
 internal graphLine GetRightEdge(graphPoint curr)
 {
     var prev = GetInvert(curr);
      float minAngle = float.PositiveInfinity;
      graphLine nextEdge = null;
      foreach (var edge in curr.links)
      {
          if (edge == this)
              continue;
          var next = edge.GetInvert(curr);
          var angleClockwise = rightAngle(prev.point, curr.point, next.point);
          if (angleClockwise < minAngle)
          {
              minAngle = angleClockwise;
              nextEdge = edge;
          }
      }
      return nextEdge;
 }
Ejemplo n.º 3
0
        /// Проверяет факт пересечения, и возвращает помеченные ребра, если пересечение есть
        private static bool _detectIntersectionsIfNeed(graphLine a, graphLine b, out graphLine[] aOut, out graphLine[] bOut)
        {
            var a1 = a.p1.point;
             var a2 = a.p2.point;
             var b1 = b.p1.point;
             var b2 = b.p2.point;

             Vector2 cross;
             if (m.intersect.trySegments(a1, a2, b1, b2, false, out cross))
             {
                 var B1_isRight_of_A1A2 = isRight(a1, a2, b1);
                 var A1_isRight_of_B1B2 = isRight(b1, b2, a1);

                 float z;
                 if (a1.z != 0 && a2.z != 0)
                 {
                     var fullDistance = ((Vector2) a2 - (Vector2) a1).magnitude;
                     var partDistance = (cross - (Vector2) a1).magnitude;
                     var t = partDistance/fullDistance;
                     z = Mathf.Lerp(a1.z, a2.z, t);
                 }
                 else z = 0f;

                 var crossEx = new graphPoint(new Vector3(cross.x, cross.y, z), true);
                 aOut = a.Split(crossEx);
                 bOut = b.Split(crossEx);

                 aOut[0].b = A1_isRight_of_B1B2;
                 aOut[1].b = !A1_isRight_of_B1B2;

                 bOut[0].a = B1_isRight_of_A1A2;
                 bOut[1].a = !B1_isRight_of_A1A2;
                 return true;
             }
             aOut = null;
             bOut = null;
             return false;
        }
Ejemplo n.º 4
0
 /// Разделить текущее ребро на два, очистив при этом инфу о текущем ребре
 internal graphLine[] Split(graphPoint graphPoint)
 {
     var edge1 = new graphLine { a = a, b = b};
      var edge2 = new graphLine { a = a, b = b };
      edge1.p1 = p1;
      edge1.p2 = graphPoint;
      edge2.p1 = graphPoint;
      edge2.p2 = p2;
      p1 = null;
      p2 = null;
      edge1.aMain = aMain;
      edge2.aMain = aMain;
      return new[] { edge1, edge2 };
 }
Ejemplo n.º 5
0
 private static graphPoint MaxYItem(graphPoint[] ps)
 {
     var max = float.NegativeInfinity;
      graphPoint maxItem = null;
      for (int i = 0; i < ps.Length; i++)
      {
          var point = ps[i].point;
          if (point.y > max)
          {
              max = point.y;
              maxItem = ps[i];
          }
      }
      return maxItem;
 }