/// <summary> /// 根据当前长度和角度的输入情况,得到计算后的"悬停"位置; /// </summary> /// <param name="position">返回是否已经处理,以指示编辑工具是否继续处理</param> /// <param name="currentHoverPosition">当前的悬停位置</param> private Vector2D GetCalculatedHoverPosition(Vector2D currentHoverPosition) { var commitedLength = _lengthInteractionHandler.GetCommitedNumber(); var commitedAngle = _angleInteractionHandler.GetCommitedNumber(); //若长度和角度均未确定,则不能计算位置; if (commitedLength == null && commitedAngle == null) { return(null); } //若角方向为顺时针方向,则反转角度值; if (commitedAngle != null) { commitedAngle = _isClockWise ? -commitedAngle.Value : commitedAngle.Value; commitedAngle = Extension.DegToRad(commitedAngle.Value); } if (HaveMousePositionTracker.MousePositionTracker.LastMouseDownPosition == null) { return(null); } var lastDownPosition = HaveMousePositionTracker.MousePositionTracker.LastMouseDownPosition; var distanceVector = currentHoverPosition - lastDownPosition; var distance = distanceVector.Modulus(); if (distance < Extension.SMALL_NUMBER) { return(null); } //若长度未限定,则根据角度设定悬停点; if (commitedLength == null) { var x = Math.Cos(commitedAngle.Value) * distance; var y = Math.Sin(commitedAngle.Value) * distance; return(new Vector2D(x + lastDownPosition.X, y + lastDownPosition.Y)); } //若角度未限定,则根据长度设定悬停点; else if (commitedAngle == null) { var destination = lastDownPosition + distanceVector.Normalize() * commitedLength.Value; return(destination); } ///若均已经限定,则<param name="currentHoverPosition"/>将被忽略; ///悬停点将全由本类字段决定; else { var length = commitedLength.Value; var angle = commitedAngle.Value; var x = Math.Cos(commitedAngle.Value) * length; var y = Math.Sin(commitedAngle.Value) * length; return(new Vector2D(x + lastDownPosition.X, y + lastDownPosition.Y)); } }
/// <summary> /// 根据当前长度和角度的输入情况,得到计算后的"悬停"位置; /// </summary> /// <param name="position">返回是否已经处理,以指示编辑工具是否继续处理</param> /// <param name="currentHoverPosition">当前的悬停位置</param> private Vector2D GetCalculatedHoverPosition(Vector2D currentHoverPosition) { var commitedLength = _lengthInteractionHandler.GetCommitedNumber(); //若长度未确定,则不能计算位置; if (commitedLength == null) { return(null); } if (HaveMousePositionTracker.MousePositionTracker.LastMouseDownPosition == null) { return(null); } var lastDownPosition = HaveMousePositionTracker.MousePositionTracker.LastMouseDownPosition; var distanceVector = currentHoverPosition - lastDownPosition; var distance = distanceVector.Modulus(); if (distance < Extension.SMALL_NUMBER) { return(null); } var length = commitedLength.Value; var destination = lastDownPosition + distanceVector.Normalize() * commitedLength.Value; return(destination); }