Ejemplo n.º 1
0
        public override bool Equals(Object obj)
        {
            if (obj == null)
            {
                return(false);
            }

            if (!(obj is KVector2))
            {
                return(false);
            }

            KVector2 other = (KVector2)obj;

            if (!KMath.AlmostEquals(X, other.X, Config.EpsilonsFloat))
            {
                return(false);
            }
            if (!KMath.AlmostEquals(Y, other.Y, Config.EpsilonsFloat))
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 2
0
        public bool IsConvex()
        {
            if (Count < 3)
            {
                return(false);
            }

            if (Count == 3)
            {
                return(true);
            }

            //TODO: A ameliorer
            double oldValue = 0;
            bool   convex   = true;

            for (int i = 0; i < Count; i++)
            {
                int secondIndex = i + 1 < Count ? i + 1 : 0;
                int thirdIndex  = secondIndex + 1 < Count ? secondIndex + 1 : 0;

                KVector2 edgeA = this[secondIndex] - this[i];
                KVector2 edgeB = this[thirdIndex] - this[secondIndex];

                double nextValue = edgeA % edgeB;

                if (KMath.AlmostEquals(nextValue, 0, Config.EpsilonsDouble))
                {
                    if (this[i] == this[thirdIndex])
                    {
                        //Order is important here
                        Remove(this[thirdIndex]);
                        Remove(this[secondIndex]);
                    }
                    else
                    {
                        Remove(this[secondIndex]);
                    }

                    i = i - 1 > 0 ? i - 1 : Count;
                    continue;
                }

                convex &= nextValue * oldValue >= 0;

                oldValue = nextValue;
            }

            if (Count < 3)
            {
                return(false);
            }

            return(convex);
        }