finished the changelog and fixed some blunders
This commit is contained in:
parent
1517f317e7
commit
89d52381ab
35
Changelog.md
35
Changelog.md
@ -11,9 +11,42 @@ Here's the full changelog:
|
||||
+ Q_rsqrt
|
||||
* Mathematics
|
||||
* Geometry
|
||||
* Line
|
||||
= Replaced all references to `Vert` with references to `Float3`
|
||||
* Polygon
|
||||
= Replaced all references to `Vert` with references to `Float3`
|
||||
* Quadrilateral
|
||||
= Replaced all references to `Vert` with references to `Float3`
|
||||
* Sphere
|
||||
= Replaced all references to `Vert` with references to `Float3`
|
||||
* Triangle
|
||||
= Replaced all references to `Vert` with references to `Float3`
|
||||
= Renamed `Box2D` to `Box2d`
|
||||
= Replaced all references to `Vert` with references to `Float3`
|
||||
= Renamed `Box3D` to `Box3d`
|
||||
= Replaced all references to `Vert` with references to `Float3`
|
||||
- Vert
|
||||
* NumberSystems
|
||||
* Complex
|
||||
= Replaced all references to `Vert` with references to `Float3`
|
||||
* Quaternion
|
||||
= Replaced all references to `Vert` with references to `Float3`
|
||||
* Float2
|
||||
- operator Float2(Vert)
|
||||
= Replaced all references to `Vert` with references to `Float3`
|
||||
* Float3
|
||||
= Replaced all references to `Vert` with references to `Float3`
|
||||
* Float4
|
||||
= Replaced all references to `Vert` with references to `Float3`
|
||||
* Int2
|
||||
= Replaced all references to `Vert` with references to `Float3`
|
||||
* Int3
|
||||
= Replaced all references to `Vert` with references to `Float3`
|
||||
* Int4
|
||||
= Replaced all references to `Vert` with references to `Float3`
|
||||
* Vector2d
|
||||
= Replaced all references to `Vert` with references to `Float3`
|
||||
* Vector3d
|
||||
= Replaced all references to `Vert` with references to `Float3`
|
||||
* Mathf
|
||||
= Modified `InverseSqrt(float)` to use the faster unsafe inverse square root method.
|
||||
```
|
||||
|
||||
@ -6,7 +6,7 @@ public record class Box2d : IAbsolute<Box2d>, IAverage<Box2d>, ICeiling<Box2d>,
|
||||
{
|
||||
public static Box2d Unit => new(Float3.Zero, Float2.One);
|
||||
|
||||
public Float3 MaxFloat3
|
||||
public Float3 MaxVert
|
||||
{
|
||||
get => center + (size / 2);
|
||||
set
|
||||
@ -15,7 +15,7 @@ public record class Box2d : IAbsolute<Box2d>, IAverage<Box2d>, ICeiling<Box2d>,
|
||||
size = (Float2)diff * 2f;
|
||||
}
|
||||
}
|
||||
public Float3 MinFloat3
|
||||
public Float3 MinVert
|
||||
{
|
||||
get => center - (size / 2);
|
||||
set
|
||||
|
||||
@ -8,7 +8,7 @@ public record class Box3d : IAbsolute<Box3d>, IAverage<Box3d>, ICeiling<Box3d>,
|
||||
{
|
||||
public static Box3d Unit => new(Float3.Zero, Float3.One);
|
||||
|
||||
public Float3 MaxFloat3
|
||||
public Float3 MaxVert
|
||||
{
|
||||
get => center + (size / 2);
|
||||
set
|
||||
@ -17,7 +17,7 @@ public record class Box3d : IAbsolute<Box3d>, IAverage<Box3d>, ICeiling<Box3d>,
|
||||
size = diff * 2;
|
||||
}
|
||||
}
|
||||
public Float3 MinFloat3
|
||||
public Float3 MinVert
|
||||
{
|
||||
get => center - (size / 2);
|
||||
set
|
||||
|
||||
@ -9,11 +9,11 @@ public struct Polygon : ICloneable, IEquatable<Polygon>, IGroup<Float3>, ISubdiv
|
||||
set
|
||||
{
|
||||
p_lines = value;
|
||||
p_verts = GenerateFloat3s(value);
|
||||
p_verts = GenerateVerts(value);
|
||||
}
|
||||
}
|
||||
public Float3 Midpoint => Float3.Average(Float3s);
|
||||
public Float3[] Float3s
|
||||
public Float3 Midpoint => Float3.Average(Verts);
|
||||
public Float3[] Verts
|
||||
{
|
||||
get => p_verts;
|
||||
set
|
||||
@ -97,13 +97,13 @@ public struct Polygon : ICloneable, IEquatable<Polygon>, IGroup<Float3>, ISubdiv
|
||||
public Polygon(params Line[] lines)
|
||||
{
|
||||
p_lines = lines;
|
||||
p_verts = GenerateFloat3s(lines);
|
||||
p_verts = GenerateVerts(lines);
|
||||
}
|
||||
|
||||
public Float3 this[int index]
|
||||
{
|
||||
get => Float3s[index];
|
||||
set => Float3s[index] = value;
|
||||
get => Verts[index];
|
||||
set => Verts[index] = value;
|
||||
}
|
||||
|
||||
public static Polygon CreateCircle(int vertCount)
|
||||
@ -119,13 +119,13 @@ public struct Polygon : ICloneable, IEquatable<Polygon>, IGroup<Float3>, ISubdiv
|
||||
|
||||
public static Polygon Absolute(Polygon val)
|
||||
{
|
||||
Float3[] v = val.Float3s;
|
||||
Float3[] v = val.Verts;
|
||||
for (int i = 0; i < v.Length; i++) v[i] = Float3.Absolute(v[i]);
|
||||
return new(v);
|
||||
}
|
||||
public static Polygon Average(params Polygon[] vals)
|
||||
{
|
||||
if (!CheckFloat3s(vals)) throw new DifferingVertCountException(nameof(vals), vals);
|
||||
if (!CheckVerts(vals)) throw new DifferingVertCountException(nameof(vals), vals);
|
||||
if (vals.Length < 1) return default;
|
||||
|
||||
Line[][] lines = new Line[vals.Length][];
|
||||
@ -143,13 +143,13 @@ public struct Polygon : ICloneable, IEquatable<Polygon>, IGroup<Float3>, ISubdiv
|
||||
}
|
||||
public static Polygon Ceiling(Polygon val)
|
||||
{
|
||||
Float3[] v = val.Float3s;
|
||||
Float3[] v = val.Verts;
|
||||
for (int i = 0; i < v.Length; i++) v[i] = Float3.Ceiling(v[i]);
|
||||
return new(v);
|
||||
}
|
||||
public static Polygon Clamp(Polygon val, Polygon min, Polygon max)
|
||||
{
|
||||
if (!CheckFloat3s(val, min, max)) throw new DifferingVertCountException(val, min, max);
|
||||
if (!CheckVerts(val, min, max)) throw new DifferingVertCountException(val, min, max);
|
||||
Line[][] lines = new Line[3][] { val.Lines, min.Lines, max.Lines };
|
||||
Line[] res = new Line[val.Lines.Length];
|
||||
for (int i = 0; i < res.Length; i++) res[i] = Line.Clamp(lines[0][i], lines[1][i], lines[2][i]);
|
||||
@ -157,13 +157,13 @@ public struct Polygon : ICloneable, IEquatable<Polygon>, IGroup<Float3>, ISubdiv
|
||||
}
|
||||
public static Polygon Floor(Polygon val)
|
||||
{
|
||||
Float3[] v = val.Float3s;
|
||||
Float3[] v = val.Verts;
|
||||
for (int i = 0; i < v.Length; i++) v[i] = Float3.Floor(v[i]);
|
||||
return new(v);
|
||||
}
|
||||
public static Polygon Lerp(Polygon a, Polygon b, float t, bool clamp = true)
|
||||
{
|
||||
if (!CheckFloat3s(a, b)) throw new DifferingVertCountException(a, b);
|
||||
if (!CheckVerts(a, b)) throw new DifferingVertCountException(a, b);
|
||||
Line[][] lines = new Line[2][] { a.Lines, b.Lines };
|
||||
Line[] res = new Line[a.Lines.Length];
|
||||
for (int i = 0; i < res.Length; i++) res[i] = Line.Lerp(lines[0][i], lines[1][i], t, clamp);
|
||||
@ -171,7 +171,7 @@ public struct Polygon : ICloneable, IEquatable<Polygon>, IGroup<Float3>, ISubdiv
|
||||
}
|
||||
public static Polygon Median(params Polygon[] vals)
|
||||
{
|
||||
if (!CheckFloat3s(vals)) throw new DifferingVertCountException(nameof(vals), vals);
|
||||
if (!CheckVerts(vals)) throw new DifferingVertCountException(nameof(vals), vals);
|
||||
if (vals.Length < 1) return default;
|
||||
|
||||
Line[][] lines = new Line[vals.Length][];
|
||||
@ -203,7 +203,7 @@ public struct Polygon : ICloneable, IEquatable<Polygon>, IGroup<Float3>, ISubdiv
|
||||
}
|
||||
public bool Equals(Polygon other)
|
||||
{
|
||||
if (!CheckFloat3s(this, other)) return false;
|
||||
if (!CheckVerts(this, other)) return false;
|
||||
return Lines == other.Lines;
|
||||
}
|
||||
public override int GetHashCode() => Lines.GetHashCode();
|
||||
@ -217,25 +217,25 @@ public struct Polygon : ICloneable, IEquatable<Polygon>, IGroup<Float3>, ISubdiv
|
||||
public object Clone() => new Polygon(Lines);
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
|
||||
public IEnumerator<Float3> GetEnumerator() { foreach (Float3 v in Float3s) yield return v; }
|
||||
public IEnumerator<Float3> GetEnumerator() { foreach (Float3 v in Verts) yield return v; }
|
||||
|
||||
public Float3[] ToArray() => Float3s;
|
||||
public Float3[] ToArray() => Verts;
|
||||
public Fill<Float3> ToFill()
|
||||
{
|
||||
Polygon @this = this;
|
||||
return i => @this[i];
|
||||
}
|
||||
public List<Float3> ToList() => new(Float3s);
|
||||
public List<Float3> ToList() => new(Verts);
|
||||
|
||||
public float[] ToFloatArray()
|
||||
{
|
||||
float[] vals = new float[Float3s.Length * 3];
|
||||
for (int i = 0; i < Float3s.Length; i++)
|
||||
float[] vals = new float[Verts.Length * 3];
|
||||
for (int i = 0; i < Verts.Length; i++)
|
||||
{
|
||||
int pos = i * 3;
|
||||
vals[pos + 0] = Float3s[i].x;
|
||||
vals[pos + 1] = Float3s[i].y;
|
||||
vals[pos + 2] = Float3s[i].z;
|
||||
vals[pos + 0] = Verts[i].x;
|
||||
vals[pos + 1] = Verts[i].y;
|
||||
vals[pos + 2] = Verts[i].z;
|
||||
}
|
||||
return vals;
|
||||
}
|
||||
@ -259,32 +259,32 @@ public struct Polygon : ICloneable, IEquatable<Polygon>, IGroup<Float3>, ISubdiv
|
||||
public Polygon SubdivideCatmullClark(int segments)
|
||||
{
|
||||
// Thanks Saalty for making this accidentally.
|
||||
List<Float3> newFloat3s = new();
|
||||
for (int i = 0; i < Float3s.Length; i++)
|
||||
List<Float3> newVerts = new();
|
||||
for (int i = 0; i < Verts.Length; i++)
|
||||
{
|
||||
for (int factor = 0; factor < segments; factor++)
|
||||
{
|
||||
float unit = factor / (float)(segments * 2), unit2 = unit + 0.5f, lastUnit = unit * 2;
|
||||
Float3 p1, p2;
|
||||
if (i == Float3s.Length - 1)
|
||||
if (i == Verts.Length - 1)
|
||||
{
|
||||
p1 = Float3s[^1] + (Float3s[0] - Float3s[^1]) * unit2;
|
||||
p2 = Float3s[0] + (Float3s[1] - Float3s[0]) * unit;
|
||||
p1 = Verts[^1] + (Verts[0] - Verts[^1]) * unit2;
|
||||
p2 = Verts[0] + (Verts[1] - Verts[0]) * unit;
|
||||
}
|
||||
else if (i == Float3s.Length - 2)
|
||||
else if (i == Verts.Length - 2)
|
||||
{
|
||||
p1 = Float3s[^2] + (Float3s[^1] - Float3s[^2]) * unit2;
|
||||
p2 = Float3s[^1] + (Float3s[0] - Float3s[^1]) * unit;
|
||||
p1 = Verts[^2] + (Verts[^1] - Verts[^2]) * unit2;
|
||||
p2 = Verts[^1] + (Verts[0] - Verts[^1]) * unit;
|
||||
}
|
||||
else
|
||||
{
|
||||
p1 = Float3s[i] + (Float3s[i + 1] - Float3s[i]) * unit2;
|
||||
p2 = Float3s[i + 1] + (Float3s[i + 2] - Float3s[i + 1]) * unit;
|
||||
p1 = Verts[i] + (Verts[i + 1] - Verts[i]) * unit2;
|
||||
p2 = Verts[i + 1] + (Verts[i + 2] - Verts[i + 1]) * unit;
|
||||
}
|
||||
newFloat3s.Add(p1 + (p2 - p1) * lastUnit);
|
||||
newVerts.Add(p1 + (p2 - p1) * lastUnit);
|
||||
}
|
||||
}
|
||||
return new(newFloat3s.ToArray());
|
||||
return new(newVerts.ToArray());
|
||||
}
|
||||
|
||||
[Obsolete("This method doesn't work very well, and will give very weird results in certain cases. " +
|
||||
@ -294,15 +294,15 @@ public struct Polygon : ICloneable, IEquatable<Polygon>, IGroup<Float3>, ISubdiv
|
||||
// This may cause issues. FIXME
|
||||
// Tbh, not even sure if this works. This was a bit confusing.
|
||||
|
||||
if (Float3s.Length == 3) return new Triangle[] { new(Float3s[0], Float3s[1], Float3s[2]) };
|
||||
if (Verts.Length == 3) return new Triangle[] { new(Verts[0], Verts[1], Verts[2]) };
|
||||
|
||||
(int posA, int posB, Line line)? closest = null;
|
||||
for (int i = 0; i < Float3s.Length; i++)
|
||||
for (int i = 0; i < Verts.Length; i++)
|
||||
{
|
||||
for (int j = 0; j < Float3s.Length; j++)
|
||||
for (int j = 0; j < Verts.Length; j++)
|
||||
{
|
||||
if (i == j) continue;
|
||||
Line l = new(Float3s[i], Float3s[j]);
|
||||
Line l = new(Verts[i], Verts[j]);
|
||||
if (Lines.Contains(l)) continue;
|
||||
|
||||
if (!closest.HasValue || closest.Value.line.Length > l.Length) closest = (i, j, l);
|
||||
@ -333,17 +333,17 @@ public struct Polygon : ICloneable, IEquatable<Polygon>, IGroup<Float3>, ISubdiv
|
||||
return tris.ToArray();
|
||||
}
|
||||
|
||||
private static bool CheckFloat3s(params Polygon[] polys)
|
||||
private static bool CheckVerts(params Polygon[] polys)
|
||||
{
|
||||
int len = -1;
|
||||
foreach (Polygon poly in polys)
|
||||
{
|
||||
if (len == -1)
|
||||
{
|
||||
len = poly.Float3s.Length;
|
||||
len = poly.Verts.Length;
|
||||
continue;
|
||||
}
|
||||
if (poly.Float3s.Length != len) return false;
|
||||
if (poly.Verts.Length != len) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -354,7 +354,7 @@ public struct Polygon : ICloneable, IEquatable<Polygon>, IGroup<Float3>, ISubdiv
|
||||
lines[i] = new(verts[i], verts[i == lines.Length - 1 ? 0 : i + 1]);
|
||||
return lines;
|
||||
}
|
||||
private static Float3[] GenerateFloat3s(Line[] lines)
|
||||
private static Float3[] GenerateVerts(Line[] lines)
|
||||
{
|
||||
Float3[] verts = new Float3[lines.Length];
|
||||
for (int i = 0; i < verts.Length; i++)
|
||||
@ -368,7 +368,7 @@ public struct Polygon : ICloneable, IEquatable<Polygon>, IGroup<Float3>, ISubdiv
|
||||
|
||||
public static Polygon operator +(Polygon a, Polygon b)
|
||||
{
|
||||
if (!CheckFloat3s(a, b)) throw new DifferingVertCountException(a, b);
|
||||
if (!CheckVerts(a, b)) throw new DifferingVertCountException(a, b);
|
||||
Line[][] lines = new Line[2][] { a.Lines, b.Lines };
|
||||
Line[] res = new Line[a.Lines.Length];
|
||||
for (int i = 0; i < res.Length; i++) res[i] = lines[0][i] + lines[1][i];
|
||||
@ -388,7 +388,7 @@ public struct Polygon : ICloneable, IEquatable<Polygon>, IGroup<Float3>, ISubdiv
|
||||
}
|
||||
public static Polygon operator -(Polygon a, Polygon b)
|
||||
{
|
||||
if (!CheckFloat3s(a, b)) throw new DifferingVertCountException(a, b);
|
||||
if (!CheckVerts(a, b)) throw new DifferingVertCountException(a, b);
|
||||
Line[][] lines = new Line[2][] { a.Lines, b.Lines };
|
||||
Line[] res = new Line[a.Lines.Length];
|
||||
for (int i = 0; i < res.Length; i++) res[i] = lines[0][i] - lines[1][i];
|
||||
@ -402,7 +402,7 @@ public struct Polygon : ICloneable, IEquatable<Polygon>, IGroup<Float3>, ISubdiv
|
||||
}
|
||||
public static Polygon operator *(Polygon a, Polygon b)
|
||||
{
|
||||
if (!CheckFloat3s(a, b)) throw new DifferingVertCountException(a, b);
|
||||
if (!CheckVerts(a, b)) throw new DifferingVertCountException(a, b);
|
||||
Line[][] lines = new Line[2][] { a.Lines, b.Lines };
|
||||
Line[] res = new Line[a.Lines.Length];
|
||||
for (int i = 0; i < res.Length; i++) res[i] = lines[0][i] * lines[1][i];
|
||||
@ -422,7 +422,7 @@ public struct Polygon : ICloneable, IEquatable<Polygon>, IGroup<Float3>, ISubdiv
|
||||
}
|
||||
public static Polygon operator /(Polygon a, Polygon b)
|
||||
{
|
||||
if (!CheckFloat3s(a, b)) throw new DifferingVertCountException(a, b);
|
||||
if (!CheckVerts(a, b)) throw new DifferingVertCountException(a, b);
|
||||
Line[][] lines = new Line[2][] { a.Lines, b.Lines };
|
||||
Line[] res = new Line[a.Lines.Length];
|
||||
for (int i = 0; i < res.Length; i++) res[i] = lines[0][i] / lines[1][i];
|
||||
|
||||
@ -208,7 +208,7 @@ public record class Quadrilateral : IAbsolute<Quadrilateral>, IAverage<Quadrilat
|
||||
new(Float3.Absolute(val.A), Float3.Absolute(val.B), Float3.Absolute(val.C), Float3.Absolute(val.D));
|
||||
public static Quadrilateral Average(params Quadrilateral[] vals)
|
||||
{
|
||||
(Float3[] As, Float3[] Bs, Float3[] Cs, Float3[] Ds) = SplitFloat3Array(vals);
|
||||
(Float3[] As, Float3[] Bs, Float3[] Cs, Float3[] Ds) = SplitVertArray(vals);
|
||||
return new(Float3.Average(As), Float3.Average(Bs), Float3.Average(Cs), Float3.Average(Ds));
|
||||
}
|
||||
public static Quadrilateral Ceiling(Quadrilateral val) =>
|
||||
@ -223,23 +223,23 @@ public record class Quadrilateral : IAbsolute<Quadrilateral>, IAverage<Quadrilat
|
||||
Float3.Lerp(a.D, b.D, t, clamp));
|
||||
public static Quadrilateral Max(params Quadrilateral[] vals)
|
||||
{
|
||||
(Float3[] As, Float3[] Bs, Float3[] Cs, Float3[] Ds) = SplitFloat3Array(vals);
|
||||
(Float3[] As, Float3[] Bs, Float3[] Cs, Float3[] Ds) = SplitVertArray(vals);
|
||||
return new(Float3.Max(As), Float3.Max(Bs), Float3.Max(Cs), Float3.Max(Ds));
|
||||
}
|
||||
public static Quadrilateral Median(params Quadrilateral[] vals)
|
||||
{
|
||||
(Float3[] As, Float3[] Bs, Float3[] Cs, Float3[] Ds) = SplitFloat3Array(vals);
|
||||
(Float3[] As, Float3[] Bs, Float3[] Cs, Float3[] Ds) = SplitVertArray(vals);
|
||||
return new(Float3.Median(As), Float3.Median(Bs), Float3.Median(Cs), Float3.Median(Ds));
|
||||
}
|
||||
public static Quadrilateral Min(params Quadrilateral[] vals)
|
||||
{
|
||||
(Float3[] As, Float3[] Bs, Float3[] Cs, Float3[] Ds) = SplitFloat3Array(vals);
|
||||
(Float3[] As, Float3[] Bs, Float3[] Cs, Float3[] Ds) = SplitVertArray(vals);
|
||||
return new(Float3.Min(As), Float3.Min(Bs), Float3.Min(Cs), Float3.Min(Ds));
|
||||
}
|
||||
public static Quadrilateral Round(Quadrilateral val) =>
|
||||
new(Float3.Round(val.A), Float3.Round(val.B), Float3.Round(val.C), Float3.Round(val.D));
|
||||
|
||||
public static (Float3[] As, Float3[] Bs, Float3[] Cs, Float3[] Ds) SplitFloat3Array(params Quadrilateral[] quads)
|
||||
public static (Float3[] As, Float3[] Bs, Float3[] Cs, Float3[] Ds) SplitVertArray(params Quadrilateral[] quads)
|
||||
{
|
||||
Float3[] a = new Float3[quads.Length], b = new Float3[quads.Length],
|
||||
c = new Float3[quads.Length], d = new Float3[quads.Length];
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user