internal static bool CirclesOverlap(ref fp2 aOrigin, ref fp aRadius, ref fp2 bOrigin, ref fp bRadius) { var radsum = aRadius.value + bRadius.value; return(DistanceSqr(ref aOrigin, ref bOrigin).value <= ((radsum * radsum) >> fixlut.PRECISION)); }
internal static fp Sqrt(fp num) { fp r; r.value = Sqrt_Raw(num.value); return(r); }
public static fp2 Y(fp y) { fp2 r; r.x.value = 0; r.y.value = y.value; return(r); }
internal static void ClampMagnitude(ref fp2 value, ref fp length) { if (SqrMagnitude(value).value <= ((length.value * length.value) >> fixlut.PRECISION)) { return; } value = Normalize(value) * length; }
internal static fp Max(fp a, fp b) { if (a.value > b.value) { return(a); } return(b); }
internal static fp Min(fp a, fp b) { if (a.value < b.value) { return(a); } return(b); }
internal static fp2 ClosestPointOnCicle(fp2 center, fp radius, fp2 point) { var v = fm.Normalize(point - center); v *= radius; v += center; return(v); }
// // internal static bool linecast_collider_fast(fix3 point0, fix3 point1, ref collider2 collider) { // fix3 intersection; // // switch (collider.type) { // case collider2_types.circle: return linecast_circle_fast_nopoint(ref point0, ref point1, ref collider.circle.center, ref collider.circle.radius); // case collider2_types.aabb: return linecast_aabb(new line { point0 = point0, point1 = point1 }, collider.aabb, out intersection); // case collider2_types.oobb: return linecast_oobb(new line { point0 = point0, point1 = point1 }, collider.oobb, out intersection); // } // // throw new NotImplementedException(collider.type.ToString()); // } // internal static bool linecast_circle_fast(ref fp2 point0, ref fp2 point1, ref fp2 circle_center, ref fp circle_radius, out fp2 point) { fp2 v; fp2 z; fp2 z_normalized; fp z_magnitude; v.x.value = point0.x.value - circle_center.x.value; v.y.value = point0.y.value - circle_center.y.value; z.x.value = point1.x.value - point0.x.value; z.y.value = point1.y.value - point0.y.value; z_normalized = z; z_magnitude = default(fp); Normalize(ref z_normalized, ref z_magnitude); var b = Dot(ref v, ref z_normalized).value; var c = Dot(ref v, ref v).value - ((circle_radius.value * circle_radius.value) >> fixlut.PRECISION); if (c > fp.RAW_ZERO && b > fp.RAW_ZERO) { goto MISS; } var d = ((b * b) >> fixlut.PRECISION) - c; if (d < fp.RAW_ZERO) { goto MISS; } var distance = -b - Sqrt_Raw(d); if (distance <= z_magnitude.value) { if (distance < fp.RAW_ZERO) { point = point0; } else { point = point0; point.x.value += ((z_normalized.x.value * distance) >> fixlut.PRECISION); point.y.value += ((z_normalized.y.value * distance) >> fixlut.PRECISION); } return(true); } MISS: point = fp2.zero; return(false); }
public static fp2 X(fp x) { fp2 r; r.x.value = x.value; r.y.value = 0; return(r); }
internal static int RoundToInt(fp num) { var fraction = Fractions(num); if (fraction.value >= fp.half.value) { return(num.as_int_int + 1); } return(num.as_int_int); }
internal static fp Ceil(fp num) { var fractions = Fractions(num); if (fractions.value == 0) { return(num); } return(num + fp.one); }
public static fp Cos(fp num) { var sign = fp.one; if (num > fp.pi || num < -fp.pi) { sign = fp.minus_one; } return(fm.Cos(num) * sign); }
internal static fp2 Reflect(fp2 vector, fp2 normal) { fp dot = (vector.x * normal.x) + (vector.y * normal.y); fp2 result; result.x = vector.x - ((fp.two * dot) * normal.x); result.y = vector.y - ((fp.two * dot) * normal.y); return(result); }
public static fp SqrtAprox(fp num) { var sign = fp.one; if (num < fp.zero) { sign = fp.minus_one; num *= fp.minus_one; } return(fm.SqrtAprox(num) * sign); }
internal static fp2 Rotate(fp2 vector, fp rotation) { var cs = fixmath.Cos(rotation); var sn = fixmath.Sin(rotation); var px = (vector.x * cs) - (vector.y * sn); var pz = (vector.x * sn) + (vector.y * cs); vector.x = px; vector.y = pz; return(vector); }
internal static void Normalize(ref fp2 v, ref fp m) { m = Magnitude(v); if (m.value <= fp.epsilon.value) { v = default(fp2); return; } v.x.value = ((v.x.value << fixlut.PRECISION) / m.value); v.y.value = ((v.y.value << fixlut.PRECISION) / m.value); }
internal static fp Clamp(fp num, fp min, fp max) { if (num.value < min.value) { return(min); } if (num.value > max.value) { return(max); } return(num); }
public static fp Asin(fp num) { return(fm.Asin(num)); }
internal static fp Clamp01(fp num) { return(Clamp(num, fp.zero, fp.one)); }
internal static fp2 Lerp(fp2 from, fp2 to, fp t) { t = Clamp01(t); return(new fp2(from.x + (to.x - from.x) * t, from.y + (to.y - from.y) * t)); }
internal static void Normalize(ref fp2 v) { fp m = default(fp); Normalize(ref v, ref m); }
internal static fp Abs(fp num) { return(new fp(Math.Abs(num.value))); }
internal static fp Lerp(fp from, fp to, fp t) { return(from + ((to - from) * Clamp01(t))); }
public static fp Ceil(fp num) { return(fm.Ceil(num)); }
public static fp Sqrt(fp num) { return(fm.Sqrt(num)); }
internal static fp Sign(fp num) { return((num.value < fp.RAW_ZERO) ? fp.minus_one : fp.one); }
public static fp Floor(fp num) { return(fm.Floor(num)); }
public static fp Atan(fp num) { return(fm.Atan(num)); }
public static fp Fractions(fp num) { return(fm.Fractions(num)); }
internal static fp2 ClampMagnitude(fp2 value, fp length) { ClampMagnitude(ref value, ref length); return(value); }