예제 #1
0
        /// <summary>
        /// Trims a rect in axis units into the visible portion of it in axis units. returns false if the parameter rect is completely out of view , true otherwise
        /// </summary>
        /// <param name="rect"></param>
        /// <param name="trimmed"></param>
        /// <returns></returns>
        public bool TrimRect(DoubleRect rect, out DoubleRect trimmed)
        {
            DoubleVector3 min = rect.min;
            DoubleVector3 max = rect.max;

            trimmed = new DoubleRect();
            min     = PointToNormalized(min.x, min.y);
            max     = PointToNormalized(max.x, max.y);

            if (min.x > 1f || min.y > 1f)
            {
                return(false);
            }
            if (max.x < 0f || max.y < 0f)
            {
                return(false);
            }

            double minX = ChartCommon.Clamp(Math.Min(min.x, max.x));
            double minY = ChartCommon.Clamp(Math.Min(min.y, max.y));
            double maxX = ChartCommon.Clamp(Math.Max(min.x, max.x));
            double maxY = ChartCommon.Clamp(Math.Max(min.y, max.y));

            min = NormalizedToPoint(minX, minY);
            max = NormalizedToPoint(maxX, maxY);

            trimmed = new DoubleRect(min.x, min.y, max.x - min.x, max.y - min.y);
            return(true);
        }