Esempio n. 1
0
 public SierpinskiVectorTree(Vector2f _base, Vector2f dims, int splitMax = 20)
 {
     root = new IsoTrianglei {
         _base = _base, dims = dims
     };
     this.splitMax = splitMax;
 }
Esempio n. 2
0
        public void Divide()
        {
            var nextBase = _base;

            nextBase.x -= dims.x / 4;
            var ll = new IsoTrianglei {
                dims = dims / 2f, _base = nextBase, inverted = inverted
            };

            nextBase.x = _base.x;
            var imiddle = new IsoTrianglei {
                dims = dims / 2f, _base = nextBase + new Vector2f(0, dims.y / 2) * (inverted ? -1 : 1), inverted = !inverted
            };
            var iupper = new IsoTrianglei {
                dims = dims / 2f, _base = nextBase + new Vector2f(0, dims.y / 2) * (inverted ? -1 : 1), inverted = inverted
            };

            nextBase.x += dims.x / 4;
            var lr = new IsoTrianglei {
                dims = dims / 2, _base = nextBase, inverted = inverted
            };

            children = new List <IsoTrianglei>();

            children.Add(ll);
            children.Add(imiddle);
            children.Add(iupper);
            children.Add(lr);

            int DBUGLost = 0;

            foreach (var v in data)
            {
                bool lostOne = true;
                foreach (var c in children)
                {
                    if (c.Contains(v))
                    {
                        c.data.Add(v);
                        lostOne = false;
                        break;
                    }
                }
                if (lostOne)
                {
                    DBUGLost++;
                    //Gizmos.color = Color.magenta;
                    //Gizmos.DrawWireCube(v, Vector3.one * .4f);
                }
            }

            if (DBUGLost > 0)
            {
                Debug.LogWarning("lost data: " + DBUGLost);
            }

            data.Clear();
        }
Esempio n. 3
0
        public void Add(Vector2f v)
        {
            IsoTrianglei tri = root.Add(v);

            if (tri != null && tri.Count > splitMax)
            {
                tri.DivideR(splitMax);
            }
        }