-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtil.cs
More file actions
30 lines (27 loc) · 1.06 KB
/
Copy pathUtil.cs
File metadata and controls
30 lines (27 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
using System;
using System.Collections.Generic;
using System.Linq;
using SDL2;
namespace Spacerunner3
{
public static class Util
{
public static Random rand = new Random();
public static void CheckSdl(this int retval)
{
if (retval != 0)
{
throw new Exception("SDL call failure: returned (" + retval + "): " + SDL.SDL_GetError());
}
}
public static Vector2 MyVec(this Microsoft.Xna.Framework.Vector2 vec) => new Vector2(vec.X, vec.Y);
public static IEnumerable<double> RoundRange(double start, double end, int count)
{
var step = (end - start) / count;
var stepFixed = Math.Pow(2, Math.Round(Math.Log(step, 2)));
//Console.WriteLine(stepFixed + " " + Math.Round(Math.Log(step, 2)) + " " + Math.Log(step, 2) + " " + step);
var startFixed = Math.Floor(start / stepFixed) * stepFixed;
return Enumerable.Range(0, int.MaxValue).Select(i => stepFixed * i + startFixed).TakeWhile(v => v < end);
}
}
}