Exemple #1
0
        /// <summary>
        /// 检查矩形与圆形是否发生了碰撞
        /// </summary>
        ///
        /// <param name="rect1"></param>
        /// <param name="rect2"></param>
        /// <returns></returns>
        public static bool IsRectToCirc(RectBox rect1, RectBox rect2)
        {
            float radius     = rect2.GetWidth() / 2;
            Point middle     = GetMiddlePoint(rect2);
            Point upperLeft  = new Point(rect1.GetMinX(), rect1.GetMinY());
            Point upperRight = new Point(rect1.GetMaxX(), rect1.GetMinY());
            Point downLeft   = new Point(rect1.GetMinX(), rect1.GetMaxY());
            Point downRight  = new Point(rect1.GetMaxX(), rect1.GetMaxY());
            bool  collided   = true;

            if (!IsPointToLine(upperLeft, upperRight, middle, radius))
            {
                if (!IsPointToLine(upperRight, downRight, middle, radius))
                {
                    if (!IsPointToLine(upperLeft, downLeft, middle, radius))
                    {
                        if (!IsPointToLine(downLeft, downRight, middle, radius))
                        {
                            collided = false;
                        }
                    }
                }
            }
            return(collided);
        }
Exemple #2
0
        public int GetScroll(RectBox visibleRect, int orientation, int direction)
        {
            int    cellSize  = this.GetCellSize();
            double scrollPos = 0.0D;

            if (orientation == 0)
            {
                if (direction < 0)
                {
                    scrollPos = visibleRect.GetMinX();
                }
                else if (direction > 0)
                {
                    scrollPos = visibleRect.GetMaxX();
                }
            }
            else if (direction < 0)
            {
                scrollPos = visibleRect.GetMinY();
            }
            else if (direction > 0)
            {
                scrollPos = visibleRect.GetMaxY();
            }
            int increment = MathUtils.Abs((int)Math.IEEERemainder(scrollPos, cellSize));

            if (increment == 0)
            {
                increment = cellSize;
            }
            return(increment);
        }