public override void Render(float deltaTime) { var deltaX = PrevX + (X - PrevX) * deltaTime; var deltaY = PrevY + (Y - PrevY) * deltaTime; var deltaSize = PrevSize + (Size - PrevSize) * deltaTime; var deltaAlpha = Math.Min(1, Math.Max(0, PrevAlpha + (Alpha - PrevAlpha) * deltaTime)); var deltaAngle = PrevAngle + (Angle - PrevAngle) * deltaTime; var c = Hue.Create(deltaX / Game.Instance.Width * 360); // GL.PushAttrib(AttribMask.LineBit); GL.PushMatrix(); //GL.LineWidth(deltaSize / StartSize); GL.Translate(deltaX, deltaY, 0); GL.Rotate(deltaAngle, 0, 0, 1); GL.Scale(deltaSize, deltaSize, 0); GL.Begin(PrimitiveType.Polygon); GL.Color4(c.X, c.Y, c.Z, deltaAlpha * 0.15); VertexUtil.PutCircle(0, 0, 1, 20); GL.End(); GL.Begin(PrimitiveType.LineLoop); GL.Color4(c.X, c.Y, c.Z, deltaAlpha); VertexUtil.PutCircle(0, 0, 1, 20); GL.End(); GL.PopMatrix(); //GL.PopAttrib(); }
public static WaterType GetWater(MapData[,] map, Vector2 pos) { int x = Math.Max(Math.Min((int)pos.X, map.GetLength(0) - 1), 0); int y = Math.Max(Math.Min((int)pos.Y, map.GetLength(1) - 1), 0); return(map[x, y].Water); }
public static void SetWater(MapData[,] heightMap, Vector2 pos, WaterType waterType) { int x = Math.Max(Math.Min((int)pos.X, heightMap.GetLength(0) - 1), 0); int y = Math.Max(Math.Min((int)pos.Y, heightMap.GetLength(1) - 1), 0); heightMap[x, y].Water = waterType; }
void UpdateVisibleRegion(LatLng pos) { var map = NativeMap; if (map == null) { return; } var projection = map.Projection; var width = Control.Width; var height = Control.Height; var ul = projection.FromScreenLocation(new global::Android.Graphics.Point(0, 0)); var ur = projection.FromScreenLocation(new global::Android.Graphics.Point(width, 0)); var ll = projection.FromScreenLocation(new global::Android.Graphics.Point(0, height)); var lr = projection.FromScreenLocation(new global::Android.Graphics.Point(width, height)); var dlat = Math.Max(Math.Abs(ul.Latitude - lr.Latitude), Math.Abs(ur.Latitude - ll.Latitude)); var dlong = Math.Max(Math.Abs(ul.Longitude - lr.Longitude), Math.Abs(ur.Longitude - ll.Longitude)); ((Map)Element).VisibleRegion = new MapSpan( new Position( pos.Latitude, pos.Longitude ), dlat, dlong ); }
public static float GetHeight(float[,] heightMap, Vector2 pos) { int x = Math.Max(Math.Min((int)pos.X, heightMap.GetLength(0) - 1), 0); int y = Math.Max(Math.Min((int)pos.Y, heightMap.GetLength(1) - 1), 0); return(heightMap[x, y]); }
private void showWinnerAnimation(string winnerImageUrl) { if (_cxPosition == 0) { _cxPosition = _ivWinner.MeasuredWidth / 2; _cyPosition = _ivWinner.MeasuredHeight / 2; _finalRadius = Math.Max(_ivWinner.Width, val2: _ivWinner.Height); } Glide .With(_activity) .Load(winnerImageUrl) .Apply(RequestOptions.CenterCropTransform()).Into(_ivWinner); _isWinnerRevealing = true; Animator anim = ViewAnimationUtils.CreateCircularReveal(_groupWinner, _cxPosition, _cyPosition, 0, _finalRadius); _groupWinner.Visibility = ViewStates.Visible; _winnerView.PlayAnimation(); anim.SetDuration(2000); anim.AddListener(this); anim.Start(); }
public static List <Vector3Int> MakeLine(Vector3Int pos1, Vector3Int pos2) { List <Vector3Int> affected = new List <Vector3Int>(); bool notdrawn = true; int x1 = pos1.x; int y1 = pos1.x; int z1 = pos1.x; int x2 = pos2.x; int y2 = pos2.y; int z2 = pos2.z; int tipx = x1; int tipy = y1; int tipz = z1; int dx = Math.Abs(x2 - x1); int dy = Math.Abs(y2 - y1); int dz = Math.Abs(z2 - z1); if (dx + dy + dz == 0) { affected.Add(pos2 + new Vector3Int(tipx, tipy, tipz)); notdrawn = false; } if (Math.Max(Math.Max(dx, dy), dz) == dx && notdrawn) { for (int domstep = 0; domstep <= dx; domstep++) { tipx = x1 + domstep * (x2 - x1 > 0 ? 1 : -1); tipy = (int)Math.Round(y1 + domstep * (((double)dy) / ((double)dx)) * (y2 - y1 > 0 ? 1 : -1)); tipz = (int)Math.Round(z1 + domstep * (((double)dz) / ((double)dx)) * (z2 - z1 > 0 ? 1 : -1)); affected.Add(new Vector3Int(tipx, tipy, tipz)); } notdrawn = false; } if (Math.Max(Math.Max(dx, dy), dz) == dy && notdrawn) { for (int domstep = 0; domstep <= dx; domstep++) { tipx = x1 + domstep * (x2 - x1 > 0 ? 1 : -1); tipy = (int)Math.Round(y1 + domstep * ((double)dy) / ((double)dx) * (y2 - y1 > 0 ? 1 : -1)); tipz = (int)Math.Round(z1 + domstep * ((double)dz) / ((double)dx) * (z2 - z1 > 0 ? 1 : -1)); affected.Add(new Vector3Int(tipx, tipy, tipz)); } notdrawn = false; } if (Math.Max(Math.Max(dx, dy), dz) == dz && notdrawn) { for (int domstep = 0; domstep <= dz; domstep++) { tipz = z1 + domstep * (z2 - z1 > 0 ? 1 : -1); tipy = (int)Math.Round(y1 + domstep * ((double)dy) / ((double)dz) * (y2 - y1 > 0 ? 1 : -1)); tipx = (int)Math.Round(x1 + domstep * ((double)dx) / ((double)dz) * (x2 - x1 > 0 ? 1 : -1)); affected.Add(pos2 + new Vector3Int(tipx, tipy, tipz)); } } return(affected); }
static public SkryptObject Max(SkryptObject[] Values) { var a = TypeConverter.ToNumeric(Values, 0); var b = TypeConverter.ToNumeric(Values, 1); return((Numeric)SysMath.Max(a, b)); }
private void ConfigureTransform(int requestWidth, int requestHeight) { var viewRect = new RectF(0, 0, requestHeight, requestWidth); var bufferRect = new RectF(0, 0, PixelSize.Height, PixelSize.Width); var centerX = viewRect.CenterX(); var centerY = viewRect.CenterY(); if ((int)SurfaceOrientation.Rotation90 == _rotation || (int)SurfaceOrientation.Rotation270 == _rotation) { Transform.TranslateX = centerX - bufferRect.CenterX(); Transform.TranslateY = centerY - bufferRect.CenterY(); var scale = Math.Max((float)requestWidth / PixelSize.Height, (float)requestHeight / PixelSize.Width); Transform.ScaleX = scale; Transform.ScaleY = scale; Transform.ScalePivotX = centerX; Transform.ScalePivotY = centerY; Transform.RotateDegrees = 90 * (_rotation - 2); Transform.RotatePivotX = centerX; Transform.RotatePivotY = centerY; } else if ((int)SurfaceOrientation.Rotation180 == _rotation) { Transform.RotateDegrees = 180; Transform.RotatePivotX = centerX; Transform.RotatePivotY = centerY; } }
protected override void KeyboardWillShow(object sender, UIKeyboardEventArgs e) { // this bit of code depends on the knowledge of the component tree: // - description label is inside of a container view which is placed in a stack view // - we want to know the vertical location of the container view in the whole view // - we actually want to know the Y coordinate of the bottom of the container and make // sure we don't overaly it with the keyboard var container = DescriptionTextView.Superview; var absoluteLocation = View.ConvertPointFromView(container.Frame.Location, container.Superview); var minimumVisibleContentHeight = View.Frame.Height - absoluteLocation.Y - container.Frame.Height; var coveredByKeyboard = e.FrameEnd.Height - minimumVisibleContentHeight; if (coveredByKeyboard < 0) { return; } var safeAreaOffset = UIDevice.CurrentDevice.CheckSystemVersion(11, 0) ? Math.Max(UIApplication.SharedApplication.KeyWindow.SafeAreaInsets.Top, UIApplication.SharedApplication.StatusBarFrame.Height) : 0; var distanceFromTop = Math.Max(safeAreaOffset, View.Frame.Y - coveredByKeyboard); View.Frame = new CGRect(View.Frame.X, distanceFromTop, View.Frame.Width, View.Frame.Height); UIView.Animate(Animation.Timings.EnterTiming, View.LayoutIfNeeded); }
/// <summary> /// Handle a 503 Service Unavailable status by processing the Retry-After header. /// </summary> /// <param name="state"> /// The state. /// </param> /// <param name="response"> /// The response. /// </param> private static void HandleServiceUnavailable(State state, HttpWebResponse response) { string header = response.GetResponseHeader("Retry-After"); Debug.WriteLine("DownloadThread : got HTTP response code 503 (retry after {0})", header); state.CountRetry = true; int retryAfter; int.TryParse(header, out retryAfter); state.RetryAfter = Math.Max(retryAfter, 0); if (state.RetryAfter < DownloaderService.MinimumRetryAfter) { state.RetryAfter = DownloaderService.MinimumRetryAfter; } else if (state.RetryAfter > DownloaderService.MaxRetryAfter) { state.RetryAfter = DownloaderService.MaxRetryAfter; } state.RetryAfter += Helpers.Random.Next(DownloaderService.MinimumRetryAfter + 1); state.RetryAfter *= 1000; throw new StopRequestException( ExpansionDownloadStatus.WaitingToRetry, "got 503 Service Unavailable, will retry later"); }
/// <summary> /// Constructs a <see cref="Xenon.Math.BoundingSphere"/> that is the as large as the total combined area of the two specified spheres. /// </summary> /// <param name="value1">The first sphere to merge.</param> /// <param name="value2">The second sphere to merge.</param> /// <param name="result">When the method completes, contains the newly constructed bounding sphere.</param> public static void Merge(ref BoundingSphere value1, ref BoundingSphere value2, out BoundingSphere result) { Vector3 difference = value2.Center - value1.Center; float length = difference.Length; float radius = value1.Radius; float radius2 = value2.Radius; if (radius + radius2 >= length) { if (radius - radius2 >= length) { result = value1; return; } if (radius2 - radius >= length) { result = value2; return; } } Vector3 vector = difference * (1.0f / length); float min = SMath.Min(-radius, length - radius2); float max = (SMath.Max(radius, length + radius2) - min) * 0.5f; result.Center = value1.Center + vector * (max + min); result.Radius = max; }
public void Insert(T quadObject) { lock (syncLock) { if (sort & !objectSortOrder.ContainsKey(quadObject)) { objectSortOrder.Add(quadObject, objectSortId++); } Box2 bounds = quadObject.GetBBox(); if (root == null) { var rootSize = new Vector2( SysMath.Ceiling(bounds.Width / minLeafSize.X), SysMath.Ceiling(bounds.Height / minLeafSize.Y)); double mul = SysMath.Max(rootSize.X, rootSize.Y); rootSize = new Vector2(minLeafSize.X, minLeafSize.Y) * mul; var center = bounds.Min + new Vector2(bounds.Width, bounds.Height) / 2; var rootOrigin = center - rootSize / 2; root = new QuadNode(new Box2(rootOrigin, rootOrigin + rootSize)); } while (!root.BBox.Contains(bounds)) { ExpandRoot(bounds); } InsertNodeObject(root, quadObject); } }
public ParticleSquare(float x, float y, float mx, float my, int maxAge, float size) : base(x, y, mx, my, maxAge, size) { var mult = Math.Max(Math.Min(32 / size, 4), 1); Mx *= mult; My *= mult; }
/// <summary> /// Implements the - operator. /// </summary> /// <param name="point1">The point1.</param> /// <param name="point2">The point2.</param> /// <returns>The result of the operator.</returns> public static CartesianOffset3D operator -(CartesianCoordinate3D point1, CartesianCoordinate3D point2) { return(new CartesianOffset3D( point1, point2, NMath.Max(point1.Tolerance, point2.Tolerance))); }
static void Main(string[] args) { Chart chart = new Chart("Vector Triad", "Memory [Bytes]", "Throughput", true); Warmup(); int threads = 4; { long maxLength = (1 << 28) / sizeof(double); for (long n = 1 << 1; n <= maxLength; n += Math.Max(1, n)) { long r = maxLength / n; double elapsedMilliseconds = RunVectorTriad(n, r, threads); double gigabytePerSecond = n * sizeof(double) * 4 * threads / (elapsedMilliseconds / 1000.0) / (1 << 30); double mflops = n * 2 * threads / (elapsedMilliseconds / 1000.0) / (1 << 20); Console.WriteLine( $"{n} ({r}): {elapsedMilliseconds:F2}ms/Iteration, {gigabytePerSecond:F2}GB/s, {mflops:F2}MFLOPS"); chart.Add($"Throughput [GB/s]", n * sizeof(double) * 4 * threads, gigabytePerSecond); } } chart.Save(typeof(VectorTriad)); chart.Show(); Console.WriteLine("Finished..." + (accumulator == 0 ? " " : "")); Console.Read(); }
/// <summary> /// Implements the + operator. /// </summary> /// <param name="offset1">The offset1.</param> /// <param name="point2">The point2.</param> /// <returns>The result of the operator.</returns> public static SphericalCoordinate operator +(SphericalOffset offset1, SphericalCoordinate point2) { return(new SphericalCoordinate( offset1.Radius() + point2.Radius, offset1.Azimuth() + point2.Azimuth, NMath.Max(offset1.Tolerance, point2.Tolerance))); }
/// <summary> /// Configures the necessary transformation to autoFitTextureView. /// This method should be called after the camera preciew size is determined in openCamera, and also the size of /// autoFitTextureView is fixed /// </summary> /// <param name="viewWidth">The width of autoFitTextureView</param> /// <param name="viewHeight">VThe height of autoFitTextureView</param> private void ConfigureTransform(int viewWidth, int viewHeight) { Activity activity = this.Activity; if (this.autoFitTextureView == null || this.previewSize == null || activity == null) { this.tracer.Debug("ConfigureTransform: Could not perform transformation."); return; } SurfaceOrientation rotation = activity.WindowManager.DefaultDisplay.Rotation; Matrix matrix = new Matrix(); RectF viewRect = new RectF(0, 0, viewWidth, viewHeight); RectF bufferRect = new RectF(0, 0, this.previewSize.Width, this.previewSize.Height); float centerX = viewRect.CenterX(); float centerY = viewRect.CenterY(); if (rotation == SurfaceOrientation.Rotation90 || rotation == SurfaceOrientation.Rotation270) { bufferRect.Offset(centerX - bufferRect.CenterX(), centerY - bufferRect.CenterY()); matrix.SetRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.Fill); float verticalScale = (float)viewHeight / this.previewSize.Height; float horizontalScale = (float)viewWidth / this.previewSize.Width; float scale = Math.Max(verticalScale, horizontalScale); matrix.PostScale(scale, scale, centerX, centerY); matrix.PostRotate(90 * ((int)rotation - 2), centerX, centerY); } this.autoFitTextureView.SetTransform(matrix); }
public static List <Vector3Int> MakeWalls(WorldEdit.AreaSelection area, int border = 1) { List <Vector3Int> affected = new List <Vector3Int>(); int minX = Math.Min(area.posA.x, area.posB.x); int maxX = Math.Max(area.posA.x, area.posB.x); int minZ = Math.Min(area.posA.z, area.posB.z); int maxZ = Math.Max(area.posA.z, area.posB.z); Vector3Int relative; for (int x = area.cornerB.x; x >= area.cornerA.x; x--) { for (int y = area.cornerB.y; y >= area.cornerA.y; y--) { for (int z = area.cornerB.z; z >= area.cornerA.z; z--) { relative = new Vector3Int(x, y, z); if (relative.x > (maxX - border) || relative.x < (minX + border) || relative.z > (maxZ - border) || relative.z < (minZ + border)) { affected.Add(relative); } } } } return(affected); }
/// <summary> /// Implements the - operator. /// </summary> /// <param name="point1">The point1.</param> /// <param name="offset2">The offset2.</param> /// <returns>The result of the operator.</returns> public static PolarCoordinate operator -(PolarCoordinate point1, PolarOffset offset2) { return(new PolarCoordinate( point1.Radius - offset2.Radius(), point1.Azimuth - offset2.Azimuth(), NMath.Max(point1.Tolerance, offset2.Tolerance))); }
protected override void OnSizeChanged(int w, int h, int oldw, int oldh) { base.OnSizeChanged(w, h, oldw, oldh); int thumbWidth = mThumb.IntrinsicWidth; int thumbHeight = mThumb.IntrinsicHeight; int addedThumb = mAddedTouchBounds; int halfThumb = thumbWidth / 2; int paddingLeft = PaddingLeft + addedThumb; int paddingRight = PaddingRight; int bottom = Height - PaddingBottom - addedThumb; mThumb.SetBounds(paddingLeft, bottom - thumbHeight, paddingLeft + thumbWidth, bottom); int trackHeight = Math.Max(mTrackHeight / 2, 1); mTrack.SetBounds(paddingLeft + halfThumb, bottom - halfThumb - trackHeight, Width - halfThumb - paddingRight - addedThumb, bottom - halfThumb + trackHeight); int scrubberHeight = Math.Max(mScrubberHeight / 2, 2); mScrubber.SetBounds(paddingLeft + halfThumb, bottom - halfThumb - scrubberHeight, paddingLeft + halfThumb, bottom - halfThumb + scrubberHeight); //Update the thumb position after size changed UpdateThumbPosFromCurrentProgress(); }
/// <summary> /// Implements the + operator. /// </summary> /// <param name="offset1">The offset1.</param> /// <param name="point2">The point2.</param> /// <returns>The result of the operator.</returns> public static PolarCoordinate operator +(PolarOffset offset1, PolarCoordinate point2) { return(new PolarCoordinate( offset1.Radius() + point2.Radius, offset1.Azimuth() + point2.Azimuth, NMath.Max(offset1.Tolerance, point2.Tolerance))); }
public static void SetHeight(float[,] heightMap, Vector2 pos, float height) { int x = Math.Max(Math.Min((int)pos.X, heightMap.GetLength(0) - 1), 0); int y = Math.Max(Math.Min((int)pos.Y, heightMap.GetLength(1) - 1), 0); heightMap[x, y] = height; }
/// <summary> /// Implements the - operator. /// </summary> /// <param name="offset1">The offset1.</param> /// <param name="offset2">The offset2.</param> /// <returns>The result of the operator.</returns> public static CartesianOffset3D operator -(CartesianOffset3D offset1, CartesianOffset3D offset2) { return(new CartesianOffset3D( new CartesianCoordinate3D(), offset1.ToCartesianCoordinate3D() - offset2, NMath.Max(offset1.Tolerance, offset2.Tolerance))); }
public static float GetValue(MapData[,] map, Vector2 pos, ScalarFieldType value) { int x = Math.Max(Math.Min((int)pos.X, map.GetLength(0) - 1), 0); int y = Math.Max(Math.Min((int)pos.Y, map.GetLength(1) - 1), 0); return(map[x, y].GetValue(value)); }
///<summary> ///</summary> ///<param name="optionType"></param> ///<param name="price"></param> ///<param name="strike"></param> ///<returns></returns> ///<exception cref="ArgumentOutOfRangeException"></exception> public static double ExercisePayoff(Type optionType, double price, double strike) { switch (optionType) { case Type.Call: { return(Math.Max(price - strike, 0.0)); } case Type.Put: { return(Math.Max(strike - price, 0.0)); } case Type.Straddle: { return(Math.Abs(strike - price)); } default: { throw new ArgumentOutOfRangeException(nameof(optionType), optionType, "TODO: Unknown option type"); } } }
public static void AddValue(MapData[,] map, Vector2 pos, ScalarFieldType value, float amount) { int x = Math.Max(Math.Min((int)pos.X, map.GetLength(0) - 1), 0); int y = Math.Max(Math.Min((int)pos.Y, map.GetLength(1) - 1), 0); map[x, y].SetValue(value, map[x, y].GetValue(value) + amount); }
public override bool Build(ref CodeNode _this, int expressionDepth, Dictionary <string, VariableDescriptor> variables, CodeContext codeContext, InternalCompilerMessageCallback message, FunctionInfo stats, Options opts) { Parser.Build(ref _variable, 2, variables, codeContext | CodeContext.InExpression, message, stats, opts); Parser.Build(ref _source, 2, variables, codeContext | CodeContext.InExpression, message, stats, opts); Parser.Build(ref _body, Math.Max(1, expressionDepth), variables, codeContext | CodeContext.Conditional | CodeContext.InLoop, message, stats, opts); if (_variable is Comma) { if ((_variable as Comma).RightOperand != null) { throw new InvalidOperationException("Invalid left-hand side in for-of"); } _variable = (_variable as Comma).LeftOperand; } if (message != null && (_source is ObjectDefinition || _source is ArrayDefinition || _source is Constant)) { message(MessageLevel.Recomendation, Position, Length, "for-of with constant source. This solution has a performance penalty. Rewrite without using for..in."); } return(false); }
/// <summary> /// Shows the audio toolbar. /// </summary> /// <returns>true if the toolbar has been revealed, false otherwise.</returns> private bool ShowAudioToolbar() { revealView.Visibility = ViewStates.Visible; isAudioToolbarHidden = false; return(true); // check only if mRevealView != null. If isAudioToolbarHidden == true is also checked, // the toolbar cannot be displayed on savedInstanceState if (revealView != null) { var cx = revealView.Left + revealView.Right; var cy = revealView.Top; var radius = Math.Max(revealView.Width, revealView.Height); if (Build.VERSION.SdkInt < BuildVersionCodes.Lollipop) { var animator = ViewAnimationUtils.CreateCircularReveal(revealView, cx, cy, 0, radius); animator.SetInterpolator(new AccelerateDecelerateInterpolator()); animator.SetDuration(800); revealView.Visibility = ViewStates.Invisible; animator.Start(); } var anim = ViewAnimationUtils .CreateCircularReveal(revealView, cx, cy, 0, radius); revealView.Visibility = ViewStates.Visible; anim.Start(); isAudioToolbarHidden = false; return(true); } return(false); }
public void UpdateBarometer(float pressure) { if (_ledRainbowStrip == null) { return; } int[] clearColors = new int[_rainbow.Length]; float t = (pressure - BarometerRangeLow) / (BarometerRangeHigh - BarometerRangeLow); int n = (int)Math.Ceiling(_rainbow.Length * t); n = Math.Max(0, Math.Min(n, _rainbow.Length)); int[] colors = new int[_rainbow.Length]; for (int i = 0; i < n; i++) { int ri = _rainbow.Length - 1 - i; colors[ri] = _rainbow[ri]; } try { _ledRainbowStrip.Write(clearColors); _ledRainbowStrip.Write(colors); } catch (Exception e) { System.Console.WriteLine(e); } }