public static int M8By8FloatOffset(this int lhs, double xOff, double yOff) { var typed = new _M8By8(lhs); var valueX = (typed.ValueX.M8ToDouble() + xOff).AsM8(); var valueY = (typed.ValueY.M8ToDouble() + yOff).AsM8(); return (valueX << Bits) + valueY; }
public static int[] ToCornersOnM8By8(this int index) { var typed = new _M8By8(index); var upLeft = new _M8By8((typed.ValueX - 1).AsM8(), (typed.ValueY - 1).AsM8()); var upRight = new _M8By8((typed.ValueX + 1).AsM8(), (typed.ValueY - 1).AsM8()); var lowLeft = new _M8By8((typed.ValueX - 1).AsM8(), (typed.ValueY + 1).AsM8()); var lowRight = new _M8By8((typed.ValueX + 1).AsM8(), (typed.ValueY + 1).AsM8()); return new[] { upLeft.Index, upRight.Index, lowLeft.Index, lowRight.Index }; }
public static int[] ToSidesOnM8By8(this int index) { var typed = new _M8By8(index); var top = new _M8By8(typed.ValueX, typed.ValueY - 1); var right = new _M8By8(typed.ValueX + 1, typed.ValueY); var bottom = new _M8By8(typed.ValueX, typed.ValueY + 1); var left = new _M8By8(typed.ValueX - 1, typed.ValueY); return new[] { top.Index, right.Index, bottom.Index, left.Index }; }
public static int[] ToPerimeterOnM8By8(this int index) { var typed = new _M8By8(index); var top = new _M8By8(typed.ValueX, typed.ValueY - 1); var right = new _M8By8(typed.ValueX + 1, typed.ValueY); var bottom = new _M8By8(typed.ValueX, typed.ValueY + 1); var left = new _M8By8(typed.ValueX - 1, typed.ValueY); var upLeft = new _M8By8((typed.ValueX - 1).AsM8(), (typed.ValueY - 1).AsM8()); var upRight = new _M8By8((typed.ValueX + 1).AsM8(), (typed.ValueY - 1).AsM8()); var lowLeft = new _M8By8((typed.ValueX - 1).AsM8(), (typed.ValueY + 1).AsM8()); var lowRight = new _M8By8((typed.ValueX + 1).AsM8(), (typed.ValueY + 1).AsM8()); return new[] { top.Index, right.Index, bottom.Index, left.Index, upLeft.Index, upRight.Index, lowLeft.Index, lowRight.Index }; }
static void MakeForceField() { forceField[0] = new[] { 0.0f, 0.0f, 0.0f }; for (var i = 1; i < Mod; i++) { var typed = new _M8By8(i); var distance = Math.Sqrt(typed.ValueX.M8ToDouble() * typed.ValueX.M8ToDouble() + typed.ValueY.M8ToDouble() * typed.ValueY.M8ToDouble()); forceField[i] = new[] { (float)distance, (float)(typed.ValueX.M8ToDouble() / distance), (float)(typed.ValueY.M8ToDouble() / distance) }; } }