当前位置: 首页>>代码示例>>C#>>正文


C# Rect.Add方法代码示例

本文整理汇总了C#中System.Windows.Rect.Add方法的典型用法代码示例。如果您正苦于以下问题:C# Rect.Add方法的具体用法?C# Rect.Add怎么用?C# Rect.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Rect的用法示例。


在下文中一共展示了Rect.Add方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetInertialMotionParameters

        /// <summary>
        /// Gets inertial motion parameters: distance and duration.
        /// </summary>
        /// <param name="hostBounds">The host bounds.</param>
        /// <param name="windowBounds">The window bounds.</param>
        /// <returns>
        /// The inertial motion parameters: distance and duration.
        /// </returns>
        public InertialMotion GetInertialMotionParameters(Rect hostBounds, Rect windowBounds)
        {
            if (mouseTrails.Count < 2) return null;

            var mouseTrailsArray = mouseTrails.ToArray();

            Point startPosition = mouseTrailsArray[0].Position;
            DateTime startTime = mouseTrailsArray[0].Timestamp;
            Point endPosition = mouseTrailsArray[mouseTrails.Count - 1].Position;
            DateTime endTime = mouseTrailsArray[mouseTrails.Count - 1].Timestamp;

            double timeBetweenNowAndLastMove = (DateTime.Now - endTime).TotalMilliseconds;
            Vector2 vector = new Vector2(startPosition, endPosition);

            if (timeBetweenNowAndLastMove < DELAY_BEFORE_MOUSE_UP_IN_MILLISECONDS && !vector.IsZero)
            {
                double time = (endTime - startTime).TotalSeconds;
                time = (time == 0) ? 0.001 : time;

                double distance = vector.Length / pixelsPerMeter;

                double intialVelocity = distance / time;

                double expectedDistance = ((intialVelocity * intialVelocity) / (2 * COEFFICIENT_OF_SLIDING_FRICTION * GRAVITATIONAL_ACCELERATION));
                double expectedTime = (2 * expectedDistance) / intialVelocity;

                double shiftX = Math.Round(vector.LengthX * expectedDistance / distance);
                double shiftY = Math.Round(vector.LengthY * expectedDistance / distance);

                // New Inertial Motion Vector
                Vector2 imVector = new Vector2(endPosition, shiftX, shiftY).Round();
                double expectedLength = imVector.Length;

                Rect bounds = hostBounds.Add(-windowBounds.Width, -windowBounds.Height);

                if (bounds.Contains(endPosition))
                {
                    imVector = EnsureEndPointInBounds(imVector, bounds).Round();
                }
                else if (hostBounds.Contains(endPosition))
                {
                    imVector = EnsureEndPointInBounds(imVector, hostBounds).Round();
                }

                // Reduce expected time if the Inertial Motion Vector was truncated by the bounds
                double realTime = (expectedLength == 0) ? 0 : (expectedTime * imVector.Length / expectedLength);

                var motion = new InertialMotion()
                {
                    Seconds = realTime,
                    EndPosition = imVector.End,
                    EasingFunction = new CubicEase()
                    {
                        EasingMode = EasingMode.EaseOut
                    }
                };

                return motion;
            }

            return null;
        }
开发者ID:Zoomicon,项目名称:ZUI,代码行数:70,代码来源:InertiaController.cs


注:本文中的System.Windows.Rect.Add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。