Example #1
0
 public override bool Equals(object obj)
 {
     Poly item = obj as Poly;
     if (item == null)
         return false;
     return  item.A == this.A && item.B == this.B && item.C == this.C;
 }
Example #2
0
        public void SplitPolys()
        {
            var canSkip = new List<int>();
            var done = new List<Vector3>();
            var newPolys = new SortedSet<Poly>(new PolySorter());
            var polyArray = new Poly[polys.Count];
            polys.CopyTo (polyArray);
            for (int i = 0; i < polyArray.Length; i++)
            {
                if (canSkip.Contains(i)) continue;
                var poly = polyArray[i];
                if (i>polyArray.Length/2)
                {
                    newPolys.Add(poly);
                    continue;
                }

                Vector3 a, b, c;
                Vector3 ab,bc,ca;
                Vector3 m = new Vector3();

                var abDone = done.Contains(poly.AB);
                var bcDone = done.Contains(poly.BC);
                var caDone = done.Contains(poly.CA);
                if (!abDone && (poly.ABLen >= poly.BCLen || bcDone) && (poly.ABLen >= poly.CALen || caDone))
                {
                    a = poly.A; b = poly.B; c = poly.C;
                    ab = poly.AB; bc = poly.BC; ca = poly.CA;
                }
                else if (!bcDone && (poly.BCLen >= poly.ABLen || abDone) && (poly.BCLen >= poly.CALen || caDone))
                {
                    a = poly.B; b = poly.C; c = poly.A;
                    ab = poly.BC; bc = poly.CA; ca = poly.AB;
                }
                else if (!caDone && (poly.CALen >= poly.ABLen || abDone) && (poly.CALen >= poly.BCLen || bcDone))
                {
                    a = poly.C; b = poly.A; c = poly.B;
                    ab = poly.CA; bc = poly.AB; ca = poly.BC;
                }
                else
                {
                    //Console.WriteLine ("Cant split");
                    newPolys.Add(poly);
                    done.Add(poly.AB);
                    done.Add(poly.BC);
                    done.Add(poly.CA);
                    continue;
                }

                float avg = (a.Length + b.Length + c.Length) / 3;
                float h = avg + (float)(rnd.NextDouble() - 0.5) * (0.1f * (a-b).Length);
                //m = ab * (1 / ab.Length); // normalize point to radius 1
                m = ab * (h / ab.Length);

                newPolys.Add(new Poly(a, m, c));
                newPolys.Add(new Poly(m, b, c));

                done.Add (ab);
                done.Add (bc);
                done.Add (ca);

                // find other poly sharing split ab line
                for (int j = i+1; j < polyArray.Length; j++)
                {
                    var poly2 = polyArray[j];
                    if (poly2.AB == ab)
                    {
                        newPolys.Add(new Poly(poly2.A, m, poly2.C));
                        newPolys.Add(new Poly(m, poly2.B, poly2.C));
                        done.Add(poly2.BC);
                        done.Add(poly2.CA);
                        canSkip.Add (j);
                        break;
                    }
                    else if (poly2.BC == ab)
                    {
                        newPolys.Add(new Poly(poly2.B, m, poly2.A));
                        newPolys.Add(new Poly(m, poly2.C, poly2.A));
                        done.Add(poly2.AB);
                        done.Add(poly2.CA);
                        canSkip.Add (j);
                        break;
                    }
                    else if (poly2.CA == ab)
                    {
                        newPolys.Add(new Poly(poly2.C, m, poly2.B));
                        newPolys.Add(new Poly(m, poly2.A, poly2.B));
                        done.Add(poly2.AB);
                        done.Add(poly2.BC);
                        canSkip.Add (j);
                        break;
                    }
                }
            }
            polys = newPolys;
            Console.WriteLine ($"{polys.Count} polygons");
            CreateMap();
        }