Exemplo n.º 1
0
        public static void CombineCloseAngles(List <Line> lines, double maxAngle)
        {
            if (maxAngle == 0)
            {
                return;
            }

            while (true)
            {
                bool changed = false;
                for (int a = lines.Count - 1; a >= 0; a--)
                {
                    for (int b = 0; b < lines.Count; b++)
                    {
                        if (a != b)
                        {
                            Vertex angleA;
                            Vertex angleMid;
                            Vertex angleC;

                            if (lines[a].Vertex1.EqualTo(lines[b].Vertex1))
                            {
                                angleMid = lines[a].Vertex1;
                                angleA   = lines[a].Vertex2;
                                angleC   = lines[b].Vertex2;
                            }
                            else if (lines[a].Vertex1.EqualTo(lines[b].Vertex2))
                            {
                                angleMid = lines[a].Vertex1;
                                angleA   = lines[a].Vertex2;
                                angleC   = lines[b].Vertex1;
                            }
                            else if (lines[a].Vertex2.EqualTo(lines[b].Vertex1))
                            {
                                angleMid = lines[a].Vertex2;
                                angleA   = lines[b].Vertex2;
                                angleC   = lines[a].Vertex1;
                            }
                            else if (lines[a].Vertex2.EqualTo(lines[b].Vertex2))
                            {
                                angleMid = lines[a].Vertex2;
                                angleA   = lines[b].Vertex1;
                                angleC   = lines[a].Vertex1;
                            }
                            else
                            {
                                continue;
                            }

                            double angle = Vertex.GetAngle(angleA, angleMid, angleC);
                            if (angle <= maxAngle)
                            {
                                lines[b] = new Line(angleA, angleC);
                                lines.RemoveAt(a);
                                changed = true;
                                break;
                            }
                        }
                    }
                }
                if (!changed)
                {
                    break;
                }
            }
        }
Exemplo n.º 2
0
        public static void CombineCloseAngles(List <Line> lines, double maxAngle)
        {
            if (maxAngle == 0)
            {
                return;
            }

            while (true)
            {
                bool changed = false;
                for (int a = lines.Count - 1; a >= 0; a--)
                {
                    for (int b = 0; b < lines.Count; b++)
                    {
                        if (a != b)
                        {
                            Vertex angleA;
                            Vertex angleMid;
                            Vertex angleC;

                            if (lines[a].Vertex1.EqualTo(lines[b].Vertex1))
                            {
                                angleMid = lines[a].Vertex1;
                                angleA   = lines[a].Vertex2;
                                angleC   = lines[b].Vertex2;
                            }
                            else if (lines[a].Vertex1.EqualTo(lines[b].Vertex2))
                            {
                                angleMid = lines[a].Vertex1;
                                angleA   = lines[a].Vertex2;
                                angleC   = lines[b].Vertex1;
                            }
                            else if (lines[a].Vertex2.EqualTo(lines[b].Vertex1))
                            {
                                angleMid = lines[a].Vertex2;
                                angleA   = lines[b].Vertex2;
                                angleC   = lines[a].Vertex1;
                            }
                            else if (lines[a].Vertex2.EqualTo(lines[b].Vertex2))
                            {
                                angleMid = lines[a].Vertex2;
                                angleA   = lines[b].Vertex1;
                                angleC   = lines[a].Vertex1;
                            }
                            else
                            {
                                continue;
                            }

                            double angle = Vertex.GetAngle(angleA, angleMid, angleC);
                            if (angle <= maxAngle)
                            {
                                lines[b] = new Line(angleA, angleC);
                                lines.RemoveAt(a);
                                changed = true;
                                break;
                            }
                        }
                    }
                }
                if (!changed)
                {
                    break;
                }
            }

            /*
             * bool loop = true;
             * while (loop)
             * {
             *  bool changed = false;
             *  for (int a = lines.Count - 1; a >= 0; a--)
             *  {
             *      var pointsA = new (double X, double Y, double Z)[] {
             *          (lines[a].Vertex1.X, lines[a].Vertex1.Y, lines[a].Vertex1.Z),
             *          (lines[a].Vertex2.X, lines[a].Vertex2.Y, lines[a].Vertex2.Z)
             *      };
             *
             *      for (int b = 0; b < lines.Count; b++)
             *      {
             *          var pointsB = new (double X, double Y, double Z)[] {
             *              (lines[b].Vertex1.X, lines[b].Vertex1.Y, lines[b].Vertex1.Z),
             *              (lines[b].Vertex2.X, lines[b].Vertex2.Y, lines[b].Vertex2.Z)
             *          };
             *
             *          if (a != b)
             *          {
             *              Vertex angleA;
             *              Vertex angleMid;
             *              Vertex angleC;
             *              if (pointsA[0] == pointsB[0])
             *              {
             *                  angleMid = lines[a].Vertex1;
             *                  angleA = lines[a].Vertex2;
             *                  angleC = lines[b].Vertex2;
             *              }
             *              else if (pointsA[0] == pointsB[1])
             *              {
             *                  angleMid = lines[a].Vertex1;
             *                  angleA = lines[a].Vertex2;
             *                  angleC = lines[b].Vertex1;
             *              }
             *              else if (pointsA[1] == pointsB[0])
             *              {
             *                  angleMid = lines[a].Vertex2;
             *                  angleA = lines[a].Vertex1;
             *                  angleC = lines[b].Vertex2;
             *              }
             *              else if (pointsA[1] == pointsB[1])
             *              {
             *                  angleMid = lines[a].Vertex2;
             *                  angleA = lines[a].Vertex1;
             *                  angleC = lines[b].Vertex1;
             *              }
             *              else continue;
             *
             *              double angle = Vertex.GetAngle(angleA, angleMid, angleC);
             *              if (angle <= maxAngle)
             *              {
             *                  lines[b] = new Line(angleA, angleC);
             *                  lines.RemoveAt(a);
             *                  changed = true;
             *                  break;
             *              }
             *          }
             *      }
             *  }
             *  loop = changed;
             * }
             */
        }