public virtual void MoveToViewControllerAtIndex(int index, bool animated) { if (!IsViewLoaded) { CurrentIndex = index; } else { if (SkipIntermediateViewControllers && NMath.Abs(CurrentIndex - index) > 1) { var originalPagerTabStripChildViewControllers = _pagerTabStripChildViewControllers; var tempChildControllerList = _pagerTabStripChildViewControllers.ToList(); var currentChildVC = originalPagerTabStripChildViewControllers [(int)CurrentIndex]; nint fromIndex = (CurrentIndex < index) ? index - 1 : index + 1; tempChildControllerList [(int)CurrentIndex] = originalPagerTabStripChildViewControllers [(int)fromIndex]; tempChildControllerList [(int)fromIndex] = currentChildVC; _pagerTabStripChildViewControllers = tempChildControllerList; ContainerView.SetContentOffset(new CGPoint(PageOffsetForChildIndex(fromIndex), 0), false); if (NavigationController != null) { NavigationController.View.UserInteractionEnabled = false; } else { View.UserInteractionEnabled = false; } _originalPagerTabStripChildViewControllers = originalPagerTabStripChildViewControllers; ContainerView.SetContentOffset(new CGPoint(PageOffsetForChildIndex(index), 0), true); } else { ContainerView.SetContentOffset(new CGPoint(PageOffsetForChildIndex(index), 0), animated); } } }
public static void SetTransparencyMask(this UIView view, nfloat top, nfloat bottom) { if (top > view.Frame.Height || bottom > view.Frame.Height) { view.Layer.Mask = view.visibilityMaskWithLocation(1); } else if (top >= 0 && top <= view.Frame.Height) { var location = top / view.Frame.Height; view.Layer.Mask = view.visibilityMaskWithLocation(location); } else if (bottom >= 0 && bottom <= view.Frame.Height) { var location = NMath.Abs(1 - (bottom / view.Frame.Height)); view.Layer.Mask = view.visibilityMaskWithLocation(location, true); } else { view.Layer.Mask = null; } view.Layer.MasksToBounds = true; }
private void Mstep() { double x, xn, f, df, step; double v = NMath.Log(en2 / en1) - en3 / en1; x = param.A; do { f = NMath.Log(x) - NMath.Psi(x) - v; df = 1.0 / x - NMath.Polygamma(1, x); step = 1.0; do { xn = x - step * f / df; if (xn > 0.0) { break; } step *= 0.5; } while (true); if (double.IsNaN(x) || double.IsInfinity(x)) { throw new System.NotFiniteNumberException(); } if (NMath.Abs(xn - x) < newton_eps * NMath.Abs(x)) { break; } x = xn; } while (true); param.A = xn; param.Omega = en1; param.C = param.A * en1 / en2; }
public virtual double Quantile(double p, double eps) { int cnt = 1; double x, xn; x = QuantileInit(); // init x do { xn = x - 0.1 * (Cdf(x) - p) / Pdf(x); if (double.IsInfinity(x) || double.IsNaN(x)) { return(double.NaN); } if (NMath.Abs(xn - x) < eps * NMath.Abs(x)) { break; } x = xn; cnt++; if (cnt >= 10000) { break; } } while (true); return(xn); }
private static double GetNormalQuantile(double eps) { double leps = NMath.Log(eps); if (leps > -6.6 || leps < -689.0) { throw new InvalidOperationException(); } double l = 3.0; double u = 37.0; double m = (l + u) / 2.0; double fm = GetApproximateNormalTail(m) - leps; while (NMath.Abs(fm) > 1.0e-8) { if (fm > 0) { l = m; } else { u = m; } m = (l + u) / 2.0; fm = GetApproximateNormalTail(m) - leps; } return(m); }
void TrackPause(nfloat velocity, nfloat offset) { if (hasPaused) { return; } // update the array of most recent velocities if (velocities.Count >= numberOfVelocities) { velocities.RemoveAt(0); } velocities.Add(velocity); // enforce minimum velocity and offset if (NMath.Abs(velocity) > 100 || Math.Abs(offset) < 50) { return; } var firstRecorded = velocities [0]; // if the majority of the velocity has been lost recetly, we consider the motion to be paused if (NMath.Abs(firstRecorded - velocity) / NMath.Abs(firstRecorded) > 0.9) { pauseLabel.Alpha = 1; feedbackGenerator.ImpactOccurred(); hasPaused = true; velocities.Clear(); } }
public double Rdiff(IModelParam param) { CPHParam v = param as CPHParam; double o = NMath.Abs(omega - v.omega) / v.omega; double a = Blas.Rdiff(ndim, alpha, v.alpha); double b = Blas.Rdiff(ndim, rate, v.rate); return(NMath.Max(o, a, b)); }
public double Adiff(IModelParam param) { HErlangParam v = param as HErlangParam; double o = NMath.Abs(omega - v.omega); double a = Blas.Adiff(m, alpha, v.alpha); double b = Blas.Adiff(m, rate, v.rate); return(NMath.Max(o, a, b)); }
void UpdateCachedAssets() { bool isViewVisible = IsViewLoaded && View.Window != null; if (!isViewVisible) { return; } // The preheat window is twice the height of the visible rect. CGRect preheatRect = CollectionView.Bounds; preheatRect = preheatRect.Inset(0f, -.5f * preheatRect.Height); nfloat delta = NMath.Abs(preheatRect.GetMidY() - previousPreheatRect.GetMidY()); if (delta > CollectionView.Bounds.Height / 3.0f) { // Compute the assets to start caching and to stop caching. var addedIndexPaths = new List <NSIndexPath> (); var removedIndexPaths = new List <NSIndexPath> (); ComputeDifferenceBetweenRect(previousPreheatRect, preheatRect, removedRect => { var indexPaths = CollectionView.GetIndexPaths(removedRect); if (indexPaths != null) { removedIndexPaths.AddRange(indexPaths); } }, addedRect => { var indexPaths = CollectionView.GetIndexPaths(addedRect); if (indexPaths != null) { addedIndexPaths.AddRange(indexPaths); } }); var assetsToStartCaching = AssetsAtIndexPaths(addedIndexPaths.ToArray()); var assetsToStopCaching = AssetsAtIndexPaths(removedIndexPaths.ToArray()); // Update the assets the PHCachingImageManager is caching. if (assetsToStartCaching != null) { imageManager.StartCaching(assetsToStartCaching, assetGridThumbnailSize, PHImageContentMode.AspectFill, null); } if (assetsToStopCaching != null) { imageManager.StopCaching(assetsToStopCaching, assetGridThumbnailSize, PHImageContentMode.AspectFill, null); } // Store the preheat rect to compare against in the future. previousPreheatRect = preheatRect; } }
/// <summary> /// Updates the progress bar to the given value with the optional properties /// </summary> /// <param name="progress">The progress to update to, pinned between <c>0</c> and <c>1</c>.</param> /// <param name="animated">Whether or not the update should be animated (defaults to <c>true</c>).</param> /// <param name="initialDelay">Sets an initial delay before the animation begins.</param> /// <param name="duration">Sets the overal duration that the animation should complete within.</param> public void UpdateProgress(nfloat progress, bool animated = true, double initialDelay = 0, double?duration = null) { var pinnedProgress = pin(progress, 0.0f, 1.0f); var indeterminate = progressLayer.AnimationForKey(CircularProgressAnimationKeys.indeterminate); if (indeterminate != null && pinnedProgress > 0) { progressLayer.RemoveAnimation(CircularProgressAnimationKeys.indeterminate); } if (animated) { // Get duration double animationDuration = 0; if (duration.HasValue && Math.Abs(duration.Value) > double.Epsilon) { animationDuration = duration.Value; } else { // Same duration as UIProgressView animation animationDuration = NMath.Abs(Progress - pinnedProgress); } // Get current progress (to avoid jumpy behavior) // Basic animations have their value reset to the original once the animation is finished // since only the presentation layer is animating nfloat currentProgress = 0; var presentationLayer = progressLayer.PresentationLayer as CircularProgressLayer; if (presentationLayer != null) { currentProgress = presentationLayer.Progress; } progressLayer.Progress = currentProgress; progressLayer.RemoveAnimation(CircularProgressAnimationKeys.progress); animate(progress, currentProgress, initialDelay, animationDuration); } else { progressLayer.RemoveAnimation(CircularProgressAnimationKeys.progress); progressLayer.Progress = pinnedProgress; progressLayer.SetNeedsDisplay(); } }
private void Mstep() { int cnt1, cnt2; double x, xn, f, df, step; double v = NMath.Log(en2 / en1) - en3 / en1; x = param.Alpha; cnt1 = 0; do { f = NMath.Log(x) - NMath.Psi(x) - v; df = 1.0 / x - NMath.Polygamma(1, x); step = 1.0; cnt2 = 0; do { xn = x - step * f / df; if (xn > 0.0) { break; } step *= 0.5; if (cnt2 >= 1000) { xn = double.NaN; goto FINAL; } cnt2++; } while (true); if (double.IsNaN(x) || double.IsInfinity(x)) { throw new NotFiniteNumberException(); } if (cnt1 >= 1000) { xn = double.NaN; goto FINAL; } cnt1++; if (NMath.Abs(xn - x) < newton_eps * NMath.Abs(x)) { break; } x = xn; } while (true); FINAL: param.Alpha = xn; param.Omega = en1; param.Beta = param.Alpha * en1 / en2; }
public void UpdateOffset(nfloat offsetY) { var over = offsetY <= nfloat.Epsilon; ClipsToBounds = !over; imageView.ClipsToBounds = over; var x = over ? offsetY : 0; var y = over ? offsetY : offsetY / 2.5f; var w = over ? Frame.Width + (NMath.Abs(offsetY) * 2) : Frame.Width; var h = over ? Frame.Height + NMath.Abs(offsetY) : Frame.Height; imageView.Frame = new CGRect(x, y, w, h); }
public void ZoomingEnded(UIScrollView scrollView, UIView withView, nfloat scale) { var desiredScale = TraitCollection.DisplayScale; var existingScale = cgView.ContentScaleFactor; if (scale >= 2) { desiredScale *= 2; } if (NMath.Abs(desiredScale - existingScale) > 0.00001) { cgView.ContentScaleFactor = desiredScale; cgView.SetNeedsDisplay(); } }
void UpdateCachedAssets() { bool isViewVisible = IsViewLoaded && View.Window != null; if (!isViewVisible) { return; } // The preheat window is twice the height of the visible rect. CGRect preheatRect = CollectionView.Bounds; preheatRect = preheatRect.Inset(0, -preheatRect.Height / 2); // Update only if the visible area is significantly different from the last preheated area. nfloat delta = NMath.Abs(preheatRect.GetMidY() - previousPreheatRect.GetMidY()); if (delta <= CollectionView.Bounds.Height / 3) { return; } // Compute the assets to start caching and to stop caching. var rects = ComputeDifferenceBetweenRect(previousPreheatRect, preheatRect); var addedAssets = rects.Added .SelectMany(rect => CollectionView.GetIndexPaths(rect)) .Select(indexPath => FetchResult.ObjectAt(indexPath.Item)) .Cast <PHAsset> () .ToArray(); var removedAssets = rects.Removed .SelectMany(rect => CollectionView.GetIndexPaths(rect)) .Select(indexPath => FetchResult.ObjectAt(indexPath.Item)) .Cast <PHAsset> () .ToArray(); // Update the assets the PHCachingImageManager is caching. imageManager.StartCaching(addedAssets, thumbnailSize, PHImageContentMode.AspectFill, null); imageManager.StopCaching(removedAssets, thumbnailSize, PHImageContentMode.AspectFill, null); // Store the preheat rect to compare against in the future. previousPreheatRect = preheatRect; }
nfloat PercentForGesture(UIPanGestureRecognizer gesture) { if (TransitionContext == null) { return(0f); } UIView transitionContainerView = TransitionContext.ContainerView; var translationInContainerView = gesture.TranslationInView(transitionContainerView); if (translationInContainerView.X > 0f && initialTranslationInContainerView.X < 0f && translationInContainerView.X < 0f && initialTranslationInContainerView.X > 0f) { return(-1f); } nfloat retVal = translationInContainerView.X / transitionContainerView.Bounds.Width; return(NMath.Abs(retVal)); }
public override bool ContinueTracking(UITouch touch, UIEvent uievent) { if (!this.Tracking) { return(false); } var previousLocation = touch.PreviousLocationInView(this); var currentLocation = touch.LocationInView(this); var trackingOffset = currentLocation.X - previousLocation.X; nfloat verticalOffset = NMath.Abs(currentLocation.Y - beganTrackingLocation.Y); var scrubbingSpeedChangePosIndex = indexOfLowerScrubbingSpeed(verticalOffset); ScrubbingSpeed = ScrubbingSpeeds[scrubbingSpeedChangePosIndex]; var trackRect = this.TrackRectForBounds(this.Bounds); realPositionValue = realPositionValue + (MaxValue - MinValue) * (trackingOffset / trackRect.Width); nfloat valueAdjustment = ScrubbingSpeed * (MaxValue - MinValue) * (trackingOffset / trackRect.Width); nfloat thumbAdjustment = 0f; if (((beganTrackingLocation.Y < currentLocation.Y) && (currentLocation.Y < previousLocation.Y)) || ((beganTrackingLocation.Y > currentLocation.Y) && (currentLocation.Y > previousLocation.Y))) { // We are getting closer to the slider, go closer to the real location thumbAdjustment = (realPositionValue - Value) / (1 + NMath.Abs(currentLocation.Y - beganTrackingLocation.Y)); } Value += (float)(valueAdjustment + thumbAdjustment); if (Continuous) { this.SendActionForControlEvents(UIControlEvent.ValueChanged); } return(true); }
unsafe public void GradientLerp(nfloat *data, nfloat *outData) { nfloat lerpDist = *(nfloat *)data; int i = 0; int numPositions = positions.Length; // Make sure we put the linear distance value back into the 0.0 .. 1.0 range // depending on the wrap mode if (wrapMode == WrapMode.Tile || wrapMode == WrapMode.TileFlipY) { // Repeat lerpDist = lerpDist - (nfloat)NMath.Floor(lerpDist); } else { // Reflect lerpDist = (nfloat)NMath.Abs(lerpDist) % 2.0f; if (lerpDist > 1.0f) { lerpDist = 2.0f - lerpDist; } } for (i = 0; i < numPositions; i++) { if (positions[i] > lerpDist) { break; } } nfloat prevPosition = 0; nfloat dist = 0; nfloat normalized = 0; if (i == 0 || i == numPositions) { if (i == numPositions) { --i; } // When we have multiple positions we need to interpolate the colors // between the two positions. // normalized will be the normalized [0,1] amount // of the gradiant area between the two positions. // // The shading colors have already // been setup with the color factors taken into account. // Get the distance between current position and last position dist = factors[i] - prevPosition; // normalized value between the two shading colors normalized = (nfloat)((lerpDist - prevPosition) / dist); // Console.WriteLine("prev {0} dist {1} normal {2} i {3} t {4}", // prevPosition, dist, normalized, i, t); for (ushort ctr = 0; ctr < 4; ctr++) { outData[ctr] = GeomUtilities.Lerp(shadingColors[0, ctr], shadingColors[1, ctr], normalized); } } else { // When we have multiple positions we need to interpolate the colors // between the two positions. // normalized will be the normalized [0,1] amount // of the gradiant area between the two positions. // // The shading colors have already // been setup with the color factors taken into account. prevPosition = positions[i - 1]; // Get the distance between current position and last position dist = positions[i] - prevPosition; // normalized value between the two shading colors normalized = (nfloat)((lerpDist - prevPosition) / dist); for (ushort ctr = 0; ctr < 4; ctr++) { outData[ctr] = GeomUtilities.Lerp(shadingColors[i - 1, ctr], shadingColors[i, ctr], normalized); } } if (gammaCorrection) { // * NOTE * Here I am only computing the gamma correction for RGB values not alpha // I am really not sure if this is correct or not but from my reading on this topic // it is really never mentioned that alpha is included. for (ushort ctr = 0; ctr < 3; ctr++) { outData[ctr] = (nfloat)Math.Pow(outData[ctr], gamma); } } // Console.WriteLine("R: {0}, G: {1}, B: {2}, A: {3}", // outData[0], // outData[1], // outData[2], // outData[3]); }
public static bool AreSizesDifferent(this CGRect cgRectOne, CGRect cgRectTwo) { return(NMath.Abs(cgRectOne.Width - cgRectTwo.Width) > nfloat.Epsilon || NMath.Abs(cgRectOne.Height - cgRectTwo.Height) > nfloat.Epsilon); }
void Panned(object r) { var recognizer = r as UIPanGestureRecognizer; switch (recognizer.State) { case UIGestureRecognizerState.Began: StartAnimationIfNeeded(); animator.PauseAnimation(); animationProgress = animator.FractionComplete; break; case UIGestureRecognizerState.Changed: var fraction = -recognizer.TranslationInView(momentumView).Y / closedTransform.y0; if (isOpen) { fraction *= -1; } if (animator.Reversed) { fraction *= -1; } animator.FractionComplete = fraction + animationProgress; break; case UIGestureRecognizerState.Ended: case UIGestureRecognizerState.Cancelled: var yVelocity = recognizer.VelocityInView(momentumView).Y; var shouldClose = yVelocity > 0; // todo: should use projection instead if (yVelocity == 0) { animator.ContinueAnimation(parameters: null, durationFactor: 0); break; } if (isOpen) { if (!shouldClose && !animator.Reversed) { animator.Reversed = !animator.Reversed; } if (shouldClose && animator.Reversed) { animator.Reversed = !animator.Reversed; } } else { if (shouldClose && !animator.Reversed) { animator.Reversed = !animator.Reversed; } if (!shouldClose && animator.Reversed) { animator.Reversed = !animator.Reversed; } } var fractionRemaining = 1 - animator.FractionComplete; var distanceRemaining = fractionRemaining * closedTransform.y0; if (distanceRemaining == 0) { animator.ContinueAnimation(null, 0); break; } var relativeVelocity = NMath.Min(NMath.Abs(yVelocity) / distanceRemaining, 30); var timingParameters = UISpringTiming.MakeTimingParameters(damping: 0.8f, response: 0.3f, initialVelocity: new CGVector(dx: relativeVelocity, dy: relativeVelocity)); var preferredDuration = new UIViewPropertyAnimator(duration: 0, parameters: timingParameters).Duration; var durationFactor = preferredDuration / animator.Duration; animator.ContinueAnimation(parameters: timingParameters, durationFactor: (nfloat)durationFactor); break; default: break; } }
private void UpdateContent() { if (_lastSize != ContainerView.Bounds.Size) { _lastSize = ContainerView.Bounds.Size; ContainerView.SetContentOffset(new CGPoint(PageOffsetForChildIndex(CurrentIndex), 0), false); } var childViewControllers = _pagerTabStripChildViewControllers; ContainerView.ContentSize = new CGSize(ContainerView.Bounds.Width * childViewControllers.Count, ContainerView.ContentSize.Height); for (int i = 0; i < childViewControllers.Count; i++) { UIViewController childController = childViewControllers [i] as UIViewController; nfloat pageOffsenForChild = PageOffsetForChildIndex(i); if (NMath.Abs(ContainerView.ContentOffset.X - pageOffsenForChild) < ContainerView.Bounds.Width) { if (childController.ParentViewController == null) { AddChildViewController(childController); childController.DidMoveToParentViewController(this); nfloat childPosition = OffsetForChildIndex(i); childController.View.Frame = new CGRect(childPosition, 0, View.Bounds.Width, ContainerView.Bounds.Height); childController.View.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight; ContainerView.AddSubview(childController.View); } else { nfloat childPosition = OffsetForChildIndex(i); childController.View.Frame = new CGRect(childPosition, 0, View.Bounds.Width, ContainerView.Bounds.Height); childController.View.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight; } } else { if (childController.ParentViewController != null) { childController.View.RemoveFromSuperview(); childController.WillMoveToParentViewController(null); childController.RemoveFromParentViewController(); } } } nint oldCurrentIndex = CurrentIndex; nint virtualPage = VirtualPageForContentOffset(ContainerView.ContentOffset.X); nint newCurrentIndex = PageForVirtualPage(virtualPage); CurrentIndex = newCurrentIndex; if (IsProgressiveIndicator) { nfloat scrollPercentage = ScrollPercentage; if (scrollPercentage > 0) { nint fromIndex = CurrentIndex; nint toIndex = CurrentIndex; PagerTabStripDirection scrollDirection = ScrollDirection; if (scrollDirection == PagerTabStripDirection.Left) { if (virtualPage > _pagerTabStripChildViewControllers.Count - 1) { fromIndex = _pagerTabStripChildViewControllers.Count - 1; toIndex = _pagerTabStripChildViewControllers.Count; } else { if (scrollPercentage > 0.5f) { fromIndex = NMath.Max(toIndex - 1, 0); } else { toIndex = fromIndex + 1; } } } else if (scrollDirection == PagerTabStripDirection.Right) { if (virtualPage < 0) { fromIndex = 0; toIndex = -1; } else { if (scrollPercentage > 0.5f) { fromIndex = NMath.Min(toIndex + 1, _pagerTabStripChildViewControllers.Count - 1); } else { toIndex = fromIndex - 1; } } } UpdatePage(fromIndex, toIndex, IsElasticIndicatorLimit ? scrollPercentage : (toIndex < 0 || toIndex >= _pagerTabStripChildViewControllers.Count ? 0 : scrollPercentage)); } } else { if (oldCurrentIndex != newCurrentIndex) { UpdatePage(NMath.Max(oldCurrentIndex, _pagerTabStripChildViewControllers.Count - 1), newCurrentIndex); } } }
public void UpdateContent() { if (LastSize.Width != ContainerView.Bounds.Size.Width) { LastSize = ContainerView.Bounds.Size; ContainerView.ContentOffset = new CGPoint(PageOffsetForChild(CurrentIndex), 0); } LastSize = ContainerView.Bounds.Size; var pagerViewControllers = PagerTabStripChildViewControllersForScrolling ?? ViewControllers; ContainerView.ContentSize = new CGSize(ContainerView.Bounds.Width * pagerViewControllers.Count, ContainerView.ContentSize.Height); for (var index = 0; index < pagerViewControllers.Count; index++) { var childController = pagerViewControllers[index]; var pageOffsetForChild = PageOffsetForChild(index); if (NMath.Abs(ContainerView.ContentOffset.X - pageOffsetForChild) < ContainerView.Bounds.Width) { if (childController.ParentViewController != null) { childController.View.Frame = new CGRect(OffsetForChild(index), 0, View.Bounds.Width, ContainerView.Bounds.Height); childController.View.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight; } else { AddChildViewController(childController); childController.BeginAppearanceTransition(true, false); childController.View.Frame = new CGRect(OffsetForChild(index), 0, View.Bounds.Width, ContainerView.Bounds.Height); childController.View.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight; ContainerView.AddSubview(childController.View); childController.DidMoveToParentViewController(this); childController.EndAppearanceTransition(); } } else { if (childController.ParentViewController != null) { childController.WillMoveToParentViewController(null); childController.BeginAppearanceTransition(false, false); childController.View.RemoveFromSuperview(); childController.RemoveFromParentViewController(); childController.EndAppearanceTransition(); } } } var oldCurrentIndex = CurrentIndex; var virtualPage = VirtualPageFor(ContainerView.ContentOffset.X); var newCurrentIndex = PageFor(virtualPage); CurrentIndex = newCurrentIndex; var changeCurrentIndex = newCurrentIndex != oldCurrentIndex; var progressiveDelegate = this as PagerTabStripIsProgressiveDelegate; if (progressiveDelegate != null && PagerBehaviour.ProgressiveIndicator) { var t = ProgressiveIndicatorData(virtualPage); progressiveDelegate.UpdateIndicator( viewController: this, fromIndex: t.Item1, toIndex: t.Item2, progressPercentage: t.Item3, indexWasChanged: changeCurrentIndex); } else { if (Delegate != null) { Delegate.UpdateIndicator(this, NMath.Min(oldCurrentIndex, pagerViewControllers.Count - 1), newCurrentIndex); } } }
private static void CGMirrorFunction(UGGradientStop[] stops, nfloat *data, nfloat *outData) { var pos = NMath.Abs(NMath.IEEERemainder(*data, 2)); CGFunctionBase(stops, pos, outData); }
void handleLtrPanGesture(UIPanGestureRecognizer pan) { switch (pan.State) { case UIGestureRecognizerState.Began: pendingStatusBarAppearanceUpdate = true; break; case UIGestureRecognizerState.Changed: var ltrCurrentTranslation = pan.TranslationInView(pan.View); // if panning right-to-left ltrCurrentTranslation.X will be negative // setting pan.Enabled to false causes this method to be called again with // pan.State == Cancelled, so we'll reenable the gesture in Cancelled: case if (ltrCurrentTranslation.X < 0) { pan.Enabled = false; return; } // if panning up or down more than left-to-right, kill this gesture recognizer // to allow only the TopViewControllers scrollview, tableview, etc. to scroll if (NMath.Abs(ltrCurrentTranslation.Y) > ltrCurrentTranslation.X) { pan.Enabled = false; return; } var frame = TopViewFrame; frame.X += ltrCurrentTranslation.X; TopView.Frame = frame; if (pendingStatusBarAppearanceUpdate) { pendingStatusBarAppearanceUpdate = false; DrawerTransitioning?.Invoke(this, new DrawerTransitioningEventArgs(DrawerTransitioningState.Transitioning)); updateStatusBarAppearance(); } break; case UIGestureRecognizerState.Ended: case UIGestureRecognizerState.Cancelled: pan.Enabled = true; // the TopView's frame was never moved because the pan was the wrong direction // or the pan was a vertical scroll, so no reason to do anything here if (pendingStatusBarAppearanceUpdate) { pendingStatusBarAppearanceUpdate = false; return; } // if the drawer has been opened at least 50%, finish opening, otherwise close var finalFrame = TopView.Frame.X > (DrawerWidth / 2) ? TopViewFrameOpen : TopViewFrame; UIView.AnimateNotify(0.1, () => { TopView.Frame = finalFrame; }, (finished) => { TapGestureRecognizer.Enabled = DrawerOpen; DrawerTransitioning?.Invoke(this, new DrawerTransitioningEventArgs(DrawerOpen ? DrawerTransitioningState.Open : DrawerTransitioningState.Closed)); updateStatusBarAppearance(); }); break; } }
public void Fit(SRMData data) { emparam.Status = Status.PROCESSING; //if (emparam.initflag) //{ // initialize(data); //} double prev_llf; emparam.Llf = -double.MaxValue; model.Pre_em(data); emparam.Cnt = 0; while (true) { prev_llf = emparam.Llf; model.GetParam().CopyTo(prev_param); emparam.Llf = model.Emstep(data); if (emparam.Llf < prev_llf) { msg.Warning(); } switch (emparam.StopCond) { case StopCondition.LLF: emparam.Aerror = NMath.Abs(emparam.Llf - prev_llf); emparam.Rerror = emparam.Aerror / NMath.Abs(prev_llf); break; case StopCondition.PARAMETER: emparam.Aerror = model.GetParam().Adiff(prev_param); emparam.Rerror = model.GetParam().Rdiff(prev_param); break; } emparam.Cnt++; if (double.IsNaN(emparam.Llf)) { emparam.Status = Status.NUMERICALERROR; break; } if (emparam.PrintFlag && emparam.Cnt % emparam.Progress == 0) { msg.Show(); } if (emparam.Aerror < emparam.Atol && emparam.Rerror < emparam.Rtol) { emparam.Status = Status.CONVERGENCE; break; } if (emparam.Cnt >= emparam.MaxIter) { emparam.Status = Status.MAXITERATION; break; } } msg.Final(); model.Post_em(data); }