System.Math.Min(double, double)

Here are the examples of the csharp api System.Math.Min(double, double) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

1914 Examples 7

19 View Source File : MathUtils.cs
License : GNU General Public License v3.0
Project Creator : ahmed605

public static Rect3D TransformBounds(Rect3D bounds, Matrix3D transform)
        {
            double x1 = bounds.X;
            double y1 = bounds.Y;
            double z1 = bounds.Z;
            double x2 = bounds.X + bounds.SizeX;
            double y2 = bounds.Y + bounds.SizeY;
            double z2 = bounds.Z + bounds.SizeZ;

            Point3D[] points = new Point3D[] {
                                                 new Point3D(x1, y1, z1),
                                                 new Point3D(x1, y1, z2),
                                                 new Point3D(x1, y2, z1),
                                                 new Point3D(x1, y2, z2),
                                                 new Point3D(x2, y1, z1),
                                                 new Point3D(x2, y1, z2),
                                                 new Point3D(x2, y2, z1),
                                                 new Point3D(x2, y2, z2),
                                             };

            transform.Transform(points);

            // reuse the 1 and 2 variables to stand for smallest and largest
            Point3D p = points[0];
            x1 = x2 = p.X;
            y1 = y2 = p.Y;
            z1 = z2 = p.Z;

            for (int i = 1; i < points.Length; i++)
            {
                p = points[i];

                x1 = Math.Min(x1, p.X); y1 = Math.Min(y1, p.Y); z1 = Math.Min(z1, p.Z);
                x2 = Math.Max(x2, p.X); y2 = Math.Max(y2, p.Y); z2 = Math.Max(z2, p.Z);
            }

            return new Rect3D(x1, y1, z1, x2 - x1, y2 - y1, z2 - z1);
        }

private Tuple<int, int> GetScaledImageDimensions()
        {
            if (this.PreviewMode == GroupMeImageDisplayMode.Preview)
            {
                return new Tuple<int, int>(200, 200);
            }

            var choppedUrl = new Uri(this.ImageAttachment.Url).AbsolutePath.Substring(1).Split('.')[0];
            var dimensionsStr = choppedUrl.Split('x');

            int.TryParse(dimensionsStr[0], out var width);
            int.TryParse(dimensionsStr[1], out var height);

            // GroupMe in large mode limits images to 960px in the largest dimensions. Small mode is not doreplacedented for the limits.
            const int MaxImageDim = 960;

            var largestSide = Math.Max(width, height);
            var scale = Math.Min(1.0, (double)MaxImageDim / largestSide);

            return new Tuple<int, int>((int)(width * scale), (int)(height * scale));
        }

19 View Source File : DropDownGlyphPanel.cs
License : MIT License
Project Creator : Actipro

protected override Size ArrangeOverride(Size finalSize) {
			var internalChildren = base.InternalChildren;
			if (internalChildren.Count == 2) {
				var x = Math.Max(0, Math.Min(internalChildren[0].DesiredSize.Width, finalSize.Width - internalChildren[1].DesiredSize.Width));
				internalChildren[1].Arrange(new Rect(x, 0, internalChildren[1].DesiredSize.Width, finalSize.Height));
				internalChildren[0].Arrange(new Rect(0, 0, x, finalSize.Height));
			}

			return finalSize;
		}

19 View Source File : ConeShape.cs
License : The Unlicense
Project Creator : aeroson

public static ConvexShapeDescription ComputeDescription(float height, float radius, float collisionMargin)
        {
            ConvexShapeDescription description;
            description.EnreplacedyShapeVolume.Volume = (float)(.333333 * Math.PI * radius * radius * height);

            description.EnreplacedyShapeVolume.VolumeDistribution = new Matrix3x3();
            float diagValue = (.1f * height * height + .15f * radius * radius);
            description.EnreplacedyShapeVolume.VolumeDistribution.M11 = diagValue;
            description.EnreplacedyShapeVolume.VolumeDistribution.M22 = .3f * radius * radius;
            description.EnreplacedyShapeVolume.VolumeDistribution.M33 = diagValue;

            description.MaximumRadius = (float)(collisionMargin + Math.Max(.75 * height, Math.Sqrt(.0625f * height * height + radius * radius)));

            double denominator = radius / height;
            denominator = denominator / Math.Sqrt(denominator * denominator + 1);
            description.MinimumRadius = (float)(collisionMargin + Math.Min(.25f * height, denominator * .75 * height));

            description.CollisionMargin = collisionMargin;
            return description;
        }

19 View Source File : TestHardSigmoid.cs
License : MIT License
Project Creator : adamtiger

private double HardSigmoidFunc(double x)
        {
            return Math.Max(0.0, Math.Min(1, 0.2*x+0.5));
        }

19 View Source File : Particle.cs
License : GNU General Public License v3.0
Project Creator : ACEmulator

public void Update(ParticleType particleType, bool persistent, PhysicsPart part, AFrame parent)
        {
            var currentTime = PhysicsTimer.CurrentTime;
            var elapsedTime = currentTime - LastUpdateTime;

            if (persistent)
            {
                Lifetime += elapsedTime;
                LastUpdateTime = currentTime;
            }
            else
                Lifetime = elapsedTime;

            var lifetime = (float)Lifetime;

            switch (particleType)
            {
                case ParticleType.Still:
                    part.Pos.Frame.Origin = parent.Origin + Offset;
                    break;
                case ParticleType.LocalVelocity:
                case ParticleType.GlobalVelocity:
                    part.Pos.Frame.Origin = (lifetime * A) + parent.Origin + Offset;
                    break;
                case ParticleType.ParabolicLVGA:
                case ParticleType.ParabolicLVLA:
                case ParticleType.ParabolicGVGA:
                    part.Pos.Frame.Origin = (lifetime * lifetime * B / 2.0f) + (lifetime * A) + parent.Origin + Offset;
                    break;
                case ParticleType.ParabolicLVGAGR:
                case ParticleType.ParabolicLVLALR:
                case ParticleType.ParabolicGVGAGR:
                    part.Pos.Frame = new AFrame(parent);
                    part.Pos.Frame.Origin += (lifetime * lifetime * B / 2.0f) + (lifetime * A) + Offset;
                    part.Pos.Frame.Rotate(lifetime * C);
                    break;
                case ParticleType.Swarm:
                    var swarm = (lifetime * A) + parent.Origin + Offset;
                    part.Pos.Frame.Origin.X = (float)Math.Cos(lifetime * B.X) * C.X + swarm.X;
                    part.Pos.Frame.Origin.Y = (float)Math.Sin(lifetime * B.Y) * C.Y + swarm.Y;
                    part.Pos.Frame.Origin.Z = (float)Math.Cos(lifetime * B.Z) * C.Z + swarm.Z;
                    break;
                case ParticleType.Explode:
                    part.Pos.Frame.Origin = (lifetime * B + C * A.X) * lifetime + Offset + parent.Origin;
                    break;
                case ParticleType.Implode:
                    part.Pos.Frame.Origin = ((float)Math.Cos(A.X * lifetime) * C) + (lifetime * lifetime * B) + parent.Origin + Offset;
                    break;
            }

            var interval = Math.Min(Lifetime / Lifespan, 1.0f);

            var currentScale = StartScale + (FinalScale - StartScale) * interval;
            var currentTrans = StartTrans + (FinalTrans - StartTrans) * interval;

            part.GfxObjScale = new Vector3((float)currentScale);
            part.SetTranslucency((float)currentTrans);
        }

19 View Source File : VirtualControl.cs
License : MIT License
Project Creator : alaabenfatma

private void OnMouseMove(object sender, MouseEventArgs mouseEventArgs)
        {
            if (WireMode == WireMode.FirstPortSelected && MouseMode == MouseMode.DraggingPort)
            {
                TempConn.EndPoint = new Point(mouseEventArgs.GetPosition(this).X - 1,
                    mouseEventArgs.GetPosition(this).Y);
                if (_wiresDisabled) return;
                for (var index = 0; index < Children.Count - 1; index++)
                {
                    var uielement = Children[index];
                    if (uielement is Wire)
                        MagicLaboratory.GrayWiresOut(uielement as Wire);
                }
                _wiresDisabled = true;
                return;
            }
            if (mouseEventArgs.LeftButton == MouseButtonState.Released)
                if (_wiresDisabled)
                {
                    for (var index = 0; index < Children.Count - 1; index++)
                    {
                        var uielement = Children[index];
                        if (uielement is Wire)
                            MagicLaboratory.GrayWiresOut_Reverse(uielement as Wire);
                    }
                    _wiresDisabled = false;
                }

            if (mouseEventArgs.LeftButton != MouseButtonState.Released && MouseMode == MouseMode.SelectionRectangle)
            {
                if (!Children.Contains(_selectionZone))
                    AddChildren(_selectionZone);
                var pos = mouseEventArgs.GetPosition(this);
                var x = Math.Min(pos.X, _startPoint.X);
                var y = Math.Min(pos.Y, _startPoint.Y);
                var w = Math.Max(pos.X, _startPoint.X) - x;
                var h = Math.Max(pos.Y, _startPoint.Y) - y;
                _selectionZone.Width = w;
                _selectionZone.Height = h;
                SetLeft(_selectionZone, x);
                SetTop(_selectionZone, y);
                SelectionZoneWorkerOnDoWork();
                return;
            }
            if (MouseMode == MouseMode.ResizingComment && mouseEventArgs.LeftButton == MouseButtonState.Pressed)
            {
                Cursor = Cursors.SizeNWSE;
                var currentPoint = Mouse.GetPosition(this);
                if (currentPoint.Y - TempComment.Y > 0 && currentPoint.X - TempComment.X > 0)
                {
                    TempComment.Height = /*TempComment.Top +*/ currentPoint.Y - TempComment.Y;
                    TempComment.Width = /* TempComment.Left +*/ currentPoint.X - TempComment.X;
                    TempComment.LocateHandler();
                }
                else
                {
                    TempComment.Height = 32;
                    TempComment.Width = 32;
                    TempComment.LocateHandler();
                }
                return;
            }
            if (NeedsRefresh)
            {
                foreach (var node in Nodes)
                    node.Refresh();

                TemExecPort = null;
                TemObjectPort = null;
                NeedsRefresh = false;
            }
        }

19 View Source File : BackgroundGeometryBuilder.cs
License : MIT License
Project Creator : Abdesol

static IEnumerable<Rect> ProcessTextLines(TextView textView, VisualLine visualLine, int segmentStartVC, int segmentEndVC)
		{
			TextLine lastTextLine = visualLine.TextLines.Last();
			Vector scrollOffset = textView.ScrollOffset;

			for (int i = 0; i < visualLine.TextLines.Count; i++) {
				TextLine line = visualLine.TextLines[i];
				double y = visualLine.GetTextLineVisualYPosition(line, VisualYPosition.LineTop);
				int visualStartCol = visualLine.GetTextLineVisualStartColumn(line);
				int visualEndCol = visualStartCol + line.Length;
				if (line == lastTextLine)
					visualEndCol -= 1; // 1 position for the TextEndOfParagraph
				else
					visualEndCol -= line.TrailingWhitespaceLength;

				if (segmentEndVC < visualStartCol)
					break;
				if (lastTextLine != line && segmentStartVC > visualEndCol)
					continue;
				int segmentStartVCInLine = Math.Max(segmentStartVC, visualStartCol);
				int segmentEndVCInLine = Math.Min(segmentEndVC, visualEndCol);
				y -= scrollOffset.Y;
				Rect lastRect = Rect.Empty;
				if (segmentStartVCInLine == segmentEndVCInLine) {
					// GetTextBounds crashes for length=0, so we'll handle this case with GetDistanceFromCharacterHit
					// We need to return a rectangle to ensure empty lines are still visible
					double pos = visualLine.GetTextLineVisualXPosition(line, segmentStartVCInLine);
					pos -= scrollOffset.X;
					// The following special cases are necessary to get rid of empty rectangles at the end of a TextLine if "Show Spaces" is active.
					// If not excluded once, the same rectangle is calculated (and added) twice (since the offset could be mapped to two visual positions; end/start of line), if there is no trailing whitespace.
					// Skip this TextLine segment, if it is at the end of this line and this line is not the last line of the VisualLine and the selection continues and there is no trailing whitespace.
					if (segmentEndVCInLine == visualEndCol && i < visualLine.TextLines.Count - 1 && segmentEndVC > segmentEndVCInLine && line.TrailingWhitespaceLength == 0)
						continue;
					if (segmentStartVCInLine == visualStartCol && i > 0 && segmentStartVC < segmentStartVCInLine && visualLine.TextLines[i - 1].TrailingWhitespaceLength == 0)
						continue;
					lastRect = new Rect(pos, y, textView.EmptyLineSelectionWidth, line.Height);
				} else {
					if (segmentStartVCInLine <= visualEndCol) {
						foreach (TextBounds b in line.GetTextBounds(segmentStartVCInLine, segmentEndVCInLine - segmentStartVCInLine)) {
							double left = b.Rectangle.Left - scrollOffset.X;
							double right = b.Rectangle.Right - scrollOffset.X;
							if (!lastRect.IsEmpty)
								yield return lastRect;
							// left>right is possible in RTL languages
							lastRect = new Rect(Math.Min(left, right), y, Math.Abs(right - left), line.Height);
						}
					}
				}
				// If the segment ends in virtual space, extend the last rectangle with the rectangle the portion of the selection
				// after the line end.
				// Also, when word-wrap is enabled and the segment continues into the next line, extend lastRect up to the end of the line.
				if (segmentEndVC > visualEndCol) {
					double left, right;
					if (segmentStartVC > visualLine.VisualLengthWithEndOfLineMarker) {
						// segmentStartVC is in virtual space
						left = visualLine.GetTextLineVisualXPosition(lastTextLine, segmentStartVC);
					} else {
						// Otherwise, we already processed the rects from segmentStartVC up to visualEndCol,
						// so we only need to do the remainder starting at visualEndCol.
						// For word-wrapped lines, visualEndCol doesn't include the whitespace hidden by the wrap,
						// so we'll need to include it here.
						// For the last line, visualEndCol already includes the whitespace.
						left = (line == lastTextLine ? line.WidthIncludingTrailingWhitespace : line.Width);
					}
					if (line != lastTextLine || segmentEndVC == int.MaxValue) {
						// If word-wrap is enabled and the segment continues into the next line,
						// or if the extendToFullWidthAtLineEnd option is used (segmentEndVC == int.MaxValue),
						// we select the full width of the viewport.
						right = Math.Max(((IScrollInfo)textView).ExtentWidth, ((IScrollInfo)textView).ViewportWidth);
					} else {
						right = visualLine.GetTextLineVisualXPosition(lastTextLine, segmentEndVC);
					}
					Rect extendSelection = new Rect(Math.Min(left, right), y, Math.Abs(right - left), line.Height);
					if (!lastRect.IsEmpty) {
						if (extendSelection.IntersectsWith(lastRect)) {
							lastRect.Union(extendSelection);
							yield return lastRect;
						} else {
							// If the end of the line is in an RTL segment, keep lastRect and extendSelection separate.
							yield return lastRect;
							yield return extendSelection;
						}
					} else
						yield return extendSelection;
				} else
					yield return lastRect;
			}
		}

19 View Source File : TileMapAnnotation.cs
License : MIT License
Project Creator : AlexGyver

public override void Render(IRenderContext rc, PlotModel model)
        {
            base.Render(rc, model);
            var clippingRect = this.GetClippingRect();
            var lon0 = this.XAxis.ActualMinimum;
            var lon1 = this.XAxis.ActualMaximum;
            var lat0 = this.YAxis.ActualMinimum;
            var lat1 = this.YAxis.ActualMaximum;

            // the desired number of tiles horizontally
            double tilesx = model.Width / this.TileSize;

            // calculate the desired zoom level
            var n = tilesx / (((lon1 + 180) / 360) - ((lon0 + 180) / 360));
            var zoom = (int)Math.Round(Math.Log(n) / Math.Log(2));
            if (zoom < this.MinZoomLevel)
            {
                zoom = this.MinZoomLevel;
            }

            if (zoom > this.MaxZoomLevel)
            {
                zoom = this.MaxZoomLevel;
            }

            // find tile coordinates for the corners
            double x0, y0;
            LatLonToTile(lat0, lon0, zoom, out x0, out y0);
            double x1, y1;
            LatLonToTile(lat1, lon1, zoom, out x1, out y1);

            double xmax = Math.Max(x0, x1);
            double xmin = Math.Min(x0, x1);
            double ymax = Math.Max(y0, y1);
            double ymin = Math.Min(y0, y1);

            // Add the tiles
            for (var x = (int)xmin; x < xmax; x++)
            {
                for (var y = (int)ymin; y < ymax; y++)
                {
                    string uri = this.GetTileUri(x, y, zoom);
                    var img = this.GetImage(uri, rc.RendersToScreen);

                    if (img == null)
                    {
                        continue;
                    }

                    // transform from tile coordinates to lat/lon
                    double lareplacedude0, lareplacedude1, longitude0, longitude1;
                    TileToLatLon(x, y, zoom, out lareplacedude0, out longitude0);
                    TileToLatLon(x + 1, y + 1, zoom, out lareplacedude1, out longitude1);

                    // transform from lat/lon to screen coordinates
                    var s00 = this.Transform(longitude0, lareplacedude0);
                    var s11 = this.Transform(longitude1, lareplacedude1);

                    var r = OxyRect.Create(s00.X, s00.Y, s11.X, s11.Y);

                    // draw the image
                    rc.DrawClippedImage(clippingRect, img, r.Left, r.Top, r.Width, r.Height, this.Opacity, true);
                }
            }

            // draw the copyright notice
            var p = new ScreenPoint(clippingRect.Right - 5, clippingRect.Bottom - 5);
            var textSize = rc.MeasureText(this.CopyrightNotice, null, 12);
            rc.DrawRectangle(new OxyRect(p.X - textSize.Width - 2, p.Y - textSize.Height - 2, textSize.Width + 4, textSize.Height + 4), OxyColors.White.ChangeAlpha(200), null);

            rc.DrawText(
                p,
                this.CopyrightNotice,
                OxyColors.Black,
                null,
                12,
                500,
                0,
                HorizontalAlignment.Right,
                VerticalAlignment.Bottom);
        }

19 View Source File : AnimatedDataSeriesFilter.cs
License : MIT License
Project Creator : ABTSoftware

public override void FilterAll()
        {
            _filteredDataSeries.Clear();

            int index = 0;
            double animationStepMillisconds = 1;

            Action appendPoint = null;

            Action onAppendCallback = () =>
            {
                // 2.) Append the point
                _filteredDataSeries.Append(_originalDataSeries.XValues[index], _originalDataSeries.YValues[index]);
                _filteredDataSeries.InvalidateParentSurface(RangeMode.ZoomToFit);

                // 3.) Schedule another until complete
                if (++index < _originalDataSeries.Count)
                {
                    // Achieve some rudimentary easing 
                    animationStepMillisconds *= 1.05;
                    animationStepMillisconds = Math.Min(animationStepMillisconds, 10);

                    // Next point 
                    appendPoint();                    
                }
            };

            appendPoint = () =>
            {                
                TimedMethod.Invoke(onAppendCallback).After((int)animationStepMillisconds).Go();
            };

            // 1.) Schedule one point to be appended
            appendPoint();
        }

19 View Source File : SimpleAudioPlayerImplementation.cs
License : MIT License
Project Creator : adrianstevens

private void SetVolume(double volume, double balance)
        {
            if (player == null || _isDisposed) return;

            player.Volume = Math.Min(1, Math.Max(0, volume));
            player.Balance = Math.Min(1, Math.Max(-1, balance));
        }

19 View Source File : SimpleAudioPlayerImplementation.cs
License : MIT License
Project Creator : adrianstevens

void SetVolume(double volume, double balance)
        {
            volume = Math.Max(0, volume);
            volume = Math.Min(1, volume);

            balance = Math.Max(-1, balance);
            balance = Math.Min(1, balance);

            // Using the "constant power pan rule." See: http://www.rs-met.com/doreplacedents/tutorials/PanRules.pdf
            var left = Math.Cos((Math.PI * (balance + 1)) / 4) * volume;
            var right = Math.Sin((Math.PI * (balance + 1)) / 4) * volume;

            player?.SetVolume((float)left, (float)right);
        }

19 View Source File : LootGenerationFactory_Rare.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public static WorldObject TryCreateRare(int luck = 0)
        {
            //var t1_chance = 2500; // 1 in 2,500 chance // Old rate. Property default is 0.04 (which is 0.04%, or the same 1/2500)
            double rare_drop_rate_percent = (float)Managers.PropertyManager.GetDouble("rare_drop_rate_percent").Item;

            // Check to make sure there *IS* a chance. Less than/equal to 0 would mean zero chance, so we can stop here
            if (rare_drop_rate_percent <= 0)
                return null;
            
            rare_drop_rate_percent = Math.Min(rare_drop_rate_percent/100, 1); 
            int t1_chance = (int)Math.Round(1 / rare_drop_rate_percent); // Default PropertyManager value results in a 1 in 2,500 chance
            t1_chance = Math.Max(t1_chance - luck, 1);

            int tier = 0;

            if (ThreadSafeRandom.Next(1, t1_chance) == 1)   // 1 in 2,500 chance
            {
                tier = 1;
                if (ThreadSafeRandom.Next(1, 10) == 1)      // 1 in 25,000 chance
                {
                    tier = 2;
                }
                if (ThreadSafeRandom.Next(1, 100) == 1)     // 1 in 250,000 chance
                {
                    tier = 3;
                }
                if (ThreadSafeRandom.Next(1, 1250) == 1)    // 1 in 3,120,000 chance
                {
                    tier = 4;
                }
                if (ThreadSafeRandom.Next(1, 3017) == 1)    // 1 in 7,542,500 (wiki avg. 7,543,103)
                {
                    tier = 5;
                }
                if (ThreadSafeRandom.Next(1, 3500) == 1)    // 1 in 8,750,000 chance
                {
                    tier = 6;
                }
            }

            if (tier == 0) return null;

            var tierRares = RareWCIDs[tier].ToList();

            var rng = ThreadSafeRandom.Next(0, tierRares.Count - 1);

            var rareWCID = tierRares[rng];

            var wo = WorldObjectFactory.CreateNewWorldObject((uint)rareWCID);

            if (wo == null)
                log.Error($"LootGenerationFactory_Rare.CreateRare(): failed to generate rare wcid {rareWCID}");

            return wo;
        }

19 View Source File : ImageProcessing.cs
License : GNU General Public License v3.0
Project Creator : aglab2

public static void Saturate(Bitmap image)
        {
            for (int i = 0; i < image.Width; i++)
            {
                for (int j = 0; j < image.Height; j++)
                {
                    double h; double s; double l;
                    Color c = image.GetPixel(i, j);
                    ColorRGB crgb = new ColorRGB(c);
                    ColorRGB.RGB2HSL(crgb, out h, out s, out l);

                    s = Math.Min(s + 0.1, 1);

                    ColorRGB nrgb = ColorRGB.HSL2RGB(h, s, l);
                    Color n = Color.FromArgb(c.A, nrgb.R, nrgb.G, nrgb.B);
                    image.SetPixel(i, j, n);
                }
            }
        }

19 View Source File : FileTransferProgressBar.cs
License : MIT License
Project Creator : a-luna

public new void Report(double value)
		{
			var ticks = DateTime.Now.Ticks;
			Interlocked.Exchange(ref _lastReportTicks, ticks);

			// Make sure value is in [0..1] range
			value = Math.Max(0, Math.Min(1, value));
			Interlocked.Exchange(ref CurrentProgress, value);
		}

19 View Source File : Era.cs
License : Apache License 2.0
Project Creator : ajuna-network

public byte[] Encode()
        {
            if (IsImmortal)
            {
                return new byte[] { 0x00 };
            }
            var quantizeFactor = Math.Max(1, Period / 4096);
            var lastBit = Period & (ulong)-(long)Period;
            //var rest = _period;
            //var lastBit = 1;
            //while (rest % 2 == 0 && rest != 0)
            //{
            //    rest /= 2;
            //    lastBit *= 2;
            //}
            var logOf2 = lastBit != 0 ? Math.Log(lastBit, 2) : 64;
            var low = (ushort)Math.Min(15, Math.Max(1, logOf2 - 1));
            var high = (ushort)(Phase / quantizeFactor << 4);
            var encoded = (ushort)(low | high);

            return BitConverter.GetBytes(encoded);
        }

19 View Source File : BackoffTimerHelper.cs
License : MIT License
Project Creator : actions

public static TimeSpan GetExponentialBackoff(
            Int32 attempt,
            TimeSpan minBackoff,
            TimeSpan maxBackoff,
            TimeSpan deltaBackoff)
        {
            Double randomBackoff = (Double)new Random().Next((Int32)(deltaBackoff.TotalMilliseconds * 0.8), (Int32)(deltaBackoff.TotalMilliseconds * 1.2));
            Double additionalBackoff = attempt < 0 ? (Math.Pow(2.0, (Double)attempt)) * randomBackoff : (Math.Pow(2.0, (Double)attempt) - 1.0) * randomBackoff;
            return TimeSpan.FromMilliseconds(Math.Min(minBackoff.TotalMilliseconds + additionalBackoff, maxBackoff.TotalMilliseconds));
        }

19 View Source File : ProbeExtractor.cs
License : MIT License
Project Creator : alen-smajic

private double averageAngle(double a, double b)
		{
			var anorm = normalizeAngle(a);
			var bnorm = normalizeAngle(b);

			var minAngle = Math.Min(anorm, bnorm);
			var maxAngle = Math.Max(anorm, bnorm);

			var dist1 = Math.Abs(a - b);
			var dist2 = (minAngle + (360 - maxAngle));

			if (dist1 <= dist2) { return normalizeAngle(minAngle + dist1 / 2); }
			else
			{
				return normalizeAngle(maxAngle + dist2 / 2);
			}
		}

19 View Source File : ElasticWrapPanel.cs
License : MIT License
Project Creator : 944095635

protected override Size ArrangeOverride(Size finalSize)
        {
            if (_columns == 0) return base.ArrangeOverride(finalSize);
            var columnWidth = Math.Floor(finalSize.Width/_columns);
            var totalHeight = 0d;
            var top = 0d;
            var rowHeight = 0d;
            var overflow = 0d;
            var column = 0;
            var index = 0;
            var overflowAlreadyCount = false;

            foreach (UIElement child in Children)
            {
                // Compute the tile size and position
                child.Arrange(new Rect(columnWidth*column, top, columnWidth, child.DesiredSize.Height));
                column++;
                rowHeight = Children.Count >= _columns
                    ? Math.Max(rowHeight, child.DesiredSize.Height)
                    : Math.Min(rowHeight, child.DesiredSize.Height);
                index++;

                // Check if the current element is at the end of a row and add an height overflow to get enough space for the next elements of the second row
                if (column == _columns && Children.Count != index && (Children.Count - index + 1) <= _columns &&
                    !overflowAlreadyCount)
                {
                    overflow = rowHeight;
                    totalHeight += rowHeight;
                    overflowAlreadyCount = true;
                }
                else
                {
                    if (!overflowAlreadyCount)
                        totalHeight += rowHeight;
                }

                if (column != _columns) continue;
                column = 0;
                top += rowHeight;
                rowHeight = 0;
            }

            if (Children.Count >= _columns)
                totalHeight = totalHeight/_columns + overflow;

            Height = totalHeight;
            finalSize.Height = totalHeight;
            return base.ArrangeOverride(finalSize);
        }

19 View Source File : LineAnnotation.cs
License : MIT License
Project Creator : AlexGyver

public override void Render(IRenderContext rc, PlotModel model)
        {
            base.Render(rc, model);

            bool aliased = false;

            double actualMinimumX = Math.Max(this.MinimumX, this.XAxis.ActualMinimum);
            double actualMaximumX = Math.Min(this.MaximumX, this.XAxis.ActualMaximum);
            double actualMinimumY = Math.Max(this.MinimumY, this.YAxis.ActualMinimum);
            double actualMaximumY = Math.Min(this.MaximumY, this.YAxis.ActualMaximum);

            if (!this.ClipByXAxis)
            {
                double right = XAxis.InverseTransform(PlotModel.PlotArea.Right);
                double left = XAxis.InverseTransform(PlotModel.PlotArea.Left);
                actualMaximumX = Math.Max(left, right);
                actualMinimumX = Math.Min(left, right);
            }

            if (!this.ClipByYAxis)
            {
                double bottom = YAxis.InverseTransform(PlotModel.PlotArea.Bottom);
                double top = YAxis.InverseTransform(PlotModel.PlotArea.Top);
                actualMaximumY = Math.Max(top, bottom);
                actualMinimumY = Math.Min(top, bottom);
            }

            // y=f(x)
            Func<double, double> fx = null;

            // x=f(y)
            Func<double, double> fy = null;

            switch (this.Type)
            {
                case LineAnnotationType.Horizontal:
                    fx = x => this.Y;
                    break;
                case LineAnnotationType.Vertical:
                    fy = y => this.X;
                    break;
                case LineAnnotationType.EquationY:
                    fx = this.Equation;
                    break;
                case LineAnnotationType.EquationX:
                    fy = this.Equation;
                    break;
                default:
                    fx = x => (this.Slope * x) + this.Intercept;
                    break;
            }

            var points = new List<DataPoint>();

            bool isCurvedLine = !(this.XAxis is LinearAxis) || !(this.YAxis is LinearAxis) || this.Type == LineAnnotationType.EquationY;

            if (!isCurvedLine)
            {
                // we only need to calculate two points if it is a straight line
                if (fx != null)
                {
                    points.Add(new DataPoint(actualMinimumX, fx(actualMinimumX)));
                    points.Add(new DataPoint(actualMaximumX, fx(actualMaximumX)));
                }
                else if (fy != null)
                {
                    points.Add(new DataPoint(fy(actualMinimumY), actualMinimumY));
                    points.Add(new DataPoint(fy(actualMaximumY), actualMaximumY));
                }

                if (this.Type == LineAnnotationType.Horizontal || this.Type == LineAnnotationType.Vertical)
                {
                    // use aliased line drawing for horizontal and vertical lines
                    aliased = true;
                }
            }
            else
            {
                if (fx != null)
                {
                    double x = actualMinimumX;

                    // todo: the step size should be adaptive
                    double dx = (actualMaximumX - actualMinimumX) / 100;
                    while (true)
                    {
                        points.Add(new DataPoint(x, fx(x)));
                        if (x > actualMaximumX)
                        {
                            break;
                        }

                        x += dx;
                    }
                }
                else if (fy != null)
                {
                    double y = actualMinimumY;

                    // todo: the step size should be adaptive
                    double dy = (actualMaximumY - actualMinimumY) / 100;
                    while (true)
                    {
                        points.Add(new DataPoint(fy(y), y));
                        if (y > actualMaximumY)
                        {
                            break;
                        }

                        y += dy;
                    }
                }
            }

            // transform to screen coordinates
            this.screenPoints = points.Select(p => this.Transform(p)).ToList();

            // clip to the area defined by the axes
            var clippingRectangle = OxyRect.Create(
                this.ClipByXAxis ? this.XAxis.ScreenMin.X : PlotModel.PlotArea.Left,
                this.ClipByYAxis ? this.YAxis.ScreenMin.Y : PlotModel.PlotArea.Top,
                this.ClipByXAxis ? this.XAxis.ScreenMax.X : PlotModel.PlotArea.Right,
                this.ClipByYAxis ? this.YAxis.ScreenMax.Y : PlotModel.PlotArea.Bottom);

            const double MinimumSegmentLength = 4;

            IList<ScreenPoint> clippedPoints = null;

            rc.DrawClippedLine(
               this.screenPoints,
               clippingRectangle,
               MinimumSegmentLength * MinimumSegmentLength,
               this.GetSelectableColor(this.Color),
               this.StrokeThickness,
               this.LineStyle,
                this.LineJoin,
                aliased,
                pts => clippedPoints = pts);

            ScreenPoint position;
            double angle;
            double margin = this.TextMargin;

            if (this.TextHorizontalAlignment == HorizontalAlignment.Center)
            {
                margin = 0;
            }
            else
            {
                margin *= this.TextPosition < 0.5 ? 1 : -1;
            }

            if (clippedPoints != null && GetPointAtRelativeDistance(clippedPoints, this.TextPosition, margin, out position, out angle))
            {
                if (angle < -90)
                {
                    angle += 180;
                }

                if (angle > 90)
                {
                    angle -= 180;
                }

                switch (this.TextOrientation)
                {
                    case AnnotationTextOrientation.Horizontal:
                        angle = 0;
                        break;
                    case AnnotationTextOrientation.Vertical:
                        angle = -90;
                        break;
                }

                // Apply 'padding' to the position
                var angleInRadians = angle / 180 * Math.PI;
                var f = 1;

                if (this.TextHorizontalAlignment == HorizontalAlignment.Right)
                {
                    f = -1;
                }

                if (this.TextHorizontalAlignment == HorizontalAlignment.Center)
                {
                    f = 0;
                }

                position.X += f * this.TextPadding * Math.Cos(angleInRadians);
                position.Y += f * this.TextPadding * Math.Sin(angleInRadians);

                var cs = new CohenSutherlandClipping(clippingRectangle);
                if (!string.IsNullOrEmpty(this.Text) && cs.IsInside(position))
                {
                    rc.DrawClippedText(
                        clippingRectangle,
                        position,
                        this.Text,
                        this.ActualTextColor,
                        this.ActualFont,
                        this.ActualFontSize,
                        this.ActualFontWeight,
                        angle,
                        this.TextHorizontalAlignment,
                        this.TextVerticalAlignment);
                }
            }
        }

19 View Source File : CustomIndicatorTag.cs
License : MIT License
Project Creator : Actipro

public override void DrawGlyph(TextViewDrawContext context, ITextViewLine viewLine, TagSnapshotRange<IIndicatorTag> tagRange, Rect bounds) {
			var diameter = Math.Max(8.0, Math.Min(13, Math.Round(Math.Min(bounds.Width, bounds.Height) - 2.0)));
			var x = bounds.X + (bounds.Width - diameter) / 2.0;
			var y = bounds.Y + (bounds.Height - diameter) / 2.0;

			context.FillEllipse(new Rect(x, y, diameter, diameter), Color.FromArgb(0xff, 0x8a, 0xf3, 0x82));
			context.DrawEllipse(new Rect(x, y, diameter, diameter), Color.FromArgb(0xff, 0x00, 0x40, 0x00), LineKind.Solid, 1);
		}

19 View Source File : ZoomBorder.cs
License : GNU General Public License v3.0
Project Creator : Adam-Wilkinson

public void AutoFit(double panelWidth, double panelHeight, double elementWidth, double elementHeight)
        {
            double zoom = Min(panelWidth / elementWidth, panelHeight / elementHeight);
            matrix = ScaleAt(zoom, zoom, elementWidth / 2.0, elementHeight / 2.0);
            Invalidate();
        }

19 View Source File : VirtualizingWrapPanel .cs
License : MIT License
Project Creator : 944095635

private double Clamp(double value, double min, double max)
        {
            return Math.Min(Math.Max(value, min), max);
        }

19 View Source File : FileSize.cs
License : MIT License
Project Creator : Adoxio

public string ToString(int precision, IFormatProvider formatProvider = null)
		{
			var pow = Math.Floor((_value > 0 ? Math.Log(_value) : 0) / Math.Log(1024));

			pow = Math.Min(pow, _units.Length - 1);

			var value = _value / Math.Pow(1024, pow);

			var precisionString = formatProvider == null
				? precision.ToString(CultureInfo.CurrentCulture)
				: precision.ToString(formatProvider);

			return value.ToString(Math.Abs(pow - 0) < double.Epsilon ? "F0" : "F" + precisionString) + " " + _units[(int)pow];
		}

19 View Source File : RandomPricesDataSource.cs
License : MIT License
Project Creator : ABTSoftware

private PriceBar GetNextRandomPriceBar()
        {
            double close = _lastPriceBar.Close;
            double num = (_random.NextDouble() - 0.9) * _initialPriceBar.Close / 30.0;
            double num2 = _random.NextDouble();
            double num3 = _initialPriceBar.Close + _initialPriceBar.Close / 2.0 * Math.Sin(7.27220521664304E-06 * _currentTime) + _initialPriceBar.Close / 16.0 * Math.Cos(7.27220521664304E-05 * _currentTime) + _initialPriceBar.Close / 32.0 * Math.Sin(7.27220521664304E-05 * (10.0 + num2) * _currentTime) + _initialPriceBar.Close / 64.0 * Math.Cos(7.27220521664304E-05 * (20.0 + num2) * _currentTime) + num;
            double num4 = Math.Max(close, num3);
            double num5 = _random.NextDouble() * _initialPriceBar.Close / 100.0;
            double high = num4 + num5;
            double num6 = Math.Min(close, num3);
            double num7 = _random.NextDouble() * _initialPriceBar.Close / 100.0;
            double low = num6 - num7;
            long volume = (long) (_random.NextDouble()*30000 + 20000);
            DateTime openTime = _simulateDateGap ? EmulateDateGap(_lastPriceBar.DateTime) : _lastPriceBar.DateTime;
            DateTime closeTime = openTime.AddMinutes(_candleIntervalMinutes);
            PriceBar candle = new PriceBar(closeTime, close, high, low, num3, volume);
            _lastPriceBar = new PriceBar(candle.DateTime, candle.Open, candle.High, candle.Low, candle.Close, volume);
            _currentTime += _candleIntervalMinutes * 60;
            return candle;
        }

19 View Source File : SimpleAudioPlayerImplementation.cs
License : MIT License
Project Creator : adrianstevens

void SetVolume(double volume, double balance)
        {
            if (player == null || isDisposed) return;

            player.Volume = Math.Min(1, Math.Max(0, volume));
            player.AudioBalance = Math.Min(1, Math.Max(-1, balance));
        }

19 View Source File : SimpleAudioPlayerImplementation.cs
License : MIT License
Project Creator : adrianstevens

void SetVolume(double volume, double balance)
        {
            if (player == null)
                return;

            volume = Math.Max(0, volume);
            volume = Math.Min(1, volume);

            balance = Math.Max(-1, balance);
            balance = Math.Min(1, balance);

            player.Volume = (float)volume;
            player.Pan = (float)balance;
        }

19 View Source File : ThreadSafeRandom.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public static double NextIntervalMax(float qualityMod)
        {
            return Math.Min(maxExclusive, random.Value.NextDouble() + qualityMod);
        }

19 View Source File : ModEntry.cs
License : GNU General Public License v3.0
Project Creator : aedenthorn

private static void chooseStoneType_Postfix(MineShaft __instance, ref StardewValley.Object __result, Vector2 tile)
        {
            if(__result == null)
            {
                return;
            }
            List<int> ores = new List<int>() { 765, 764, 290, 751 };
            var x = __result.ParentSheetIndex;
            if (!(x >= 31 && x <= 42 || x >= 47 && x <= 54 || ores.Contains(x)))
            {
                return;
            }

            if (__instance.getMineArea(-1) == 0 || __instance.getMineArea(-1) == 10)
            {
                double chanceForOre = 0.029 * Config.ChanceForOresMultiplierInMines - 0.029;

                if (__instance.mineLevel != 1 && __instance.mineLevel % 5 != 0 && Game1.random.NextDouble() < chanceForOre)
                {
                    __result = new StardewValley.Object(tile, 751, "Stone", true, false, false, false)
                    {
                        MinutesUntilReady = 3
                    };
                }
            }
            else if (__instance.getMineArea(-1) == 40)
            {
                double chanceForOre = 0.029 * Config.ChanceForOresMultiplierInMines - 0.029;
                if (__instance.mineLevel % 5 != 0 && Game1.random.NextDouble() < chanceForOre)
                {
                    __result = new StardewValley.Object(tile, 290, "Stone", true, false, false, false)
                    {
                        MinutesUntilReady = 4
                    };
                }
            }
            else if (__instance.getMineArea(-1) == 80)
            {
                double chanceForOre = 0.029 * Config.ChanceForOresMultiplierInMines - 0.029;
                if (__instance.mineLevel % 5 != 0 && Game1.random.NextDouble() < chanceForOre)
                {
                    __result = new StardewValley.Object(tile, 764, "Stone", true, false, false, false)
                    {
                        MinutesUntilReady = 8
                    };
                }
            }
            else if (__instance.getMineArea(-1) == 77377)
            {
                return;
            }
            else
            {
                int skullCavernMineLevel = __instance.mineLevel - 120;
                double chanceForOre = 0.02 + (double)skullCavernMineLevel * 0.0005;
                if (__instance.mineLevel >= 130)
                {
                    chanceForOre += 0.01 * (double)((float)(Math.Min(100, skullCavernMineLevel) - 10) / 10f);
                }
                double iridiumBoost = 0.0;
                if (__instance.mineLevel >= 130)
                {
                    iridiumBoost += 0.001 * (double)((float)(skullCavernMineLevel - 10) / 10f);
                }
                iridiumBoost = Math.Min(iridiumBoost, 0.004);
                if (skullCavernMineLevel > 100)
                {
                    iridiumBoost += (double)skullCavernMineLevel / 1000000.0;
                }

                chanceForOre = chanceForOre * Config.ChanceForOreMultiplier - chanceForOre;

                if (ores.Contains(x) || Game1.random.NextDouble() < chanceForOre) // if already an ore, don't check again
                {
                    double chanceForIridium = (double)Math.Min(100, skullCavernMineLevel) * (0.0003 + iridiumBoost);
                    double chanceForGold = 0.01 + (double)(__instance.mineLevel - Math.Min(150, skullCavernMineLevel)) * 0.0005;
                    double chanceForIron = Math.Min(0.5, 0.1 + (double)(__instance.mineLevel - Math.Min(200, skullCavernMineLevel)) * 0.005);

                    chanceForIridium *= Config.ChanceForIridiumMultiplier;
                    chanceForGold *= Config.ChanceForGoldMultiplier;
                    chanceForIron *= Config.ChanceForIronMultiplier;

                    if (Game1.random.NextDouble() < chanceForIridium)
                    {
                        __result = new StardewValley.Object(tile, 765, "Stone", true, false, false, false)
                        {
                            MinutesUntilReady = 16
                        };
                    }
                    else if (Game1.random.NextDouble() < chanceForGold)
                    {
                        __result = new StardewValley.Object(tile, 764, "Stone", true, false, false, false)
                        {
                            MinutesUntilReady = 8
                        };
                    }
                    else if (Game1.random.NextDouble() < chanceForIron)
                    {
                        __result = new StardewValley.Object(tile, 290, "Stone", true, false, false, false)
                        {
                            MinutesUntilReady = 4
                        };
                    }
                    else
                    {
                        __result = new StardewValley.Object(tile, 751, "Stone", true, false, false, false)
                        {
                            MinutesUntilReady = 2
                        };
                    }
                }
            }

            /*
            if (!ores.Contains(__result.ParentSheetIndex))
            {
                foreach(CustomOreNode node in CustomOreNodeData)
                {

                }
            }
            */
        }

19 View Source File : ConsoleProgressBar.cs
License : MIT License
Project Creator : a-luna

public void Report(double value)
        {
            // Make sure value is in [0..1] range
            value = Math.Max(0, Math.Min(1, value));
            Interlocked.Exchange(ref CurrentProgress, value);
        }

19 View Source File : Curve.cs
License : The Unlicense
Project Creator : aeroson

public static double ModifyTime(double time, double intervalBegin, double intervalEnd, CurveEndpointBehavior preLoop, CurveEndpointBehavior postLoop)
        {
            if (time < intervalBegin)
            {
                switch (preLoop)
                {
                    case CurveEndpointBehavior.Wrap:
                        double modifiedTime = time - intervalBegin;
                        double intervalLength = intervalEnd - intervalBegin;
                        modifiedTime %= intervalLength;
                        return intervalEnd + modifiedTime;
                    case CurveEndpointBehavior.Clamp:
                        return Math.Max(intervalBegin, time);
                    case CurveEndpointBehavior.Mirror:
                        modifiedTime = time - intervalBegin;
                        intervalLength = intervalEnd - intervalBegin;
                        var numFlips = (int) (modifiedTime / intervalLength);
                        if (numFlips % 2 == 0)
                            return intervalBegin - modifiedTime % intervalLength;
                        return intervalEnd + modifiedTime % intervalLength;
                }
            }
            else if (time >= intervalEnd)
            {
                switch (postLoop)
                {
                    case CurveEndpointBehavior.Wrap:
                        double modifiedTime = time - intervalEnd;
                        double intervalLength = intervalEnd - intervalBegin;
                        modifiedTime %= intervalLength;
                        return intervalBegin + modifiedTime;
                    case CurveEndpointBehavior.Clamp:
                        return Math.Min(intervalEnd, time);
                    case CurveEndpointBehavior.Mirror:
                        modifiedTime = time - intervalEnd;
                        intervalLength = intervalEnd - intervalBegin;
                        var numFlips = (int) (modifiedTime / intervalLength);
                        if (numFlips % 2 == 0)
                            return intervalEnd - modifiedTime % intervalLength;
                        return intervalBegin + modifiedTime % intervalLength;
                }
            }
            return time;
        }

19 View Source File : Particle.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public void Update(ParticleType particleType, bool persistent, PhysicsPart part, AFrame parent)
        {
            var currentTime = PhysicsTimer.CurrentTime;
            var elapsedTime = currentTime - LastUpdateTime;

            if (persistent)
            {
                Lifetime += elapsedTime;
                LastUpdateTime = currentTime;
            }
            else
                Lifetime = elapsedTime;

            var lifetime = (float)Lifetime;

            switch (particleType)
            {
                case ParticleType.Still:
                    part.Pos.Frame.Origin = parent.Origin + Offset;
                    break;
                case ParticleType.LocalVelocity:
                case ParticleType.GlobalVelocity:
                    part.Pos.Frame.Origin = (lifetime * A) + parent.Origin + Offset;
                    break;
                case ParticleType.ParabolicLVGA:
                case ParticleType.ParabolicLVLA:
                case ParticleType.ParabolicGVGA:
                    part.Pos.Frame.Origin += (lifetime * lifetime * B / 2.0f) + (lifetime * A) + Offset;
                    break;
                case ParticleType.ParabolicLVGAGR:
                case ParticleType.ParabolicLVLALR:
                case ParticleType.ParabolicGVGAGR:
                    part.Pos.Frame = new AFrame(parent);
                    part.Pos.Frame.Origin += (lifetime * lifetime * B / 2.0f) + (lifetime * A) + Offset;
                    part.Pos.Frame.Rotate(lifetime * C);
                    break;
                case ParticleType.Swarm:
                    var swarm = (lifetime * A) + C + parent.Origin + Offset;
                    part.Pos.Frame.Origin.X = (float)Math.Cos(lifetime * B.X) + swarm.X;
                    part.Pos.Frame.Origin.Y = (float)Math.Sin(lifetime * B.Y) + swarm.Y;
                    part.Pos.Frame.Origin.Z = (float)Math.Cos(lifetime * B.Z) + swarm.Z;
                    break;
                case ParticleType.Explode:
                    part.Pos.Frame.Origin = (lifetime * B + C * A.X) * lifetime + Offset + parent.Origin;
                    break;
                case ParticleType.Implode:
                    part.Pos.Frame.Origin = ((float)Math.Cos(A.X * lifetime) * C) + (lifetime * lifetime * B) + parent.Origin + Offset;
                    break;
            }

            var interval = Math.Min(Lifetime / Lifespan, 1.0f);

            var currentScale = StartScale + (FinalScale - StartScale) * interval;
            var currentTrans = StartTrans + (FinalTrans - StartTrans) * interval;

            part.GfxObjScale = new Vector3((float)currentScale);
            part.SetTranslucency((float)currentTrans);
        }

19 View Source File : Color.cs
License : GNU General Public License v3.0
Project Creator : aglab2

public static void RGB2HSL(ColorRGB rgb, out double h, out double s, out double l)
        {
            double r = rgb.R / 255.0;
            double g = rgb.G / 255.0;
            double b = rgb.B / 255.0;
            double v;
            double m;
            double vm;
            double r2, g2, b2;

            h = 0; // default to black
            s = 0;
            l = 0;
            v = Math.Max(r, g);
            v = Math.Max(v, b);
            m = Math.Min(r, g);
            m = Math.Min(m, b);
            l = (m + v) / 2.0;
            if (l <= 0.0)
            {
                return;
            }
            vm = v - m;
            s = vm;
            if (s > 0.0)
            {
                s /= (l <= 0.5) ? (v + m) : (2.0 - v - m);
            }
            else
            {
                return;
            }
            r2 = (v - r) / vm;
            g2 = (v - g) / vm;
            b2 = (v - b) / vm;
            if (r == v)
            {
                h = (g == m ? 5.0 + b2 : 1.0 - g2);
            }
            else if (g == v)
            {
                h = (b == m ? 1.0 + r2 : 3.0 - b2);
            }
            else
            {
                h = (r == m ? 3.0 + g2 : 5.0 - r2);
            }
            h /= 6.0;
        }

19 View Source File : HSVUtil.cs
License : MIT License
Project Creator : 734843327

public static HsvColor ConvertRgbToHsv(double r, double b, double g)
    {
        double delta, min;
        double h = 0, s, v;

        min = Math.Min(Math.Min(r, g), b);
        v = Math.Max(Math.Max(r, g), b);
        delta = v - min;

        if (v == 0.0)
            s = 0;
        else
            s = delta / v;

        if (s == 0)
            h = 360;
        else
        {
            if (r == v)
                h = (g - b) / delta;
            else if (g == v)
                h = 2 + (b - r) / delta;
            else if (b == v)
                h = 4 + (r - g) / delta;

            h *= 60;
            if (h <= 0.0)
                h += 360;
        }

        HsvColor hsvColor = new HsvColor();
        hsvColor.H = 360 - h;
        hsvColor.S = s;
        hsvColor.V = v / 255;

        return hsvColor;

    }

19 View Source File : IconFile.cs
License : MIT License
Project Creator : ahopper

internal static (Size, Matrix) CalculateSizeAndTransform(Size availableSize, Rect shapeBounds, Stretch Stretch)
        {
            Size shapeSize = new Size(shapeBounds.Right, shapeBounds.Bottom);
            Matrix translate = Matrix.Idenreplacedy;
            double desiredX = availableSize.Width;
            double desiredY = availableSize.Height;
            double sx = 0.0;
            double sy = 0.0;

            if (Stretch != Stretch.None)
            {
                shapeSize = shapeBounds.Size;
                translate = Matrix.CreateTranslation(-(Vector)shapeBounds.Position);
            }

            if (double.IsInfinity(availableSize.Width))
            {
                desiredX = shapeSize.Width;
            }

            if (double.IsInfinity(availableSize.Height))
            {
                desiredY = shapeSize.Height;
            }

            if (shapeBounds.Width > 0)
            {
                sx = desiredX / shapeSize.Width;
            }

            if (shapeBounds.Height > 0)
            {
                sy = desiredY / shapeSize.Height;
            }

            if (double.IsInfinity(availableSize.Width))
            {
                sx = sy;
            }

            if (double.IsInfinity(availableSize.Height))
            {
                sy = sx;
            }

            switch (Stretch)
            {
                case Stretch.Uniform:
                    sx = sy = Math.Min(sx, sy);
                    break;
                case Stretch.UniformToFill:
                    sx = sy = Math.Max(sx, sy);
                    break;
                case Stretch.Fill:
                    if (double.IsInfinity(availableSize.Width))
                    {
                        sx = 1.0;
                    }

                    if (double.IsInfinity(availableSize.Height))
                    {
                        sy = 1.0;
                    }

                    break;
                default:
                    sx = sy = 1;
                    break;
            }

            var transform = translate * Matrix.CreateScale(sx, sy);
            var size = new Size(shapeSize.Width * sx, shapeSize.Height * sy);
            return (size, transform);
        }

19 View Source File : SkillCheck.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public static double GetSkillChance(int skill, int difficulty, float factor = 0.03f)
        {
            var chance = 1.0 - (1.0 / (1.0 + Math.Exp(factor * (skill - difficulty))));

            return Math.Min(1.0, Math.Max(0.0, chance));
        }

19 View Source File : MainWindow.xaml.cs
License : Apache License 2.0
Project Creator : AKruimink

private static object OnCoerceScaleValue(DependencyObject o, object value)
        {
            var newValue = 1.0d;

            if (double.IsNaN((double)value))
            {
                return newValue;
            }

            newValue = Math.Min(MaximumScaleValue, (double)value);
            newValue = Math.Max(MinimumScaleValue, newValue);

            return newValue;
        }

19 View Source File : ExtensionMethods.cs
License : MIT License
Project Creator : Abdesol

public static double CoerceValue(this double value, double minimum, double maximum)
		{
			return Math.Max(Math.Min(value, maximum), minimum);
		}

19 View Source File : ProgressBar.cs
License : MIT License
Project Creator : alecgn

public void Report(double value)
        {
            // Make sure value is in [0..1] range
            value = Math.Max(0, Math.Min(1, value));
            Interlocked.Exchange(ref currentProgress, value);
        }

19 View Source File : MainControl.xaml.cs
License : MIT License
Project Creator : Actipro

private void GenerateNewValue() {
			int minChars = 6;
			int maxChars = 12;
			string value = "";

			// Set min/max chars
			if (barCode.Symbology is Ean13Symbology) {
				value = "2";
				minChars = 11;
				maxChars = 11;
			}
			else if (barCode.Symbology is Ean8Symbology) {
				minChars = 7;
				maxChars = 7;
			}
			else if ((barCode.Symbology is PostnetSymbology) || (barCode.Symbology is UpcASymbology)) {
				minChars = 11;
				maxChars = 11;
			}
			else if (barCode.Symbology is UpcESymbology) {
				minChars = 7;
				maxChars = 7;
			}

			// Randomly generate a value
			DateTime dateTime = DateTime.Now;
			Random random = new Random(dateTime.Millisecond);

			int count = (int)Math.Max(minChars, Math.Min(maxChars, minChars + (random.NextDouble() * (maxChars - minChars))));
			for (int index = 0; index < count; index++)
				value += "0123456789"[(int)Math.Min(9, random.NextDouble() * 10)];

			// Append any necessary pre/post text
			if (barCode.Symbology is CodabarSymbology)
				value = String.Format("A{0}A", value);
			else if (barCode.Symbology is UpcESymbology)
				value = String.Format("0{0}", value);

			// Set the value
			barCode.Symbology.Value = value;
		}

19 View Source File : MercatorProjection.cs
License : MIT License
Project Creator : alen-smajic

public static double latToY(double lat)
    {
        lat = Math.Min(89.5, Math.Max(lat, -89.5));
        double phi = DegToRad(lat);
        double sinphi = Math.Sin(phi);
        double con = ECCENT * sinphi;
        con = Math.Pow(((1.0 - con) / (1.0 + con)), COM);
        double ts = Math.Tan(0.5 * ((Math.PI * 0.5) - phi)) / con;
        return 0 - R_MAJOR * Math.Log(ts);
    }

19 View Source File : bdsvd.cs
License : MIT License
Project Creator : 1CM69

private static void svd2x2(double f, double g, double h, ref double ssmin, ref double ssmax)
  {
    double val1_1 = System.Math.Abs(f);
    double val2_1 = System.Math.Abs(g);
    double val2_2 = System.Math.Abs(h);
    double num1 = System.Math.Min(val1_1, val2_2);
    double val1_2 = System.Math.Max(val1_1, val2_2);
    if (num1 == 0.0)
    {
      ssmin = 0.0;
      if (val1_2 == 0.0)
        ssmax = val2_1;
      else
        ssmax = System.Math.Max(val1_2, val2_1) * System.Math.Sqrt(1.0 + AP.Math.Sqr(System.Math.Min(val1_2, val2_1) / System.Math.Max(val1_2, val2_1)));
    }
    else if (val2_1 < val1_2)
    {
      double num2 = 1.0 + num1 / val1_2;
      double num3 = (val1_2 - num1) / val1_2;
      double num4 = AP.Math.Sqr(val2_1 / val1_2);
      double num5 = 2.0 / (System.Math.Sqrt(num2 * num2 + num4) + System.Math.Sqrt(num3 * num3 + num4));
      ssmin = num1 * num5;
      ssmax = val1_2 / num5;
    }
    else
    {
      double num2 = val1_2 / val2_1;
      if (num2 == 0.0)
      {
        ssmin = num1 * val1_2 / val2_1;
        ssmax = val2_1;
      }
      else
      {
        double num3 = 1.0 + num1 / val1_2;
        double num4 = (val1_2 - num1) / val1_2;
        double num5 = 1.0 / (System.Math.Sqrt(1.0 + AP.Math.Sqr(num3 * num2)) + System.Math.Sqrt(1.0 + AP.Math.Sqr(num4 * num2)));
        ssmin = num1 * num5 * num2;
        ssmin = ssmin + ssmin;
        ssmax = val2_1 / (num5 + num5);
      }
    }
  }

19 View Source File : Annotation.cs
License : MIT License
Project Creator : AlexGyver

protected OxyRect GetClippingRect()
        {
            double minX = Math.Min(this.XAxis.ScreenMin.X, this.XAxis.ScreenMax.X);
            double minY = Math.Min(this.YAxis.ScreenMin.Y, this.YAxis.ScreenMax.Y);
            double maxX = Math.Max(this.XAxis.ScreenMin.X, this.XAxis.ScreenMax.X);
            double maxY = Math.Max(this.YAxis.ScreenMin.Y, this.YAxis.ScreenMax.Y);

            return new OxyRect(minX, minY, maxX - minX, maxY - minY);
        }

19 View Source File : SimpleFlowDocumentReader.cs
License : MIT License
Project Creator : Actipro

protected override void OnRenderSizeChanged(SizeChangedInfo sizeInfo) {
			// Call the base methods
			base.OnRenderSizeChanged(sizeInfo);

			// Dynamically adjust the page width and viewing mode based on the available width
			this.Doreplacedent.PageWidth = Math.Max(0.0, Math.Min(this.Doreplacedent.MaxPageWidth, sizeInfo.NewSize.Width) - SystemParameters.VerticalScrollBarWidth);
			this.ViewingMode = (sizeInfo.NewSize.Width > this.Doreplacedent.MaxPageWidth ? FlowDoreplacedentReaderViewingMode.Page : FlowDoreplacedentReaderViewingMode.Scroll);
		}

19 View Source File : RealTimeGhostedTraces.xaml.cs
License : MIT License
Project Creator : ABTSoftware

private static double Constrain(double value, double noLowerThan, double noBiggerThan)
        {
            return Math.Max(Math.Min(value, noBiggerThan), noLowerThan);
        }

19 View Source File : bdsvd.cs
License : MIT License
Project Creator : 1CM69

private static bool bidiagonalsvddecompositioninternal(ref double[] d, double[] e, int n, bool isupper, bool isfractionalaccuracyrequired, ref double[,] u, int ustart, int nru, ref double[,] c, int cstart, int ncc, ref double[,] vt, int vstart, int ncvt)
  {
    int index1 = 0;
    double num1 = 0.0;
    double num2 = 0.0;
    double cs1 = 0.0;
    double sn1 = 0.0;
    double num3 = 0.0;
    double ssmin1 = 0.0;
    double ssmin2 = 0.0;
    double ssmax = 0.0;
    double num4 = 0.0;
    double num5 = 0.0;
    double sn2 = 0.0;
    double[] numArray1 = new double[0];
    double[] numArray2 = new double[0];
    double[] numArray3 = new double[0];
    double[] numArray4 = new double[0];
    double[] numArray5 = new double[0];
    double[] numArray6 = new double[0];
    double[] numArray7 = new double[0];
    double[] numArray8 = new double[0];
    double r = 0.0;
    e = (double[]) e.Clone();
    bool flag1 = true;
    if (n == 0)
      return flag1;
    if (n == 1)
    {
      if (d[1] < 0.0)
      {
        d[1] = -d[1];
        if (ncvt > 0)
        {
          for (int index2 = vstart; index2 <= vstart + ncvt - 1; ++index2)
            vt[vstart, index2] = -1.0 * vt[vstart, index2];
        }
      }
      return flag1;
    }
    double[] c1 = new double[n - 1 + 1];
    double[] s1 = new double[n - 1 + 1];
    double[] c2 = new double[n - 1 + 1];
    double[] s2 = new double[n - 1 + 1];
    int m2 = ustart + System.Math.Max(nru - 1, 0);
    int n2_1 = vstart + System.Math.Max(ncvt - 1, 0);
    int n2_2 = cstart + System.Math.Max(ncc - 1, 0);
    double[] work1 = new double[m2 + 1];
    double[] work2 = new double[n2_1 + 1];
    double[] work3 = new double[n2_2 + 1];
    int num6 = 12;
    bool isforward = true;
    double[] numArray9 = new double[n + 1];
    for (int index2 = 1; index2 <= n - 1; ++index2)
      numArray9[index2] = e[index2];
    e = new double[n + 1];
    for (int index2 = 1; index2 <= n - 1; ++index2)
      e[index2] = numArray9[index2];
    e[n] = 0.0;
    int num7 = 0;
    double num8 = 5E-16;
    double num9 = 1E-300;
    if (!isupper)
    {
      for (int index2 = 1; index2 <= n - 1; ++index2)
      {
        rotations.generaterotation(d[index2], e[index2], ref cs1, ref sn2, ref num3);
        d[index2] = num3;
        e[index2] = sn2 * d[index2 + 1];
        d[index2 + 1] = cs1 * d[index2 + 1];
        c1[index2] = cs1;
        s1[index2] = sn2;
      }
      if (nru > 0)
        rotations.applyrotationsfromtheright(isforward, ustart, m2, 1 + ustart - 1, n + ustart - 1, ref c1, ref s1, ref u, ref work1);
      if (ncc > 0)
        rotations.applyrotationsfromtheleft(isforward, 1 + cstart - 1, n + cstart - 1, cstart, n2_2, ref c1, ref s1, ref c, ref work3);
    }
    double num10 = System.Math.Max(10.0, System.Math.Min(100.0, System.Math.Pow(num8, -0.125))) * num8;
    if (!isfractionalaccuracyrequired)
      num10 = -num10;
    double val1_1 = 0.0;
    for (int index2 = 1; index2 <= n; ++index2)
      val1_1 = System.Math.Max(val1_1, System.Math.Abs(d[index2]));
    for (int index2 = 1; index2 <= n - 1; ++index2)
      val1_1 = System.Math.Max(val1_1, System.Math.Abs(e[index2]));
    double val1_2 = 0.0;
    double num11;
    if (num10 >= 0.0)
    {
      double val1_3 = System.Math.Abs(d[1]);
      if (val1_3 != 0.0)
      {
        double val2 = val1_3;
        for (int index2 = 2; index2 <= n; ++index2)
        {
          val2 = System.Math.Abs(d[index2]) * (val2 / (val2 + System.Math.Abs(e[index2 - 1])));
          val1_3 = System.Math.Min(val1_3, val2);
          if (val1_3 == 0.0)
            break;
        }
      }
      double num12 = val1_3 / System.Math.Sqrt((double) n);
      num11 = System.Math.Max(num10 * num12, (double) (num6 * n * n) * num9);
    }
    else
      num11 = System.Math.Max(System.Math.Abs(num10) * val1_1, (double) (num6 * n * n) * num9);
    int num13 = num6 * n * n;
    int num14 = 0;
    int num15 = -1;
    int num16 = -1;
    int index3 = n;
    while (index3 > 1)
    {
      if (num14 > num13)
        return false;
      if (num10 < 0.0 & System.Math.Abs(d[index3]) <= num11)
        d[index3] = 0.0;
      double val1_3 = System.Math.Abs(d[index3]);
      double val1_4 = val1_3;
      bool flag2 = false;
      for (int index2 = 1; index2 <= index3 - 1; ++index2)
      {
        index1 = index3 - index2;
        double num12 = System.Math.Abs(d[index1]);
        double val2 = System.Math.Abs(e[index1]);
        if (num10 < 0.0 & num12 <= num11)
          d[index1] = 0.0;
        if (val2 <= num11)
        {
          flag2 = true;
          break;
        }
        val1_4 = System.Math.Min(val1_4, num12);
        val1_3 = System.Math.Max(val1_3, System.Math.Max(num12, val2));
      }
      if (!flag2)
      {
        index1 = 0;
      }
      else
      {
        e[index1] = 0.0;
        if (index1 == index3 - 1)
        {
          --index3;
          continue;
        }
      }
      ++index1;
      if (index1 == index3 - 1)
      {
        bdsvd.svdv2x2(d[index3 - 1], e[index3 - 1], d[index3], ref ssmin2, ref ssmax, ref num5, ref num2, ref num4, ref num1);
        d[index3 - 1] = ssmax;
        e[index3 - 1] = 0.0;
        d[index3] = ssmin2;
        if (ncvt > 0)
        {
          int index2 = index3 + (vstart - 1);
          int index4 = index3 - 1 + (vstart - 1);
          for (int index5 = vstart; index5 <= n2_1; ++index5)
            work2[index5] = num2 * vt[index4, index5];
          for (int index5 = vstart; index5 <= n2_1; ++index5)
            work2[index5] = work2[index5] + num5 * vt[index2, index5];
          for (int index5 = vstart; index5 <= n2_1; ++index5)
            vt[index2, index5] = num2 * vt[index2, index5];
          for (int index5 = vstart; index5 <= n2_1; ++index5)
            vt[index2, index5] = vt[index2, index5] - num5 * vt[index4, index5];
          for (int index5 = vstart; index5 <= n2_1; ++index5)
            vt[index4, index5] = work2[index5];
        }
        if (nru > 0)
        {
          int index2 = index3 + ustart - 1;
          int index4 = index3 - 1 + ustart - 1;
          for (int index5 = ustart; index5 <= m2; ++index5)
            work1[index5] = num1 * u[index5, index4];
          for (int index5 = ustart; index5 <= m2; ++index5)
            work1[index5] = work1[index5] + num4 * u[index5, index2];
          for (int index5 = ustart; index5 <= m2; ++index5)
            u[index5, index2] = num1 * u[index5, index2];
          for (int index5 = ustart; index5 <= m2; ++index5)
            u[index5, index2] = u[index5, index2] - num4 * u[index5, index4];
          for (int index5 = ustart; index5 <= m2; ++index5)
            u[index5, index4] = work1[index5];
        }
        if (ncc > 0)
        {
          int index2 = index3 + cstart - 1;
          int index4 = index3 - 1 + cstart - 1;
          for (int index5 = cstart; index5 <= n2_2; ++index5)
            work3[index5] = num1 * c[index4, index5];
          for (int index5 = cstart; index5 <= n2_2; ++index5)
            work3[index5] = work3[index5] + num4 * c[index2, index5];
          for (int index5 = cstart; index5 <= n2_2; ++index5)
            c[index2, index5] = num1 * c[index2, index5];
          for (int index5 = cstart; index5 <= n2_2; ++index5)
            c[index2, index5] = c[index2, index5] - num4 * c[index4, index5];
          for (int index5 = cstart; index5 <= n2_2; ++index5)
            c[index4, index5] = work3[index5];
        }
        index3 -= 2;
      }
      else
      {
        bool flag3 = false;
        if (num7 == 1 & System.Math.Abs(d[index1]) < 0.001 * System.Math.Abs(d[index3]))
          flag3 = true;
        if (num7 == 2 & System.Math.Abs(d[index3]) < 0.001 * System.Math.Abs(d[index1]))
          flag3 = true;
        if (index1 != num15 | index3 != num16 | flag3)
          num7 = System.Math.Abs(d[index1]) < System.Math.Abs(d[index3]) ? 2 : 1;
        if (num7 == 1)
        {
          if (System.Math.Abs(e[index3 - 1]) <= System.Math.Abs(num10) * System.Math.Abs(d[index3]) | num10 < 0.0 & System.Math.Abs(e[index3 - 1]) <= num11)
          {
            e[index3 - 1] = 0.0;
            continue;
          }
          if (num10 >= 0.0)
          {
            double val2 = System.Math.Abs(d[index1]);
            val1_2 = val2;
            bool flag4 = false;
            for (int index2 = index1; index2 <= index3 - 1; ++index2)
            {
              if (System.Math.Abs(e[index2]) <= num10 * val2)
              {
                e[index2] = 0.0;
                flag4 = true;
                break;
              }
              val2 = System.Math.Abs(d[index2 + 1]) * (val2 / (val2 + System.Math.Abs(e[index2])));
              val1_2 = System.Math.Min(val1_2, val2);
            }
            if (flag4)
              continue;
          }
        }
        else
        {
          if (System.Math.Abs(e[index1]) <= System.Math.Abs(num10) * System.Math.Abs(d[index1]) | num10 < 0.0 & System.Math.Abs(e[index1]) <= num11)
          {
            e[index1] = 0.0;
            continue;
          }
          if (num10 >= 0.0)
          {
            double val2 = System.Math.Abs(d[index3]);
            val1_2 = val2;
            bool flag4 = false;
            for (int index2 = index3 - 1; index2 >= index1; --index2)
            {
              if (System.Math.Abs(e[index2]) <= num10 * val2)
              {
                e[index2] = 0.0;
                flag4 = true;
                break;
              }
              val2 = System.Math.Abs(d[index2]) * (val2 / (val2 + System.Math.Abs(e[index2])));
              val1_2 = System.Math.Min(val1_2, val2);
            }
            if (flag4)
              continue;
          }
        }
        num15 = index1;
        num16 = index3;
        if (num10 >= 0.0 & (double) n * num10 * (val1_2 / val1_3) <= System.Math.Max(num8, 0.01 * num10))
        {
          ssmin1 = 0.0;
        }
        else
        {
          double num12;
          if (num7 == 1)
          {
            num12 = System.Math.Abs(d[index1]);
            bdsvd.svd2x2(d[index3 - 1], e[index3 - 1], d[index3], ref ssmin1, ref num3);
          }
          else
          {
            num12 = System.Math.Abs(d[index3]);
            bdsvd.svd2x2(d[index1], e[index1], d[index1 + 1], ref ssmin1, ref num3);
          }
          if (num12 > 0.0 && AP.Math.Sqr(ssmin1 / num12) < num8)
            ssmin1 = 0.0;
        }
        num14 = num14 + index3 - index1;
        double cs2;
        if (ssmin1 == 0.0)
        {
          if (num7 == 1)
          {
            cs1 = 1.0;
            cs2 = 1.0;
            for (int index2 = index1; index2 <= index3 - 1; ++index2)
            {
              rotations.generaterotation(d[index2] * cs1, e[index2], ref cs1, ref sn2, ref num3);
              if (index2 > index1)
                e[index2 - 1] = sn1 * num3;
              rotations.generaterotation(cs2 * num3, d[index2 + 1] * sn2, ref cs2, ref sn1, ref r);
              d[index2] = r;
              c1[index2 - index1 + 1] = cs1;
              s1[index2 - index1 + 1] = sn2;
              c2[index2 - index1 + 1] = cs2;
              s2[index2 - index1 + 1] = sn1;
            }
            double num12 = d[index3] * cs1;
            d[index3] = num12 * cs2;
            e[index3 - 1] = num12 * sn1;
            if (ncvt > 0)
              rotations.applyrotationsfromtheleft(isforward, index1 + vstart - 1, index3 + vstart - 1, vstart, n2_1, ref c1, ref s1, ref vt, ref work2);
            if (nru > 0)
              rotations.applyrotationsfromtheright(isforward, ustart, m2, index1 + ustart - 1, index3 + ustart - 1, ref c2, ref s2, ref u, ref work1);
            if (ncc > 0)
              rotations.applyrotationsfromtheleft(isforward, index1 + cstart - 1, index3 + cstart - 1, cstart, n2_2, ref c2, ref s2, ref c, ref work3);
            if (System.Math.Abs(e[index3 - 1]) <= num11)
              e[index3 - 1] = 0.0;
          }
          else
          {
            cs1 = 1.0;
            cs2 = 1.0;
            for (int index2 = index3; index2 >= index1 + 1; --index2)
            {
              rotations.generaterotation(d[index2] * cs1, e[index2 - 1], ref cs1, ref sn2, ref num3);
              if (index2 < index3)
                e[index2] = sn1 * num3;
              rotations.generaterotation(cs2 * num3, d[index2 - 1] * sn2, ref cs2, ref sn1, ref r);
              d[index2] = r;
              c1[index2 - index1] = cs1;
              s1[index2 - index1] = -sn2;
              c2[index2 - index1] = cs2;
              s2[index2 - index1] = -sn1;
            }
            double num12 = d[index1] * cs1;
            d[index1] = num12 * cs2;
            e[index1] = num12 * sn1;
            if (ncvt > 0)
              rotations.applyrotationsfromtheleft(!isforward, index1 + vstart - 1, index3 + vstart - 1, vstart, n2_1, ref c2, ref s2, ref vt, ref work2);
            if (nru > 0)
              rotations.applyrotationsfromtheright(!isforward, ustart, m2, index1 + ustart - 1, index3 + ustart - 1, ref c1, ref s1, ref u, ref work1);
            if (ncc > 0)
              rotations.applyrotationsfromtheleft(!isforward, index1 + cstart - 1, index3 + cstart - 1, cstart, n2_2, ref c1, ref s1, ref c, ref work3);
            if (System.Math.Abs(e[index1]) <= num11)
              e[index1] = 0.0;
          }
        }
        else if (num7 == 1)
        {
          double f1 = (System.Math.Abs(d[index1]) - ssmin1) * (bdsvd.extsignbdsqr(1.0, d[index1]) + ssmin1 / d[index1]);
          double g = e[index1];
          for (int index2 = index1; index2 <= index3 - 1; ++index2)
          {
            rotations.generaterotation(f1, g, ref num2, ref num5, ref num3);
            if (index2 > index1)
              e[index2 - 1] = num3;
            double f2 = num2 * d[index2] + num5 * e[index2];
            e[index2] = num2 * e[index2] - num5 * d[index2];
            g = num5 * d[index2 + 1];
            d[index2 + 1] = num2 * d[index2 + 1];
            rotations.generaterotation(f2, g, ref num1, ref num4, ref num3);
            d[index2] = num3;
            f1 = num1 * e[index2] + num4 * d[index2 + 1];
            d[index2 + 1] = num1 * d[index2 + 1] - num4 * e[index2];
            if (index2 < index3 - 1)
            {
              g = num4 * e[index2 + 1];
              e[index2 + 1] = num1 * e[index2 + 1];
            }
            c1[index2 - index1 + 1] = num2;
            s1[index2 - index1 + 1] = num5;
            c2[index2 - index1 + 1] = num1;
            s2[index2 - index1 + 1] = num4;
          }
          e[index3 - 1] = f1;
          if (ncvt > 0)
            rotations.applyrotationsfromtheleft(isforward, index1 + vstart - 1, index3 + vstart - 1, vstart, n2_1, ref c1, ref s1, ref vt, ref work2);
          if (nru > 0)
            rotations.applyrotationsfromtheright(isforward, ustart, m2, index1 + ustart - 1, index3 + ustart - 1, ref c2, ref s2, ref u, ref work1);
          if (ncc > 0)
            rotations.applyrotationsfromtheleft(isforward, index1 + cstart - 1, index3 + cstart - 1, cstart, n2_2, ref c2, ref s2, ref c, ref work3);
          if (System.Math.Abs(e[index3 - 1]) <= num11)
            e[index3 - 1] = 0.0;
        }
        else
        {
          double f1 = (System.Math.Abs(d[index3]) - ssmin1) * (bdsvd.extsignbdsqr(1.0, d[index3]) + ssmin1 / d[index3]);
          double g = e[index3 - 1];
          for (int index2 = index3; index2 >= index1 + 1; --index2)
          {
            rotations.generaterotation(f1, g, ref num2, ref num5, ref num3);
            if (index2 < index3)
              e[index2] = num3;
            double f2 = num2 * d[index2] + num5 * e[index2 - 1];
            e[index2 - 1] = num2 * e[index2 - 1] - num5 * d[index2];
            g = num5 * d[index2 - 1];
            d[index2 - 1] = num2 * d[index2 - 1];
            rotations.generaterotation(f2, g, ref num1, ref num4, ref num3);
            d[index2] = num3;
            f1 = num1 * e[index2 - 1] + num4 * d[index2 - 1];
            d[index2 - 1] = num1 * d[index2 - 1] - num4 * e[index2 - 1];
            if (index2 > index1 + 1)
            {
              g = num4 * e[index2 - 2];
              e[index2 - 2] = num1 * e[index2 - 2];
            }
            c1[index2 - index1] = num2;
            s1[index2 - index1] = -num5;
            c2[index2 - index1] = num1;
            s2[index2 - index1] = -num4;
          }
          e[index1] = f1;
          if (System.Math.Abs(e[index1]) <= num11)
            e[index1] = 0.0;
          if (ncvt > 0)
            rotations.applyrotationsfromtheleft(!isforward, index1 + vstart - 1, index3 + vstart - 1, vstart, n2_1, ref c2, ref s2, ref vt, ref work2);
          if (nru > 0)
            rotations.applyrotationsfromtheright(!isforward, ustart, m2, index1 + ustart - 1, index3 + ustart - 1, ref c1, ref s1, ref u, ref work1);
          if (ncc > 0)
            rotations.applyrotationsfromtheleft(!isforward, index1 + cstart - 1, index3 + cstart - 1, cstart, n2_2, ref c1, ref s1, ref c, ref work3);
        }
      }
    }
    for (int index2 = 1; index2 <= n; ++index2)
    {
      if (d[index2] < 0.0)
      {
        d[index2] = -d[index2];
        if (ncvt > 0)
        {
          for (int index4 = vstart; index4 <= n2_1; ++index4)
            vt[index2 + vstart - 1, index4] = -1.0 * vt[index2 + vstart - 1, index4];
        }
      }
    }
    for (int index2 = 1; index2 <= n - 1; ++index2)
    {
      int index4 = 1;
      double num12 = d[1];
      for (int index5 = 2; index5 <= n + 1 - index2; ++index5)
      {
        if (d[index5] <= num12)
        {
          index4 = index5;
          num12 = d[index5];
        }
      }
      if (index4 != n + 1 - index2)
      {
        d[index4] = d[n + 1 - index2];
        d[n + 1 - index2] = num12;
        if (ncvt > 0)
        {
          int num17 = n + 1 - index2;
          for (int index5 = vstart; index5 <= n2_1; ++index5)
            work2[index5] = vt[index4 + vstart - 1, index5];
          for (int index5 = vstart; index5 <= n2_1; ++index5)
            vt[index4 + vstart - 1, index5] = vt[num17 + vstart - 1, index5];
          for (int index5 = vstart; index5 <= n2_1; ++index5)
            vt[num17 + vstart - 1, index5] = work2[index5];
        }
        if (nru > 0)
        {
          int num17 = n + 1 - index2;
          for (int index5 = ustart; index5 <= m2; ++index5)
            work1[index5] = u[index5, index4 + ustart - 1];
          for (int index5 = ustart; index5 <= m2; ++index5)
            u[index5, index4 + ustart - 1] = u[index5, num17 + ustart - 1];
          for (int index5 = ustart; index5 <= m2; ++index5)
            u[index5, num17 + ustart - 1] = work1[index5];
        }
        if (ncc > 0)
        {
          int num17 = n + 1 - index2;
          for (int index5 = cstart; index5 <= n2_2; ++index5)
            work3[index5] = c[index4 + cstart - 1, index5];
          for (int index5 = cstart; index5 <= n2_2; ++index5)
            c[index4 + cstart - 1, index5] = c[num17 + cstart - 1, index5];
          for (int index5 = cstart; index5 <= n2_2; ++index5)
            c[num17 + cstart - 1, index5] = work3[index5];
        }
      }
    }
    return flag1;
  }

19 View Source File : blas.cs
License : MIT License
Project Creator : 1CM69

public static double pythag2(double x, double y)
  {
    double val1 = System.Math.Abs(x);
    double val2 = System.Math.Abs(y);
    double num1 = System.Math.Max(val1, val2);
    double num2 = System.Math.Min(val1, val2);
    return num2 != 0.0 ? num1 * System.Math.Sqrt(1.0 + AP.Math.Sqr(num2 / num1)) : num1;
  }

19 View Source File : Geometry.cs
License : GNU Lesser General Public License v3.0
Project Creator : 9and3

public static List<Polyline> Boolean(ClipType clipType, IEnumerable<Polyline> polyA, IEnumerable<Polyline> polyB,
          Plane pln, double tolerance, bool evenOddFilling, double disregardPolygonsWithArea = 0.01) {

            foreach (var pline0 in polyA) {

                foreach (var pline1 in polyB) {
                    if (pline1.GetPlane().ClosestPoint(pline0[0]).DistanceToSquared(pline0[0]) > 0.001) {
                        return new List<Polyline>();
                    }
                }
            }


            Clipper642.Clipper clipper = new Clipper642.Clipper();
            PolyFillType polyfilltype = PolyFillType.pftEvenOdd;
            if (!evenOddFilling) {
                polyfilltype = PolyFillType.pftNonZero;
            }

            double area0 = 0;
            int count = 0;
            foreach (Polyline plA in polyA) {
                var p0 = plA.ToPath2D(pln, tolerance);
                clipper.AddPath(p0, PolyType.ptSubject, plA.IsClosed);

                if (count == 0) {
                    area0 = Math.Abs(Clipper642.Clipper.Area(p0) * tolerance * tolerance);
                    count++;
                }
            }

            double area1 = 0;
            foreach (Polyline plB in polyB) {
                var p0 = plB.ToPath2D(pln, tolerance);
                clipper.AddPath(plB.ToPath2D(pln, tolerance), PolyType.ptClip, true);
                if (count == 1) {
                    area1 = Math.Abs(Clipper642.Clipper.Area(p0) * tolerance * tolerance);
                    count++;
                }
            }

            PolyTree polytree = new PolyTree();

            clipper.Execute(clipType, polytree, polyfilltype, polyfilltype);
            if (polytree.Total == 0)
                return new List<Polyline>();

            List<Polyline> output = new List<Polyline>();

            // ReSharper disable once LoopCanBeConvertedToQuery

            double AreaMin = Math.Min(area0, area1);


            foreach (PolyNode pn in polytree.Iterate()) {
                if (pn.Contour.Count > 1) {
                    if (disregardPolygonsWithArea > 0)
                    {

                        double area = Math.Abs(Clipper642.Clipper.Area(pn.Contour)*tolerance* tolerance);
                      
                        //Rhino.RhinoApp.WriteLine(area.ToString());

                        if (area > AreaMin*disregardPolygonsWithArea)
                        {
                            output.Add(pn.Contour.ToPolyline(pln, tolerance, !pn.IsOpen));
                        }
                    }
                 
                }
            }

            return output;
        }

19 View Source File : DimTracePaletteProvider.cs
License : MIT License
Project Creator : ABTSoftware

public Color? OverrideStrokeColor(IRenderableSeries rSeries, int index, IPointMetadata metadata)
        {
            var defaultColor = rSeries.Stroke;

            if (rSeries.DataSeries == null)
                return defaultColor;

            var xyzSeries = ((XyzDataSeries<double, double, double>)rSeries.DataSeries);

            double actualTime = xyzSeries.ZValues[index];
            double latestTime = (double) xyzSeries.Tag;

            // how old is the sample? 1.0 = New, 0.0 = Oldest
            double sampleAge = (actualTime - latestTime) / 10.0;

            // Clamp in ten steps, e.g.  0.1, 0.2 .... 0.9, 1.0
            // Why? Creating a new Pen for each single sample will slow down SciChart significantly
            sampleAge = Math.Round(sampleAge * 10.0, 0) * 0.1;

            // Ensure in the range 0.3 ... 1.0 always 
            sampleAge = Math.Max(0.3, sampleAge);
            sampleAge = Math.Min(1.0, sampleAge);

            // Compute the Alpha based on sample age
            var modifiedColor = Color.FromArgb((byte)(sampleAge * 0xFF), defaultColor.R, defaultColor.G, defaultColor.B);
            return modifiedColor;
        }

19 View Source File : SimpleAudioPlayerImplementation.cs
License : MIT License
Project Creator : adrianstevens

void SetVolume(double volume, double balance)
		{
			if (player == null || isDisposed)
				return;

			volume = Math.Max(0, volume);
			volume = Math.Min(1, volume);

			//balance = Math.Max(-1, balance);
			//balance = Math.Min(1, balance);

			player.Volume = (float)volume;
		}

See More Examples