Esempio n. 1
0
        public double deviationThreshold = .1d; // total guess

        public TriTree(Vector2f _base, Vector2f dims)
        {
            root = new IsoTriangle <U> {
                _base = _base, dims = dims
            };
            //this.splitMax = splitMax;
        }
Esempio n. 2
0
        public bool IsTouching(IsoTriangle <T> other, out Vector2f touchPoint, float epsilon = 0.001f)
        {
            //DEBUG (sanity check)
            if (center.Distance(other.center) > Circumradius + other.Circumradius)
            {
                touchPoint = Vector2f.One * 100f;
                return(false);
            }
            //END DBUG

            IsoTriangle <T> larger, smaller;

            if (other.dims.x < dims.x)
            {
                smaller = other;
                larger  = this;
            }
            else
            {
                smaller = this;
                larger  = other;
            }
            var   _border     = smaller.Border();
            float smallestMag = float.MaxValue;

            touchPoint = _border[0];

            for (int i = 0; i < 3; ++i)
            {
                // is touching if a slightly nudged point of other
                // is inside this tri
                var dif = larger.center - _border[i];
                if (dif.LengthSquared < smallestMag)
                {
                    smallestMag = dif.LengthSquared;
                    touchPoint  = _border[i];
                }

                //if(dif.LengthSquared < epsilon)
                //{
                //    touchPoint = _border[i];
                //    return true;
                //}

                var touch = _border[i] + dif * epsilon; // -Mathf.Min(other.dims.x, dims.x) / 4f;
                if (larger.Contains(touch))
                {
                    touchPoint = touch;
                    return(true);
                }
            }

            return(false);
        }
Esempio n. 3
0
 public DepthLeaf(IsoTriangle <T> tri, int depth)
 {
     this.tri = tri; this.depth = depth;
 }
Esempio n. 4
0
        public void Divide()
        {
            var nextBase = _base;

            nextBase.x -= dims.x / 4;
            var ll = new IsoTriangle <T> {
                dims = dims / 2f, _base = nextBase, inverted = inverted
            };

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

            nextBase.x += dims.x / 4;
            var lr = new IsoTriangle <T> {
                dims = dims / 2, _base = nextBase, inverted = inverted
            };

            //TODO: does children being an array break someting?
            //children = new IsoTriangle<T>[4]; // new List<IsoTriangle<T>>();
            children = new List <IsoTriangle <T> >();
            for (int i = 0; i < 4; ++i)
            {
                children.Add(null);
            }

            children[(int)ChildOrder.LowerLeft]  = ll;
            children[(int)ChildOrder.LowerRight] = lr;
            children[(int)ChildOrder.Upper]      = iupper;
            children[(int)ChildOrder.Middle]     = imiddle;

            int DBUGLost = 0;

            foreach (var v in data)
            {
                if (imiddle.Contains(v.v))
                {
                    imiddle.Incorporate(v);
                }
                else
                {
                    var _center = center;
                    if ((_center.y < v.v.y) == !inverted)
                    {
                        iupper.Incorporate(v);
                    }
                    else
                    {
                        if (_center.x > v.v.x)
                        {
                            ll.Incorporate(v);
                        }
                        else
                        {
                            lr.Incorporate(v);
                        }
                    }
                }
            }

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

            data.Clear();
        }