protected override void OnDrag(MouseDevice mouseDevice, double zoom) { Point point = PathFigureUtilities.GetPoint(this.PathEditContext.GetPathFigure(this.Path), this.PathEditContext.PartIndex); Point point1 = this.geometryToDocument.Transform(point); Point viewRootCoordinates = this.GetPointInViewRootCoordinates(mouseDevice, true); Vector vector = viewRootCoordinates - point1; Vector correspondingVector = ElementUtilities.GetCorrespondingVector(vector, this.geometryToDocument, this.IsShiftDown ? this.AxisConstraint : (AxisConstraint)null); if (this.hasMoved || Tolerances.HaveMoved(point1, viewRootCoordinates, zoom)) { this.hasMoved = true; PathGeometry path = this.Path; int figureIndex = this.PathEditContext.FigureIndex; int partIndex = this.PathEditContext.PartIndex; PathGeometryEditor pathGeometryEditor = this.BeginEditing(); PathFigureEditor pathFigureEditor = new PathFigureEditor(path.Figures[figureIndex]); if (partIndex > 0 || PathFigureUtilities.IsClosed(pathFigureEditor.PathFigure)) { pathGeometryEditor.SetPoint(figureIndex, partIndex - 1, point - correspondingVector); } if (pathFigureEditor.GetLastIndexOfDownstreamSegment(partIndex) != partIndex) { pathGeometryEditor.SetPoint(figureIndex, partIndex + 1, point + correspondingVector); } if (partIndex == PathFigureUtilities.PointCount(pathFigureEditor.PathFigure) - 1 && PathFigureUtilities.IsOpen(pathFigureEditor.PathFigure)) { this.LastTangent = vector; } this.PathEditorTarget.AddCriticalEdit(); } base.OnDrag(mouseDevice, zoom); }
private bool TestGeometryAgainstFrustum(MeshGeometry3D rawGeometry, Material frontMaterial, Material backMaterial, BoundingVolume frustum, Matrix3D transform) { if (rawGeometry == null) { return(false); } TriangleEnumerator triangleEnumerator = new TriangleEnumerator(rawGeometry.Positions, rawGeometry.TriangleIndices); Point3D[] point3DArray = new Point3D[3]; foreach (int[] numArray in triangleEnumerator.TriangleList) { point3DArray[0] = rawGeometry.Positions[numArray[0]]; point3DArray[1] = rawGeometry.Positions[numArray[1]]; point3DArray[2] = rawGeometry.Positions[numArray[2]]; transform.Transform(point3DArray); if (frustum.IsPolygonContainedOrIntersecting(point3DArray)) { double num = Vector3D.DotProduct(Vector3D.CrossProduct(point3DArray[1] - point3DArray[0], point3DArray[2] - point3DArray[0]), point3DArray[0] - this.frustumCenterRay.Origin); if (Tolerances.LessThanOrClose(num, 0.0) && frontMaterial != null || Tolerances.GreaterThan(num, 0.0) && backMaterial != null) { return(true); } } } return(false); }
protected override HitTestResult HitTestCore(PointHitTestParameters hitTestParams) { Point hitPoint = hitTestParams.HitPoint; if (Tolerances.AreClose(hitPoint, this.lastPoint)) { return(base.HitTestCore(hitTestParams)); } this.lastPoint = hitPoint; double num; if (((LayoutBehavior)this.AdornerSet.Behavior).IsNewGridlineEnabled && Mouse.LeftButton != MouseButtonState.Pressed && Mouse.RightButton != MouseButtonState.Pressed) { Matrix inverseMatrix = ElementUtilities.GetInverseMatrix(this.AdornerSet.Matrix); Point point = hitPoint * inverseMatrix; Point pointBegin; Point pointEnd; this.GetPoints(out pointBegin, out pointEnd, this.AdornerSet.Matrix); num = !new Rect(pointBegin, pointEnd).Contains(point) ? double.NaN : (!this.IsX ? point.Y : point.X); } else { num = double.NaN; } if (!this.position.Equals(num)) { this.position = num; if (this.isMouseOver) { this.InvalidateRender(); this.AdornerSet.Update(); } } return(base.HitTestCore(hitTestParams)); }
protected virtual void ComputeMarginOverrides() { bool flag = false; double left = this.Settings.Margin.Left; double right = this.Settings.Margin.Right; double top = this.Settings.Margin.Top; double bottom = this.Settings.Margin.Bottom; if (!Tolerances.AreClose(this.SettingsFromElement.Margin.Left, this.Settings.Margin.Left) || !Tolerances.AreClose(this.SettingsFromElement.Margin.Right, this.Settings.Margin.Right)) { this.Settings.LayoutOverrides |= LayoutOverrides.HorizontalMargin; left = this.SettingsFromElement.Margin.Left; right = this.SettingsFromElement.Margin.Right; flag = true; } if (!Tolerances.AreClose(this.SettingsFromElement.Margin.Top, this.Settings.Margin.Top) || !Tolerances.AreClose(this.SettingsFromElement.Margin.Bottom, this.Settings.Margin.Bottom)) { this.Settings.LayoutOverrides |= LayoutOverrides.VerticalMargin; top = this.SettingsFromElement.Margin.Top; bottom = this.SettingsFromElement.Margin.Bottom; flag = true; } if (!flag) { return; } this.Settings.Margin = new Thickness(left, top, right, bottom); }
public void SetTimeRegion(double originalRegionBegin, double originalRegionEnd, double finalRegionBegin, double finalRegionEnd) { using (SceneEditTransaction editTransaction = this.ViewModel.CreateEditTransaction(StringTable.UndoUnitMoveScheduledProperties)) { double scaleFactor = (finalRegionEnd - finalRegionBegin) / (originalRegionEnd - originalRegionBegin); TimeRegionChangeDetails details = TimeRegionChangeDetails.None; if (Tolerances.AreClose(originalRegionEnd - originalRegionBegin, 0.0)) { details |= TimeRegionChangeDetails.FromZero; } if (Tolerances.AreClose(finalRegionEnd - finalRegionBegin, 0.0)) { details |= TimeRegionChangeDetails.ToZero; } if (!Tolerances.AreClose(scaleFactor, 1.0)) { details |= TimeRegionChangeDetails.Scale; } if (!Tolerances.AreClose(originalRegionBegin, finalRegionBegin)) { details |= TimeRegionChangeDetails.Translate; } this.RecursiveSetTimeRegion(details, scaleFactor, originalRegionBegin, originalRegionEnd, finalRegionBegin, finalRegionEnd); editTransaction.Commit(); } }
private PathGeometry GetEllipseGeometry(Point left, Point top, Point right, Point bottom, double horizontalScale, double verticalScale) { Vector vector1 = right - left; if (!Tolerances.NearZero(vector1.Length)) { vector1.Normalize(); vector1 *= horizontalScale; } Vector vector2 = top - bottom; if (!Tolerances.NearZero(vector2.Length)) { vector2.Normalize(); vector2 *= verticalScale; } PathFigure pathFigure = new PathFigure(); pathFigure.StartPoint = left; pathFigure.Segments.Add((PathSegment) new BezierSegment(left + vector2, top - vector1, top, true)); pathFigure.Segments.Add((PathSegment) new BezierSegment(top + vector1, right + vector2, right, true)); pathFigure.Segments.Add((PathSegment) new BezierSegment(right - vector2, bottom + vector1, bottom, true)); pathFigure.Segments.Add((PathSegment) new BezierSegment(bottom - vector1, left - vector2, left, true)); pathFigure.IsClosed = true; pathFigure.Freeze(); PathGeometry pathGeometry = new PathGeometry((IEnumerable <PathFigure>) new PathFigure[1] { pathFigure }); pathGeometry.Freeze(); return(pathGeometry); }
public static bool DrawInscribedRoundedRect(DrawingContext drawingContext, Brush fill, Pen stroke, Rect outerBounds, double cornerRadius) { Point spineLeftTop = new Point(outerBounds.Left, outerBounds.Top); Point spineRightBottom = new Point(outerBounds.Right, outerBounds.Bottom); bool drewSomething = false; if (stroke != null && !Tolerances.NearZero(stroke.Thickness)) { double halfThickness = stroke.Thickness / 2d; spineLeftTop.X += halfThickness; spineLeftTop.Y += halfThickness; spineRightBottom.X -= halfThickness; spineRightBottom.Y -= halfThickness; } Rect spineRect = new Rect(spineLeftTop, spineRightBottom); if (!Tolerances.NearZero(spineRect.Width) && !Tolerances.NearZero(spineRect.Height)) { drawingContext.DrawRoundedRectangle(fill, stroke, spineRect, cornerRadius, cornerRadius); drewSomething = true; } return(drewSomething); }
public static Rect CalculateInnerRect(Rect outerBounds, double strokeThickness) { if (!Tolerances.NearZero(strokeThickness)) { return(new Rect(new Point(outerBounds.Left + strokeThickness, outerBounds.Top + strokeThickness), new Point(outerBounds.Right - strokeThickness, outerBounds.Bottom - strokeThickness))); } return(outerBounds); }
public static bool GreaterThan(double value1, double value2) { if (value1 > value2) { return(!Tolerances.AreClose(value1, value2)); } return(false); }
public static bool LessThan(double value1, double value2) { if (value1 < value2) { return(!Tolerances.AreClose(value1, value2)); } return(false); }
public static bool LessThanOrClose(double value1, double value2) { if (value1 >= value2) { return(Tolerances.AreClose(value1, value2)); } return(true); }
public static Rotation3D GetRotation3DFromDirection(Vector3D direction) { direction.Normalize(); Vector3D axis = Vector3D.CrossProduct(Vector3DEditor.pointingDirection, direction); double d = Vector3D.DotProduct(Vector3DEditor.pointingDirection, direction); return(!Tolerances.AreClose(axis.LengthSquared, 0.0) ? (Rotation3D) new AxisAngleRotation3D(axis, Math.Acos(d) * 57.2957795130823) : (!Tolerances.AreClose(d, 1.0) ? (Rotation3D) new AxisAngleRotation3D(Vector3DEditor.perpendicularDirection, 180.0) : Rotation3D.Identity)); }
protected override void OnBegin(PathEditContext pathEditContext, MouseDevice mouseDevice) { if (!Tolerances.AreClose(this.LastTangent, new Vector(0.0, 0.0))) { this.LastTangent = new Vector(0.0, 0.0); } base.OnBegin(pathEditContext, mouseDevice); }
public void ApplyScale(Vector scale, Point origin, Point fixedPoint) { this.Translation += new Vector((1.0 - scale.X) * (fixedPoint.X - origin.X), (1.0 - scale.Y) * (fixedPoint.Y - origin.Y)) * this.Value; double num1 = Tolerances.NearZero(this.ScaleX) ? 0.001 : this.ScaleX; double num2 = Tolerances.NearZero(this.ScaleY) ? 0.001 : this.ScaleY; this.Scale = new Vector(num1 * scale.X, num2 * scale.Y); }
internal Radii(CornerRadius radii, Thickness borders, bool outer) { double num1 = 0.5 * borders.Left; double num2 = 0.5 * borders.Top; double num3 = 0.5 * borders.Right; double num4 = 0.5 * borders.Bottom; if (outer) { if (Tolerances.NearZero(radii.TopLeft)) { this.LeftTop = this.TopLeft = 0.0; } else { this.LeftTop = radii.TopLeft + num1; this.TopLeft = radii.TopLeft + num2; } if (Tolerances.NearZero(radii.TopRight)) { this.TopRight = this.RightTop = 0.0; } else { this.TopRight = radii.TopRight + num2; this.RightTop = radii.TopRight + num3; } if (Tolerances.NearZero(radii.BottomRight)) { this.RightBottom = this.BottomRight = 0.0; } else { this.RightBottom = radii.BottomRight + num3; this.BottomRight = radii.BottomRight + num4; } if (Tolerances.NearZero(radii.BottomLeft)) { this.BottomLeft = this.LeftBottom = 0.0; } else { this.BottomLeft = radii.BottomLeft + num4; this.LeftBottom = radii.BottomLeft + num1; } } else { this.LeftTop = Math.Max(0.0, radii.TopLeft - num1); this.TopLeft = Math.Max(0.0, radii.TopLeft - num2); this.TopRight = Math.Max(0.0, radii.TopRight - num2); this.RightTop = Math.Max(0.0, radii.TopRight - num3); this.RightBottom = Math.Max(0.0, radii.BottomRight - num3); this.BottomRight = Math.Max(0.0, radii.BottomRight - num4); this.BottomLeft = Math.Max(0.0, radii.BottomLeft - num4); this.LeftBottom = Math.Max(0.0, radii.BottomLeft - num1); } }
public void Render(DrawingContext dc, Rect renderRect, Brush brush, CornerRadius cornerRadius) { if (brush == null || Tolerances.NearZero(renderRect.Width) || Tolerances.NearZero(renderRect.Height)) { return; } this.ValidateGeometry(renderRect, cornerRadius); dc.DrawGeometry(brush, (Pen)null, (Geometry)this.geometry); }
protected override void Finish() { if (Tolerances.AreClose(this.initialRenderTransformOrigin, this.EditingElementSet.RenderTransformOrigin)) { return; } this.EnsureEditTransaction(); this.EditingElement.ViewModel.Document.AddUndoUnit((IUndoUnit) new MultipleElementCenterEditUndoUnit(this.EditingElementSet, this.initialRenderTransformOrigin, this.EditingElementSet.RenderTransformOrigin)); }
public static bool AreClose(Point point1, Point point2) { if (Tolerances.AreClose(point1.X, point2.X) && Tolerances.AreClose(point1.Y, point2.Y)) { return(true); } return(false); }
/// <summary> /// Rounds unit value to nearest pixel. /// </summary> /// <returns> /// Rounded value in units. /// </returns> public static double RoundToPixel(double units, double unitsPerPixel) { double pixels = units / unitsPerPixel; double floorPixels = (double)Math.Floor(pixels); pixels = Tolerances.LessThan(pixels, floorPixels + 0.5) ? floorPixels : (double)Math.Ceiling(pixels); return(pixels * unitsPerPixel); }
private void SetRotationFromPointer() { Vector vector = Mouse.GetPosition((IInputElement)this) - new Point(this.RenderSize.Width / 2.0, this.RenderSize.Height / 2.0); if (Tolerances.NearZero(vector) || !this.IsEnabled) { return; } double num = Math.Atan2(vector.Y, vector.X) * 180.0 / Math.PI; this.RotationAngle = this.ClosestAngleTo(Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift) ? Math.Round(num / 15.0) * 15.0 : RoundingHelper.RoundAngle(num)); }
protected override bool OnDrag(Point dragStartPosition, Point dragCurrentPosition, bool scrollNow) { switch (this.ActiveAdorner.Kind) { case RadialGradientAdornerKind.GradientOriginPoint: this.actionString = StringTable.UndoUnitRadialGradientOrigin; if (!this.HasMouseMovedAfterDown) { this.CopyPrimaryBrushToSelection(); } Point point = this.initialCenterInBrush; if (Tolerances.HaveMoved(dragCurrentPosition, this.initialCenterInDocument, this.ActiveView.Zoom)) { Point positionInBrush = this.ActiveAdorner.InverseTransformPoint(dragCurrentPosition * this.initialContextToElementMatrix, true) * this.brushToRootMatrix; BrushTransformBehavior.OffsetDragPoint(ref positionInBrush, this.initialCenterInBrush * this.brushToRootMatrix, this.dragOffset, 0.0); point = RoundingHelper.RoundPosition(positionInBrush * this.rootToBrushMatrix); } if (this.ActiveAdorner.GradientOriginPoint != point) { this.SetBrushValue(RadialGradientBrushNode.GradientOriginProperty, (object)point); this.UpdateEditTransaction(); break; } break; case RadialGradientAdornerKind.RadiusPoint: this.actionString = StringTable.UndoUnitScaleRadialGradient; if (!this.HasMouseMovedAfterDown) { this.CopyPrimaryBrushToSelection(); this.radiusX = (double)this.GetBrushValue(RadialGradientBrushNode.RadiusXProperty); this.radiusY = (double)this.GetBrushValue(RadialGradientBrushNode.RadiusYProperty); if (Math.Abs(this.radiusX) < 0.01) { this.radiusX = 0.01; } if (Math.Abs(this.radiusY) < 0.01) { this.radiusY = 0.01; } } Vector perpendicular; double num1 = GradientStopBehavior.VectorProjection(this.ActiveAdorner.BrushCenter * this.brushToRootMatrix, this.initialPointerPosition, dragCurrentPosition, 0.0, out perpendicular); double num2 = RoundingHelper.RoundLength(this.radiusX * num1); double num3 = RoundingHelper.RoundLength(this.radiusY * num1); this.SetBrushValue(RadialGradientBrushNode.RadiusXProperty, (object)num2); this.SetBrushValue(RadialGradientBrushNode.RadiusYProperty, (object)num3); this.UpdateEditTransaction(); break; } this.ActiveView.EnsureVisible((IAdorner)this.ActiveAdorner, scrollNow); return(true); }
protected override bool OnButtonDownOverNonAdorner(Point pointerPosition) { this.IsProjectedInsertionPoint = Adorner.NonAffineTransformInParentStack(this.ActiveSceneInsertionPoint.SceneElement); if (!this.IsProjectedInsertionPoint) { this.pointList.Clear(); this.pointList.Add(pointerPosition); this.vpFitter.Clear(); this.vpFitter.Add(pointerPosition, 0L); this.vpFitter.CurveTolerance = Tolerances.CurveFittingDistanceTolerance(this.ActiveView.Zoom) * Tolerances.CurveFittingDistanceTolerance(this.ActiveView.Zoom); } return(true); }
private static bool IsNextElementStartOfNewLine(Rect currentElementLayoutBounds, Rect nextElementLayoutBounds, Orientation orientation) { switch (orientation) { case Orientation.Horizontal: return(Tolerances.LessThan(nextElementLayoutBounds.Left, currentElementLayoutBounds.Right)); case Orientation.Vertical: return(Tolerances.LessThan(nextElementLayoutBounds.Top, currentElementLayoutBounds.Bottom)); default: throw new NotImplementedException(ExceptionStringTable.StackPanelUnrecognizedOrientation); } }
private static bool ComputeLineTriangleIntersection(Ray3D line, Point3D[] triangle, out Point hitBarycentric) { hitBarycentric = new Point(double.NaN, double.NaN); Vector3D vector3D1 = triangle[1] - triangle[0]; Vector3D vector3D2 = triangle[2] - triangle[0]; if (Tolerances.NearZero(Vector3D.CrossProduct(vector3D1, vector3D2).LengthSquared)) { return(false); } Vector3D vector3D3 = line.Origin - triangle[0]; Vector3D vector2_1 = Vector3D.CrossProduct(line.Direction, vector3D2); double d = Vector3D.DotProduct(vector3D1, vector2_1); if (Tolerances.NearZero(d)) { return(false); } Vector3D vector1; if (d > 0.0) { vector1 = line.Origin - triangle[0]; } else { vector1 = triangle[0] - line.Origin; d = -d; } double num1 = 1.0 / d; double num2 = Vector3D.DotProduct(vector1, vector2_1); if (num2 < 0.0 || d < num2) { return(false); } Vector3D vector2_2 = Vector3D.CrossProduct(vector1, vector3D1); double num3 = Vector3D.DotProduct(line.Direction, vector2_2); if (num3 < 0.0 || d < num2 + num3) { return(false); } double num4 = Vector3D.DotProduct(vector3D2, vector2_2) * num1; double x = num2 * num1; double y = num3 * num1; hitBarycentric = new Point(x, y); return(true); }
private void SetOrientationFromPointer() { Vector3D positionFromPointer = this.GetPositionFromPointer(); Vector3D axisOfRotation = Vector3D.CrossProduct(this.initialPosition, positionFromPointer); if (!this.IsEnabled || Tolerances.NearZero(axisOfRotation.Length)) { return; } axisOfRotation.Normalize(); Quaternion quaternion = new Quaternion(axisOfRotation, Math.Acos(Vector3D.DotProduct(this.initialPosition, positionFromPointer)) * 57.2957795130823) * this.initialOrientation; this.Orientation = (Rotation3D) new AxisAngleRotation3D(quaternion.Axis, quaternion.Angle); }
protected override bool OnDragEnd(Point dragStartPosition, Point dragEndPosition) { if (!this.IsProjectedInsertionPoint) { SceneView activeView = this.ActiveView; SceneViewModel viewModel = activeView.ViewModel; bool flag = false; if (this.pointList.Count >= 4) { Point point1 = this.pointList[0]; Point point2 = this.pointList[this.pointList.Count - 1]; if (Tolerances.DoPointsHit(point1, point2, activeView.Zoom)) { this.pointList[this.pointList.Count - 1] = point1; flag = true; } } PropertyManager propertyManager = (PropertyManager)this.ToolBehaviorContext.PropertyManager; BezierCurveFitter bezierCurveFitter = new BezierCurveFitter(); PathGeometry pathGeometry = !DebugVariables.Instance.EnableRealTimeFitting ? (!flag ? bezierCurveFitter.OpenFit(this.pointList, true, Tolerances.CurveFitCornerThreshold, Tolerances.CurveFittingDistanceTolerance(activeView.Zoom), true) : bezierCurveFitter.ClosedFit(this.pointList, true, Tolerances.CurveFitCornerThreshold, Tolerances.CurveFittingDistanceTolerance(activeView.Zoom), true)) : this.vpFitter.Path; try { this.EnsureEditTransaction(); Matrix transformFromRoot = activeView.GetComputedTransformFromRoot(this.ActiveSceneInsertionPoint.SceneElement); new PathFigureEditor(pathGeometry.Figures[0]).ApplyTransform(transformFromRoot); viewModel.ElementSelectionSet.Clear(); this.CreatePathElement(); this.UpdateEditTransaction(); if (this.EditingElement.IsViewObjectValid) { using (ScenePathEditorTarget pathEditorTarget = new ScenePathEditorTarget((PathElement)this.EditingElement)) { pathEditorTarget.BeginEditing(); pathEditorTarget.PathGeometry = pathGeometry; pathEditorTarget.EndEditing(true); } } this.CommitEditTransaction(); this.Tool.RebuildAdornerSets(); } finally { this.CancelEditTransaction(); this.ClearFeedback(); this.PreviewInsertionPoint = (ISceneInsertionPoint)null; } } return(true); }
private void ScopeElement_MouseMove(object sender, MouseEventArgs args) { if (this.ActiveBehavior == null) { return; } if ((Keyboard.Modifiers & ModifierKeys.Alt) != ModifierKeys.None) { this.consumeAltKey = true; } Point position = args.GetPosition((IInputElement)this.scopeElement); if (position == this.lastDragPosition) { return; } this.lastDragPosition = position; FrameworkElement rootElement = this.RootElement; if (rootElement == null) { return; } GeneralTransform generalTransform = this.scopeElement.TransformToDescendant((Visual)rootElement); if (generalTransform == null) { return; } Point point = position * VectorUtilities.GetMatrixFromTransform(generalTransform); if (this.IsButtonDown && this.buttonDownHandled) { if (!this.IsDragging && !Tolerances.HaveMoved(this.dragStartPosition, point, this.view.Zoom)) { return; } this.isDragging = true; this.dragCurrentPosition = point; args.Handled = this.ActiveBehavior.HandleDrag(this.dragStartPosition, this.dragCurrentPosition); } else { args.Handled = this.ActiveBehavior.HandleHover(point); } }
private bool ReadCanonicalForm(Transform3D transform, bool useIfChangeable) { if (!CanonicalTransform3D.IsCanonical(transform)) { return(false); } Transform3DGroup transform3Dgroup = (Transform3DGroup)transform; ScaleTransform3D scaleTransform3D = transform3Dgroup.Children[1] as ScaleTransform3D; RotateTransform3D rotateTransform3D = transform3Dgroup.Children[2] as RotateTransform3D; TranslateTransform3D translateTransform3D1 = transform3Dgroup.Children[3] as TranslateTransform3D; TranslateTransform3D translateTransform3D2 = transform3Dgroup.Children[4] as TranslateTransform3D; this.center = new Point3D(translateTransform3D1.OffsetX, translateTransform3D1.OffsetY, translateTransform3D1.OffsetZ); this.scale = new Vector3D(scaleTransform3D.ScaleX, scaleTransform3D.ScaleY, scaleTransform3D.ScaleZ); this.translation = new Vector3D(translateTransform3D2.OffsetX, translateTransform3D2.OffsetY, translateTransform3D2.OffsetZ); if (useIfChangeable && !transform3Dgroup.IsFrozen) { this.transformGroup = transform3Dgroup; } else { this.InitializeTransformGroup(); Vector3D? nullable = (Vector3D?)rotateTransform3D.GetValue(CanonicalTransform3D.EulerAnglesProperty); bool flag = nullable.HasValue; AxisAngleRotation3D axisAngleRotation3D = rotateTransform3D.Rotation as AxisAngleRotation3D; Quaternion orientation = Quaternion.Identity; if (axisAngleRotation3D != null) { orientation = new Quaternion(axisAngleRotation3D.Axis, axisAngleRotation3D.Angle); } if (flag) { Quaternion quaternion = Helper3D.QuaternionFromEulerAngles(nullable.Value); if (!Tolerances.AreClose(quaternion.Angle, orientation.Angle) || !Tolerances.AreClose(quaternion.Axis, orientation.Axis)) { flag = false; } } if (!flag) { nullable = new Vector3D?(Helper3D.EulerAnglesFromQuaternion(orientation)); } this.RotationAngles = nullable.Value; } return(true); }
private void GetArcGeometry(Vector3D axis1, Vector3D axis2, Vector3D normal, out PathGeometry frontGeometry, out PathGeometry backGeometry) { Vector3D vector3D = Vector3D.CrossProduct(normal, new Vector3D(0.0, 0.0, 1.0)); if (Tolerances.NearZero(vector3D.Length)) { Point point = new Point(this.ActualWidth / 2.0, this.ActualHeight / 2.0); double num = this.ActualWidth / 2.0; Vector vector1 = new Vector(1.0, 0.0); Vector vector2 = new Vector(0.0, -1.0); Point top = point + vector2 * num; Point bottom = point - vector2 * num; Point left = point - vector1 * num; Point right = point + vector1 * num; double horizontalScale = num * ArcBallPresenter.tangentSize; double verticalScale = num * ArcBallPresenter.tangentSize; frontGeometry = this.GetEllipseGeometry(left, top, right, bottom, horizontalScale, verticalScale); backGeometry = new PathGeometry(); } else { vector3D.Normalize(); axis1 = vector3D; axis2 = Vector3D.CrossProduct(normal, axis1); if (axis2.Z < 0.0) { axis2 = -axis2; } Vector vector1 = new Vector(axis1.X, -axis1.Y); Vector vector2 = new Vector(axis2.X, -axis2.Y); Point center = new Point(this.ActualWidth / 2.0, this.ActualHeight / 2.0); double num = this.ActualWidth / 2.0; Point top1 = center + vector2 * num; Point top2 = center - vector2 * num; Point point1 = center + vector1 * num; Point point2 = center - vector1 * num; double horizontalScale = vector1.Length * num * ArcBallPresenter.tangentSize; double verticalScale = vector2.Length * num * ArcBallPresenter.tangentSize; frontGeometry = this.GetSemiEllipseGeometry(point1, top1, point2, center, horizontalScale, verticalScale); backGeometry = this.GetSemiEllipseGeometry(point2, top2, point1, center, horizontalScale, verticalScale); } }
protected void GetBrushOffsetEndpoints(out Point startPoint, out Point endPoint, double startOffset, double endOffset, Matrix matrix) { this.GetBrushEndpoints(out startPoint, out endPoint); Matrix matrix1 = this.GetCompleteBrushTransformMatrix(true) * matrix; startPoint *= matrix1; endPoint *= matrix1; Vector vector = startPoint - endPoint; if (Tolerances.NearZero(vector.LengthSquared)) { vector = new Vector(1.0, 0.0); } else { vector.Normalize(); } startPoint += startOffset * vector; endPoint -= endOffset * vector; }