private void UpdateTranslation(bool scrollNow) { SceneView activeView = this.ActiveView; SceneViewModel viewModel = activeView.ViewModel; Vector delta = this.dragCurrentPosition - this.dragStartPosition; if (this.isConstraining) { delta = this.ConstrainDeltaToAxis(delta); } if (delta == this.lastMove || this.IsAltDown) { return; } this.EnsureEditTransaction(); Vector vector1 = delta - this.lastMove; SceneElement primarySelection = viewModel.ElementSelectionSet.PrimarySelection; if (primarySelection == null) { return; } PropertyReference propertyReference = this.GetBrushPropertyReference((SceneNode)primarySelection); if (propertyReference == null) { return; } object computedValue = primarySelection.GetComputedValue(propertyReference); if (computedValue != null && !PlatformTypes.IsInstance(computedValue, PlatformTypes.SolidColorBrush, (ITypeResolver)primarySelection.ProjectContext)) { Vector vector2 = vector1 * activeView.GetComputedTransformFromRoot(primarySelection) * BrushAdorner.GetCompleteInverseBrushTransformMatrix((Base2DElement)primarySelection, computedValue, true); if (PlatformTypes.IsInstance(computedValue, PlatformTypes.LinearGradientBrush, (ITypeResolver)primarySelection.ProjectContext) && this.Tool is GradientBrushTool) { ReferenceStep referenceStep1 = (ReferenceStep)viewModel.ProjectContext.ResolveProperty(LinearGradientBrushNode.StartPointProperty); ReferenceStep referenceStep2 = (ReferenceStep)viewModel.ProjectContext.ResolveProperty(LinearGradientBrushNode.EndPointProperty); Point point1 = RoundingHelper.RoundPosition((Point)viewModel.DefaultView.ConvertToWpfValue(referenceStep1.GetCurrentValue(computedValue)) + vector2); Point point2 = RoundingHelper.RoundPosition((Point)viewModel.DefaultView.ConvertToWpfValue(referenceStep2.GetCurrentValue(computedValue)) + vector2); this.SetBrushValue(LinearGradientBrushNode.StartPointProperty, (object)point1); this.SetBrushValue(LinearGradientBrushNode.EndPointProperty, (object)point2); } else if (PlatformTypes.IsInstance(computedValue, PlatformTypes.RadialGradientBrush, (ITypeResolver)primarySelection.ProjectContext) && this.Tool is GradientBrushTool) { ReferenceStep referenceStep1 = (ReferenceStep)viewModel.ProjectContext.ResolveProperty(RadialGradientBrushNode.CenterProperty); ReferenceStep referenceStep2 = (ReferenceStep)viewModel.ProjectContext.ResolveProperty(RadialGradientBrushNode.GradientOriginProperty); Point point1 = RoundingHelper.RoundPosition((Point)viewModel.DefaultView.ConvertToWpfValue(referenceStep1.GetCurrentValue(computedValue)) + vector2); Point point2 = RoundingHelper.RoundPosition((Point)viewModel.DefaultView.ConvertToWpfValue(referenceStep2.GetCurrentValue(computedValue)) + vector2); this.SetBrushValue(RadialGradientBrushNode.CenterProperty, (object)point1); this.SetBrushValue(RadialGradientBrushNode.GradientOriginProperty, (object)point2); } else { this.TranslateBrushPosition(vector1 * activeView.GetComputedTransformFromRoot(primarySelection) * BrushAdorner.GetCompleteInverseBrushTransformMatrix((Base2DElement)primarySelection, computedValue, false), primarySelection); } } activeView.EnsureVisible(this.dragStartPosition + delta, scrollNow); this.lastMove = delta; this.UpdateEditTransaction(); }
private void UpdateRotation() { this.actionString = StringTable.UndoUnitLinearGradientRotation; if (!this.HasMouseMovedAfterDown) { this.CopyPrimaryBrushToSelection(); } Vector vector = this.dragCurrentPosition - this.centerInRootCoordinates; double num = Math.Atan2(vector.Y, vector.X); if (this.IsShiftDown) { num = Math.Round(num * 57.2957795130823 / 15.0) * 15.0 * (Math.PI / 180.0); } vector = new Vector(this.radiusInRootCoordinates * Math.Cos(num), this.radiusInRootCoordinates * Math.Sin(num)); Point point1 = this.centerInRootCoordinates + vector; Point point2 = this.centerInRootCoordinates - vector; Point point3 = RoundingHelper.RoundPosition(point1 * this.rootToBrushMatrix); Point point4 = RoundingHelper.RoundPosition(point2 * this.rootToBrushMatrix); if (this.ActiveAdorner.Kind == LinearGradientAdornerKind.EndRotation) { Point point5 = point3; point3 = point4; point4 = point5; } this.SetBrushValue(LinearGradientBrushNode.StartPointProperty, (object)point3); this.SetBrushValue(LinearGradientBrushNode.EndPointProperty, (object)point4); this.UpdateEditTransaction(); this.Cursor = this.ActiveAdorner.AdornerSet.GetCursor((IAdorner)this.ActiveAdorner); }
public void FloorShouldReturnCorrectResult_AlwaysDown() { var result = RoundingHelper.Round(26.75, 0.1, RoundingHelper.Direction.AlwaysDown); Assert.AreEqual(26.7, result); result = RoundingHelper.Round(26.75, 0.5, RoundingHelper.Direction.AlwaysDown); Assert.AreEqual(26.5, result); result = RoundingHelper.Round(26.75, 1, RoundingHelper.Direction.AlwaysDown); Assert.AreEqual(26, result); result = RoundingHelper.Round(26.75, 10, RoundingHelper.Direction.AlwaysDown); Assert.AreEqual(20, result); result = RoundingHelper.Round(26.75, 0, RoundingHelper.Direction.AlwaysDown); Assert.AreEqual(0, result); result = RoundingHelper.Round(-26.25, -0.5, RoundingHelper.Direction.AlwaysDown); Assert.AreEqual(-26.5, result); result = RoundingHelper.Round(-26.75, 1, RoundingHelper.Direction.AlwaysDown); Assert.AreEqual(-27, result); result = RoundingHelper.Round(-26.75, -1, RoundingHelper.Direction.AlwaysDown); Assert.AreEqual(-27, result); result = RoundingHelper.Round(-26.75, 5, RoundingHelper.Direction.AlwaysDown); Assert.AreEqual(-30, result); }
public void TranslateBrushPosition(Vector elementDelta, SceneElement element) { PropertyReference propertyReference = this.GetBrushPropertyReference((SceneNode)element); if (propertyReference == null) { return; } object computedValue = element.GetComputedValue(propertyReference); if (computedValue == null || PlatformTypes.IsInstance(computedValue, PlatformTypes.SolidColorBrush, (ITypeResolver)element.ProjectContext)) { return; } ReferenceStep referenceStep = (ReferenceStep)element.Platform.Metadata.ResolveProperty(BrushNode.RelativeTransformProperty); object obj = element.ViewModel.DefaultView.ConvertToWpfValue(referenceStep.GetCurrentValue(computedValue)); CanonicalTransform canonicalTransform = !(obj is Transform) ? new CanonicalTransform(Matrix.Identity) : new CanonicalTransform((Transform)obj); elementDelta *= canonicalTransform.TransformGroup.Value; double valueToSet1 = RoundingHelper.RoundLength(canonicalTransform.TranslationX + elementDelta.X); double valueToSet2 = RoundingHelper.RoundLength(canonicalTransform.TranslationY + elementDelta.Y); this.SetBrushTransformValue(element.Platform.Metadata.CommonProperties.BrushTranslationXReference, valueToSet1); this.SetBrushTransformValue(element.Platform.Metadata.CommonProperties.BrushTranslationYReference, valueToSet2); }
public void FloorShouldReturnCorrectResult_Down() { var result = RoundingHelper.Round(26.75, 0.1, RoundingHelper.Direction.Down); Assert.AreEqual(26.7, result); result = RoundingHelper.Round(26.75, 0.5, RoundingHelper.Direction.Down); Assert.AreEqual(26.5, result); result = RoundingHelper.Round(26.75, 1, RoundingHelper.Direction.Down); Assert.AreEqual(26, result); result = RoundingHelper.Round(26.75, 10, RoundingHelper.Direction.Down); Assert.AreEqual(20, result); result = RoundingHelper.Round(26.75, 20, RoundingHelper.Direction.Down); Assert.AreEqual(20, result); result = RoundingHelper.Round(-26.75, -0.1, RoundingHelper.Direction.Down); Assert.AreEqual(-26.7, result); result = RoundingHelper.Round(-26.75, -1, RoundingHelper.Direction.Down); Assert.AreEqual(-26, result); result = RoundingHelper.Round(-26.75, -5, RoundingHelper.Direction.Down); Assert.AreEqual(-25, result); result = RoundingHelper.Round(555, 1000, RoundingHelper.Direction.Down); Assert.AreEqual(0, result); result = RoundingHelper.Round(-555, -1000, RoundingHelper.Direction.Down); Assert.AreEqual(0, result); }
public void CeilingShouldReturnCorrectResult() { var result = RoundingHelper.Round(22.25, 0.1, RoundingHelper.Direction.Up); Assert.AreEqual(22.3, result); result = RoundingHelper.Round(22.25, 0.5, RoundingHelper.Direction.Up); Assert.AreEqual(22.5, result); result = RoundingHelper.Round(22.25, 1, RoundingHelper.Direction.Up); Assert.AreEqual(23, result); result = RoundingHelper.Round(22.25, 10, RoundingHelper.Direction.Up); Assert.AreEqual(30, result); result = RoundingHelper.Round(22.25, 20, RoundingHelper.Direction.Up); Assert.AreEqual(40, result); result = RoundingHelper.Round(-22.25, -0.1, RoundingHelper.Direction.Up); Assert.AreEqual(-22.3, result); result = RoundingHelper.Round(-22.25, -1, RoundingHelper.Direction.Up); Assert.AreEqual(-23, result); result = RoundingHelper.Round(-22.25, -5, RoundingHelper.Direction.Up); Assert.AreEqual(-25, result); result = RoundingHelper.Round(555, 1000, RoundingHelper.Direction.Up); Assert.AreEqual(1000, result); result = RoundingHelper.Round(-555, -1000, RoundingHelper.Direction.Up); Assert.AreEqual(-1000, result); }
public void CeilingShouldReturnCorrectResult_AlwaysUp() { var result = RoundingHelper.Round(22.25, 0.1, RoundingHelper.Direction.AlwaysUp); Assert.AreEqual(22.3, result); result = RoundingHelper.Round(22.25, 0.5, RoundingHelper.Direction.AlwaysUp); Assert.AreEqual(22.5, result); result = RoundingHelper.Round(22.25, -0.5, RoundingHelper.Direction.AlwaysUp); Assert.AreEqual(22.5, result); result = RoundingHelper.Round(22.25, 1, RoundingHelper.Direction.AlwaysUp); Assert.AreEqual(23, result); result = RoundingHelper.Round(22.25, 10, RoundingHelper.Direction.AlwaysUp); Assert.AreEqual(30, result); result = RoundingHelper.Round(22.25, 0, RoundingHelper.Direction.AlwaysUp); Assert.AreEqual(0, result); result = RoundingHelper.Round(-22.25, -0.5, RoundingHelper.Direction.AlwaysUp); Assert.AreEqual(-22, result); result = RoundingHelper.Round(-22.25, 1, RoundingHelper.Direction.AlwaysUp); Assert.AreEqual(-22, result); result = RoundingHelper.Round(-22.25, -1, RoundingHelper.Direction.AlwaysUp); Assert.AreEqual(-22, result); result = RoundingHelper.Round(-22.25, 5, RoundingHelper.Direction.AlwaysUp); Assert.AreEqual(-20, result); }
protected override bool OnDrag(Point dragStartPosition, Point dragCurrentPosition, bool scrollNow) { SceneView activeView = this.ActiveView; this.EnsureEditTransaction(); dragCurrentPosition = this.ToolBehaviorContext.SnappingEngine.SnapPoint(dragCurrentPosition); Point point = dragCurrentPosition * activeView.GetComputedTransformFromRoot(this.EditingElement.Visual); if (this.ActiveAdorner.IsX) { double num = RoundingHelper.RoundLength(Math.Max(0.0, Math.Min(point.X, this.ActiveView.GetRenderSize(this.EditingElement.Visual).Width / 2.0) - this.ActiveAdorner.HalfStrokeThickness)); this.EditingElement.SetValue(RectangleElement.RadiusXProperty, (object)num); if (!this.IsShiftDown) { this.EditingElement.SetValue(RectangleElement.RadiusYProperty, (object)num); } } else { double num = RoundingHelper.RoundLength(Math.Max(0.0, Math.Min(point.Y, this.ActiveView.GetRenderSize(this.EditingElement.Visual).Height / 2.0) - this.ActiveAdorner.HalfStrokeThickness)); this.EditingElement.SetValue(RectangleElement.RadiusYProperty, (object)num); if (!this.IsShiftDown) { this.EditingElement.SetValue(RectangleElement.RadiusXProperty, (object)num); } } this.UpdateEditTransaction(); activeView.EnsureVisible((IAdorner)this.ActiveAdorner, scrollNow); return(true); }
public void TestRounding() { Assert.AreEqual(3.00, RoundingHelper.Round(3.249)); Assert.AreEqual(3.50, RoundingHelper.Round(3.25)); Assert.AreEqual(3.50, RoundingHelper.Round(3.6)); Assert.AreEqual(4.00, RoundingHelper.Round(3.75)); }
/// <summary> /// Gets an additional handling fee of a payment method /// </summary> /// <param name="cart">Shoping cart</param> /// <param name="paymentMethodSystemName">Payment method system name</param> /// <returns>Additional handling fee</returns> public virtual async Task <decimal> GetAdditionalHandlingFee(IList <ShoppingCartItem> cart, string paymentMethodSystemName) { if (String.IsNullOrEmpty(paymentMethodSystemName)) { return(decimal.Zero); } var paymentMethod = LoadPaymentMethodBySystemName(paymentMethodSystemName); if (paymentMethod == null) { return(decimal.Zero); } decimal result = await paymentMethod.GetAdditionalHandlingFee(cart); if (result < decimal.Zero) { result = decimal.Zero; } if (_shoppingCartSettings.RoundPricesDuringCalculation) { var currency = await _currencyService.GetPrimaryExchangeRateCurrency(); result = RoundingHelper.RoundPrice(result, currency); } return(result); }
/// <summary> /// Adjust shipping rate (free shipping, additional charges, discounts) /// </summary> /// <param name="shippingRate">Shipping rate to adjust</param> /// <param name="cart">Cart</param> /// <param name="appliedDiscount">Applied discount</param> /// <returns>Adjusted shipping rate</returns> public virtual decimal AdjustShippingRate(decimal shippingRate, IList <ShoppingCartItem> cart, out Discount appliedDiscount) { appliedDiscount = null; //free shipping if (IsFreeShipping(cart)) { return(decimal.Zero); } //additional shipping charges decimal additionalShippingCharge = GetShoppingCartAdditionalShippingCharge(cart); var adjustedRate = shippingRate + additionalShippingCharge; //discount var customer = cart.GetCustomer(); decimal discountAmount = GetShippingDiscount(customer, adjustedRate, out appliedDiscount); adjustedRate = adjustedRate - discountAmount; if (adjustedRate < decimal.Zero) { adjustedRate = decimal.Zero; } if (_shoppingCartSettings.RoundPricesDuringCalculation) { adjustedRate = RoundingHelper.RoundPrice(adjustedRate); } return(adjustedRate); }
protected virtual void ComputeIdealMargin() { bool flag1 = (this.WidthConstraintMode & LayoutConstraintMode.CanvasLike) == LayoutConstraintMode.NonOverlappingGridlike; bool flag2 = (this.HeightConstraintMode & LayoutConstraintMode.CanvasLike) == LayoutConstraintMode.NonOverlappingGridlike; this.Settings.Margin = new Thickness(RoundingHelper.RoundLength(!flag1 || this.Settings.HorizontalAlignment != HorizontalAlignment.Left && this.Settings.HorizontalAlignment != HorizontalAlignment.Stretch ? 0.0 : this.ChildRect.Left - this.SlotRect.Left), RoundingHelper.RoundLength(!flag2 || this.Settings.VerticalAlignment != VerticalAlignment.Top && this.Settings.VerticalAlignment != VerticalAlignment.Stretch ? 0.0 : this.ChildRect.Top - this.SlotRect.Top), RoundingHelper.RoundLength(!flag1 || this.Settings.HorizontalAlignment != HorizontalAlignment.Right && this.Settings.HorizontalAlignment != HorizontalAlignment.Stretch ? 0.0 : this.SlotRect.Right - this.ChildRect.Right), RoundingHelper.RoundLength(!flag2 || this.Settings.VerticalAlignment != VerticalAlignment.Bottom && this.Settings.VerticalAlignment != VerticalAlignment.Stretch ? 0.0 : this.SlotRect.Bottom - this.ChildRect.Bottom)); }
public override void SetRootSize(BaseFrameworkElement root, Size size, bool setWidth, bool setHeight) { root.ViewModel.DefaultView.UpdateLayout(); if (!root.ViewModel.IsInGridDesignMode && root is GridElement) { size = RoundingHelper.RoundSize(size); using (GridLayoutDesigner.TryCanvasDesignMode(root, size, setWidth, setHeight)) { BaseFrameworkElement sizeElement = this.GetSizeElement(root); if (setHeight) { sizeElement.Height = size.Height; } if (!setWidth) { return; } sizeElement.Width = size.Width; } } else { base.SetRootSize(root, size, setWidth, setHeight); } }
protected virtual void UpdateCenterPoint(Point centerPoint) { CanonicalTransform canonicalTransform = new CanonicalTransform((Transform)this.EditingElement.GetComputedValueAsWpf(Base2DElement.RenderTransformProperty)); Point elementCoordinates = this.BaseEditingElement.RenderTransformOriginInElementCoordinates; Vector translation = canonicalTransform.Translation; Rect computedTightBounds = ((Base2DElement)this.EditingElement).GetComputedTightBounds(); Point renderTransformOrigin = this.BaseEditingElement.RenderTransformOrigin; Point point2 = new Point((centerPoint.X - computedTightBounds.Left) / (computedTightBounds.Width == 0.0 ? 1.0 : computedTightBounds.Width), (centerPoint.Y - computedTightBounds.Top) / (computedTightBounds.Height == 0.0 ? 1.0 : computedTightBounds.Height)); point2 = RoundingHelper.RoundPosition(point2); Point newOrigin = new Point(computedTightBounds.Left + point2.X * computedTightBounds.Width, computedTightBounds.Top + point2.Y * computedTightBounds.Height); canonicalTransform.UpdateForNewOrigin(elementCoordinates, newOrigin); canonicalTransform.TranslationX = RoundingHelper.RoundLength(canonicalTransform.TranslationX); canonicalTransform.TranslationY = RoundingHelper.RoundLength(canonicalTransform.TranslationY); if (!Point.Equals(renderTransformOrigin, point2)) { this.BaseEditingElement.RenderTransformOrigin = point2; } if (!object.Equals((object)translation.X, (object)canonicalTransform.TranslationX)) { this.EditingElement.SetValue(this.EditingElement.Platform.Metadata.CommonProperties.RenderTransformTranslationX, (object)canonicalTransform.TranslationX); } if (object.Equals((object)translation.Y, (object)canonicalTransform.TranslationY)) { return; } this.EditingElement.SetValue(this.EditingElement.Platform.Metadata.CommonProperties.RenderTransformTranslationY, (object)canonicalTransform.TranslationY); }
public Vector2 GetCeilDirection(Vector2 velocity) { Vector2 velocityNormalized = velocity.normalized; Vector2 ceilDirection = new Vector2(RoundingHelper.InvertOnNegativeCeil(velocityNormalized.x), RoundingHelper.InvertOnNegativeCeil(velocityNormalized.y)); return(ceilDirection); }
private void UpdateCollisions(Collision2D collision) { Vector2 allDirections = new Vector2(); foreach (ContactPoint2D contact in collision.contacts) { Vector2 direction = (contact.point - (Vector2)transform.position).normalized; Vector2 ceiledDirection = new Vector2(); if (Mathf.Abs(direction.x) > Mathf.Abs(direction.y)) { ceiledDirection.x = RoundingHelper.InvertOnNegativeCeil(direction.x); } else { ceiledDirection.y = RoundingHelper.InvertOnNegativeCeil(direction.y); } allDirections += ceiledDirection; } Vector2 combinedDirection = VectorHelper.Clamp(allDirections, -1, 1); if (collisions.ContainsKey(collision.collider)) { collisions[collision.collider] = combinedDirection; } else { collisions.Add(collision.collider, combinedDirection); } }
/// <summary> /// Formats the price /// </summary> /// <param name="price">Price</param> /// <param name="showCurrency">A value indicating whether to show a currency</param> /// <param name="targetCurrency">Target currency</param> /// <param name="language">Language</param> /// <param name="priceIncludesTax">A value indicating whether price includes tax</param> /// <param name="showTax">A value indicating whether to show tax suffix</param> /// <returns>Price</returns> public virtual string FormatPrice(decimal price, bool showCurrency, Currency targetCurrency, Language language, bool priceIncludesTax, bool showTax) { //we should round it no matter of "ShoppingCartSettings.RoundPricesDuringCalculation" setting price = RoundingHelper.RoundPrice(price); string currencyString = GetCurrencyString(price, showCurrency, targetCurrency); if (showTax) { //show tax suffix string formatStr; if (priceIncludesTax) { formatStr = _localizationService.GetResource("Products.InclTaxSuffix", language.Id, false); if (String.IsNullOrEmpty(formatStr)) { formatStr = "{0} incl tax"; } } else { formatStr = _localizationService.GetResource("Products.ExclTaxSuffix", language.Id, false); if (String.IsNullOrEmpty(formatStr)) { formatStr = "{0} excl tax"; } } return(string.Format(formatStr, currencyString)); } return(currencyString); }
protected override void ApplyScale(Vector scale, Point center) { Rect elementBounds = this.EditingElementSet.ElementBounds; Matrix m = this.startSharedTransform; Matrix inverseMatrix = ElementUtilities.GetInverseMatrix(m); Matrix matrix1 = new Matrix(); matrix1.Translate(-center.X, -center.Y); foreach (SceneElement element in this.EditingElementSet.Elements) { Matrix matrix2 = this.elementToElementsTransformDictionary[element] * matrix1; Point point1 = this.startCentersDictionary[element]; Matrix matrix3 = this.startTransformsDictionary[element]; Rect rect = this.startBoundsDictionary[element]; Point point2 = new Point(rect.X + rect.Width * point1.X, rect.Y + rect.Height * point1.Y); Point point3 = matrix2.Transform(point2); Vector vector = new Point(scale.X * point3.X, scale.Y * point3.Y) - point3; Matrix matrix4 = matrix3 * inverseMatrix; matrix4.ScaleAt(scale.X, scale.Y, matrix4.OffsetX, matrix4.OffsetY); matrix4.Translate(vector.X, vector.Y); CanonicalDecomposition newTransform = new CanonicalDecomposition(matrix4 * m); newTransform.ScaleX = RoundingHelper.RoundScale(newTransform.ScaleX); newTransform.ScaleY = RoundingHelper.RoundScale(newTransform.ScaleY); newTransform.SkewX = RoundingHelper.RoundAngle(newTransform.SkewX); newTransform.SkewY = RoundingHelper.RoundAngle(newTransform.SkewY); newTransform.RotationAngle = RoundingHelper.RoundAngle(newTransform.RotationAngle); newTransform.TranslationX = RoundingHelper.RoundLength(newTransform.TranslationX); newTransform.TranslationY = RoundingHelper.RoundLength(newTransform.TranslationY); AdornedToolBehavior.UpdateElementTransform(element, newTransform, AdornedToolBehavior.TransformPropertyFlags.All); } }
/// <summary> /// Gets an additional handling fee of a payment method /// </summary> /// <param name="cart">Shoping cart</param> /// <param name="paymentMethodSystemName">Payment method system name</param> /// <returns>Additional handling fee</returns> public virtual decimal GetAdditionalHandlingFee(IList <ShoppingCartItem> cart, string paymentMethodSystemName) { if (String.IsNullOrEmpty(paymentMethodSystemName)) { return(decimal.Zero); } var paymentMethod = LoadPaymentMethodBySystemName(paymentMethodSystemName); if (paymentMethod == null) { return(decimal.Zero); } decimal result = paymentMethod.GetAdditionalHandlingFee(cart); if (result < decimal.Zero) { result = decimal.Zero; } if (_shoppingCartSettings.RoundPricesDuringCalculation) { var currency = EngineContext.Current.Resolve <ICurrencyService>().GetCurrencyById(EngineContext.Current.Resolve <CurrencySettings>().PrimaryExchangeRateCurrencyId); result = RoundingHelper.RoundPrice(result, currency); } return(result); }
/// <summary> /// Gets an additional handling fee of a payment method /// </summary> /// <param name="cart">Shoping cart</param> /// <param name="paymentMethodSystemName">Payment method system name</param> /// <returns>Additional handling fee</returns> public virtual decimal GetAdditionalHandlingFee(IList <ShoppingCartItem> cart, string paymentMethodSystemName) { if (String.IsNullOrEmpty(paymentMethodSystemName)) { return(decimal.Zero); } var paymentMethod = LoadPaymentMethodBySystemName(paymentMethodSystemName); if (paymentMethod == null) { return(decimal.Zero); } decimal result = paymentMethod.GetAdditionalHandlingFee(cart); if (result < decimal.Zero) { result = decimal.Zero; } if (_shoppingCartSettings.RoundPricesDuringCalculation) { result = RoundingHelper.RoundPrice(result); } return(result); }
public static double RoundDouble(IProjectContext projectContext, double d) { if (projectContext.IsCapabilitySet(PlatformCapability.UsesFloatsInternally)) { return(RoundingHelper.RoundToDoublePrecision(d, 6)); } return(d); }
public void RoundingsTest(decimal value, decimal rounded) { //arrange & act var result = RoundingHelper.Round(value, 2); //assert Assert.Equal(rounded, result); }
protected override bool IsValid(PropertyValidatorContext context) { if (decimal.TryParse(context.PropertyValue.ToString(), out decimal value)) { return(RoundingHelper.RoundPrice(value) < _maxValue); } return(false); }
private void UpdateModelFromMouse(Vector mousePositionDelta) { if (this.cameraElement == null || !(this.cameraElement is ProjectionCameraElement)) { return; } if (this.mouseMovementMode == CameraOrbitToolBehavior.MovementMode.Rotate) { this.totalAzimuthDelta += -mousePositionDelta.X / 2.0; this.totalElevationDelta += -mousePositionDelta.Y / 2.0; double angle1 = this.totalAzimuthDelta; if (this.IsShiftDown) { angle1 = CameraOrbitToolBehavior.shiftSnapAngle * Math.Round(angle1 / CameraOrbitToolBehavior.shiftSnapAngle); } RotateTransform3D rotateTransform3D1 = new RotateTransform3D(Vector3D.DotProduct((Vector3D)this.cameraElement.GetComputedValue(ProjectionCameraElement.UpDirectionProperty), this.cameraInitialUp) >= 0.0 ? (Rotation3D) new AxisAngleRotation3D(this.cameraInitialUp, angle1) : (Rotation3D) new AxisAngleRotation3D(-this.cameraInitialUp, angle1), this.cameraInitialLookAt); Point3D point = rotateTransform3D1.Transform(this.cameraInitialPosition); Vector3D vector3D1 = rotateTransform3D1.Transform(this.cameraInitialUp); Vector3D axis = Vector3D.CrossProduct(this.cameraInitialLookAt - point, vector3D1); double angle2 = this.totalElevationDelta; if (this.IsShiftDown) { angle2 = CameraOrbitToolBehavior.shiftSnapAngle * Math.Round(angle2 / CameraOrbitToolBehavior.shiftSnapAngle); } if (axis.LengthSquared == 0.0) { return; } RotateTransform3D rotateTransform3D2 = new RotateTransform3D((Rotation3D) new AxisAngleRotation3D(axis, angle2), this.cameraInitialLookAt); Point3D point3D1 = rotateTransform3D2.Transform(point); Vector3D vector3D2 = rotateTransform3D2.Transform(vector3D1); Point3D point3D2 = RoundingHelper.RoundPosition(point3D1); Vector3D vector3D3 = RoundingHelper.RoundDirection(vector3D2); Vector3D vector3D4 = RoundingHelper.RoundDirection(this.cameraInitialLookAt - point3D2); this.cameraElement.SetValue(ProjectionCameraElement.PositionProperty, (object)point3D2); this.cameraElement.SetValue(ProjectionCameraElement.UpDirectionProperty, (object)vector3D3); this.cameraElement.SetValue(ProjectionCameraElement.LookDirectionProperty, (object)vector3D4); } else { Matrix3D matrix3D = Helper3D.CameraRotationMatrix((Camera)this.cameraElement.ViewObject.PlatformSpecificObject); if (this.mouseMovementMode == CameraOrbitToolBehavior.MovementMode.TranslateXY) { Vector3D vector3D1 = new Vector3D(matrix3D.M11, matrix3D.M21, matrix3D.M31); Vector3D vector3D2 = new Vector3D(matrix3D.M12, matrix3D.M22, matrix3D.M32); this.cameraInitialPosition += this.scale * (-mousePositionDelta.X * vector3D1 + mousePositionDelta.Y * vector3D2); } else { Vector3D vector3D1 = new Vector3D(matrix3D.M13, matrix3D.M23, matrix3D.M33); this.cameraInitialPosition += this.scale * mousePositionDelta.Y * vector3D1; Vector3D vector3D2 = RoundingHelper.RoundDirection(this.cameraInitialLookAt - this.cameraInitialPosition); this.cameraElement.SetValue(ProjectionCameraElement.LookDirectionProperty, (object)vector3D2); } this.cameraInitialPosition = RoundingHelper.RoundPosition(this.cameraInitialPosition); this.cameraElement.SetValue(ProjectionCameraElement.PositionProperty, (object)this.cameraInitialPosition); } }
protected override void UpdateModelFromMouse(Base3DElement selected3DElement, Vector mousePositionDelta) { Camera camera = (Camera)selected3DElement.Viewport.Camera.ViewObject.PlatformSpecificObject; Matrix3D matrix3D1 = Helper3D.CameraRotationMatrix(camera); Matrix3D matrix3D2 = camera.Transform.Value; if (matrix3D2.HasInverse) { matrix3D2.Invert(); matrix3D1 *= matrix3D2; } Vector3D vector1 = new Vector3D(matrix3D1.M11, matrix3D1.M21, matrix3D1.M31); Vector3D vector2_1 = new Vector3D(matrix3D1.M12, matrix3D1.M22, matrix3D1.M32); Vector3D vector2_2 = new Vector3D(matrix3D1.M13, matrix3D1.M23, matrix3D1.M33); Base3DElement base3Delement = selected3DElement.Parent as Base3DElement; Matrix3D matrix3D3 = Matrix3D.Identity; if (base3Delement != null) { matrix3D3 = base3Delement.GetComputedTransformFromRoot3DElementToElement(); matrix3D3.Invert(); } if (this.mouseMovementMode == ObjectRotateTranslateBehavior.MovementMode.Rotate) { mousePositionDelta /= 2.0; Vector3D axisOfRotation = Vector3D.CrossProduct(new Vector3D(-mousePositionDelta.X, mousePositionDelta.Y, 0.0), vector2_2); double length = axisOfRotation.Length; if (length <= 0.0) { return; } Vector3D vector3D = Helper3D.EulerAnglesFromQuaternion(new Quaternion(axisOfRotation, length) * Helper3D.QuaternionFromEulerAngles(selected3DElement.CanonicalRotationAngles)); vector3D = new Vector3D(RoundingHelper.RoundAngle(vector3D.X), RoundingHelper.RoundAngle(vector3D.Y), RoundingHelper.RoundAngle(vector3D.Z)); selected3DElement.CanonicalRotationAngles = vector3D; } else { Vector3D vector3D1 = new Vector3D(selected3DElement.CanonicalTranslationX, selected3DElement.CanonicalTranslationY, selected3DElement.CanonicalTranslationZ); Point lastMousePosition = this.LastMousePosition; Point endPoint = lastMousePosition + mousePositionDelta; Vector3D vector3D2; if (this.mouseMovementMode == ObjectRotateTranslateBehavior.MovementMode.TranslateXY) { Plane3D plane = new Plane3D(Vector3D.CrossProduct(vector1, vector2_1), this.hitPoint); Vector3D vector = Helper3D.VectorBetweenPointsOnPlane((Viewport3D)selected3DElement.Viewport.ViewObject.PlatformSpecificObject, plane, lastMousePosition, endPoint); Vector3D vector3D3 = matrix3D3.Transform(vector); vector3D2 = vector3D1 + vector3D3; } else { double scale = this.Scale; vector3D2 = vector3D1 + scale * -mousePositionDelta.Y * vector2_2; } selected3DElement.CanonicalTranslationX = RoundingHelper.RoundLength(vector3D2.X); selected3DElement.CanonicalTranslationY = RoundingHelper.RoundLength(vector3D2.Y); selected3DElement.CanonicalTranslationZ = RoundingHelper.RoundLength(vector3D2.Z); } }
/// <summary> /// Generates ticks for given range and preferred ticks count. /// </summary> /// <param name="range">The range.</param> /// <param name="ticksCount">The ticks count.</param> /// <returns></returns> public ITicksInfo <int> GetTicks(Range <int> range, int ticksCount) { double start = range.Min; double finish = range.Max; double delta = finish - start; int log = (int)Math.Round(Math.Log10(delta)); double newStart = RoundingHelper.Round(start, log); double newFinish = RoundingHelper.Round(finish, log); if (newStart == newFinish) { log--; newStart = RoundingHelper.Round(start, log); newFinish = RoundingHelper.Round(finish, log); } // calculating step between ticks double unroundedStep = (newFinish - newStart) / ticksCount; int stepLog = log; // trying to round step int step = (int)RoundingHelper.Round(unroundedStep, stepLog); if (step == 0) { stepLog--; step = (int)RoundingHelper.Round(unroundedStep, stepLog); if (step == 0) { // step will not be rounded if attempts to be rounded to zero. step = (int)unroundedStep; } } if (step < minStep) { step = minStep; } if (step > maxStep) { step = maxStep; } if (step <= 0) { step = 1; } int[] ticks = CreateTicks(start, finish, step); TicksInfo <int> res = new TicksInfo <int> { Info = log, Ticks = ticks }; return(res); }
protected override void UpdateModelFromMouse(Base3DElement selected3DElement, Vector mousePositionDelta) { double num = this.mouseMovementAxis * mousePositionDelta; Vector3D vector3D = new Vector3D(selected3DElement.CanonicalTranslationX, selected3DElement.CanonicalTranslationY, selected3DElement.CanonicalTranslationZ) + this.Scale * num * this.translationAxis; selected3DElement.CanonicalTranslationX = RoundingHelper.RoundLength(vector3D.X); selected3DElement.CanonicalTranslationY = RoundingHelper.RoundLength(vector3D.Y); selected3DElement.CanonicalTranslationZ = RoundingHelper.RoundLength(vector3D.Z); }
private System.Windows.Media.Geometry GetTransformedClippingGeometry(SceneElement clipper, Transform transform) { RectangleElement rectangleElement = clipper as RectangleElement; if (rectangleElement == null || !this.DesignerContext.ActiveDocument.ProjectContext.IsCapabilitySet(PlatformCapability.PrefersRectangularClippingPath)) { PathGeometry pathGeometry = PathGeometryUtilities.TransformGeometry(this.ApplyCurrentClippingToGeometry((System.Windows.Media.Geometry)PathConversionHelper.ConvertToPathGeometry(clipper), clipper), transform); if (pathGeometry.Bounds == Rect.Empty) { pathGeometry = new PathGeometry(); } return((System.Windows.Media.Geometry)pathGeometry); } RectangleGeometry rectangleGeometry = rectangleElement.ViewModel.DefaultView.GetRenderedGeometryAsWpf((SceneElement)rectangleElement) as RectangleGeometry; if (rectangleGeometry == null) { return((System.Windows.Media.Geometry) new RectangleGeometry()); } CanonicalDecomposition canonicalDecomposition = new CanonicalDecomposition(transform.Value); Matrix matrix = new Matrix(); matrix.Scale(canonicalDecomposition.ScaleX, canonicalDecomposition.ScaleY); matrix.Translate(canonicalDecomposition.TranslationX, canonicalDecomposition.TranslationY); Rect rect = rectangleGeometry.Rect; rect.Transform(matrix); rectangleGeometry.Rect = RoundingHelper.RoundRect(rect); CanonicalTransform canonicalTransform = new CanonicalTransform(); bool flag = false; canonicalTransform.CenterX = canonicalDecomposition.TranslationX; canonicalTransform.CenterY = canonicalDecomposition.TranslationY; if (canonicalDecomposition.RotationAngle != 0.0) { canonicalTransform.RotationAngle = canonicalDecomposition.RotationAngle; flag = true; } if (canonicalDecomposition.SkewX != 0.0 || canonicalDecomposition.SkewY != 0.0) { canonicalTransform.SkewX = RoundingHelper.RoundLength(canonicalDecomposition.SkewX); canonicalTransform.SkewY = RoundingHelper.RoundLength(canonicalDecomposition.SkewY); flag = true; } if (flag) { rectangleGeometry.Transform = (Transform)canonicalTransform.TransformGroup; } if ((double)rectangleElement.GetComputedValue(RectangleElement.RadiusXProperty) != 0.0 || (double)rectangleElement.GetComputedValue(RectangleElement.RadiusYProperty) != 0.0) { rectangleGeometry.ClearValue(RectangleGeometry.RadiusXProperty); rectangleGeometry.ClearValue(RectangleGeometry.RadiusYProperty); this.SceneView.ShowBubble(StringTable.ClippingRectanglePropertiesLostWarning, MessageBubbleType.Warning); } return((System.Windows.Media.Geometry)rectangleGeometry); }
private void UpdateRotation() { double num = this.unsnappedAngle; if (this.snapping) { num = this.SnapToAngle(this.unsnappedAngle, RotateBehavior.shiftSnapAngle); } this.ApplyRotation(RoundingHelper.RoundAngle(num)); }
private void AddGradientStop(object sender, ExecutedRoutedEventArgs eventArgs) { GradientBrushEditor gradientBrushEditor = (GradientBrushEditor)this.DataContext; if (gradientBrushEditor == null) { return; } gradientBrushEditor.AddGradientStop((IInputElement)this, RoundingHelper.RoundScale((double)eventArgs.Parameter)); }