예제 #1
0
        public void TestHIndices()
        {
            int        size = 4;
            IntVector3 dims = new IntVector3(size);

            List <IntVector3.IndexedIntVector3> vs = dims.IteratorXYZ.ToList();

            int bits = (int)Mathf.Log(size * size * size, 8);

            List <IntVector3.IndexedIntVector3> hsorted = vs.OrderBy(vox => vox.v.ToUint3().CoordsToFlatHilbertIndex(bits)).ToList();

            IntVector3 offset = new IntVector3(4);


            transform.DestroyAllChildrenImmediate();

            var lr = this.GetOrAddComponent <LineRenderer>(); // GetComponent<LineRenderer>();

            lr.positionCount = hsorted.Count;
            lr.SetPosition(0, hsorted[0] + offset);

            Dictionary <IntVector3, int> hcubes = new Dictionary <IntVector3, int>();

            IntVector3 compare    = hsorted[0];
            int        colorIndex = 0;

            for (int i = 1; i < hsorted.Count; ++i)
            {
                var next = hsorted[i];
                var prev = hsorted[i - 1];

                dbDraw(prev + offset, next + offset, ColorUtil.roygbivMod(colorIndex));



                if (isDifferentHilbertCube((int)compare.AbsValuesToUInt256(), (int)next.v.AbsValuesToUInt256(), hCubeSize))
                {
                    if (!hcubes.ContainsKey(compare))
                    {
                        hcubes.Add(compare, 1);
                    }
                    else
                    {
                        hcubes[compare]++;
                    }
                    addMarker(compare - (compare % hCubeSize) + offset, ColorUtil.roygbivMod(colorIndex));
                    colorIndex++;
                    //addBoundsMarker(prev - (prev % hCubeSize) + offset, c, hCubeSize);
                    compare = next;
                }
            }

            Debug.Log("hcube entries: " + hcubes.Keys.Count);
            int total = 0;

            foreach (int c in hcubes.Values)
            {
                total += c;
                if (c > 1)
                {
                    Debug.LogWarning("what happened??? " + c);
                }
            }
            Debug.Log("total diff found: " + total);
        }