public Transform ( global point ) : global::Windows.Foundation.Point | ||
point | global | |
return | global::Windows.Foundation.Point |
private static Rect RectTransform(Rect rect, Matrix matrix) { Point leftTop = matrix.Transform(new Point(rect.Left, rect.Top)); Point rightTop = matrix.Transform(new Point(rect.Right, rect.Top)); Point leftBottom = matrix.Transform(new Point(rect.Left, rect.Bottom)); Point rightBottom = matrix.Transform(new Point(rect.Right, rect.Bottom)); double left = Math.Min(Math.Min(leftTop.X, rightTop.X), Math.Min(leftBottom.X, rightBottom.X)); double top = Math.Min(Math.Min(leftTop.Y, rightTop.Y), Math.Min(leftBottom.Y, rightBottom.Y)); double right = Math.Max(Math.Max(leftTop.X, rightTop.X), Math.Max(leftBottom.X, rightBottom.X)); double bottom = Math.Max(Math.Max(leftTop.Y, rightTop.Y), Math.Max(leftBottom.Y, rightBottom.Y)); Rect rectTransformed = new Rect(left, top, right - left, bottom - top); return rectTransformed; }
/// <summary> /// Implement Windows Presentation Foundation's Rect.Transform on /// Silverlight. /// </summary> /// <param name="rectangle">The rectangle to transform.</param> /// <param name="matrix">The matrix to use to transform the rectangle. /// </param> /// <returns>The transformed rectangle.</returns> private static Rect RectTransform(Rect rectangle, Matrix matrix) { // WPF equivalent of following code: // var rectTransformed = Rect.Transform(rect, matrix); Point leftTop = matrix.Transform(new Point(rectangle.Left, rectangle.Top)); Point rightTop = matrix.Transform(new Point(rectangle.Right, rectangle.Top)); Point leftBottom = matrix.Transform(new Point(rectangle.Left, rectangle.Bottom)); Point rightBottom = matrix.Transform(new Point(rectangle.Right, rectangle.Bottom)); double left = Math.Min(Math.Min(leftTop.X, rightTop.X), Math.Min(leftBottom.X, rightBottom.X)); double top = Math.Min(Math.Min(leftTop.Y, rightTop.Y), Math.Min(leftBottom.Y, rightBottom.Y)); double right = Math.Max(Math.Max(leftTop.X, rightTop.X), Math.Max(leftBottom.X, rightBottom.X)); double bottom = Math.Max(Math.Max(leftTop.Y, rightTop.Y), Math.Max(leftBottom.Y, rightBottom.Y)); Rect rectTransformed = new Rect(left, top, right - left, bottom - top); return rectTransformed; }
/*! * @brief calibrate from the given @a point in relationship to m_calibrateRotationRoot * @param point the point relative to the rotation root */ private void CalibrateFromPoint(Point point) { float width = (float)m_calibrateRotationRoot.ActualWidth; float height = (float)m_calibrateRotationRoot.ActualHeight; // move origin from the top left to the center with y-up and x-right Matrix matrix = new Matrix( 1, 0, 0, -1, -width / 2.0, height / 2.0); Point localPoint = matrix.Transform(point); float angle = (float)Math.Atan2(localPoint.Y, localPoint.X); int angleDegrees = (int)(angle * 180.0 / Math.PI); angleDegrees += 90; angleDegrees = (angleDegrees + 360) % 360; angleDegrees = 360 - angleDegrees; // apply the rotation to the ui m_rotation.Angle = angleDegrees; // preview the calibration and limit to 10 Hz long milliseconds = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond; if ((milliseconds - m_lastCommandSentTimeMs) > 100) { m_sphero.Roll(angleDegrees, 0); m_lastCommandSentTimeMs = milliseconds; } }