From 63631632fee7114fcef0e6b92e931f4357ad5a96 Mon Sep 17 00:00:00 2001 From: That_One_Nerd Date: Thu, 24 Aug 2023 07:59:07 -0400 Subject: [PATCH] Some improvements to the line and a bunch of changelog additions. --- Changelog.md | 96 ++++++++++++++++++++++++++- Nerd_STF/Mathematics/Geometry/Line.cs | 25 +++++-- 2 files changed, 113 insertions(+), 8 deletions(-) diff --git a/Changelog.md b/Changelog.md index 8ba4209..ff896fc 100644 --- a/Changelog.md +++ b/Changelog.md @@ -21,10 +21,102 @@ Here's the full changelog: - Polygon - Quadrilateral - Sphere - - Triangle - Vert + = Rewrote all of `Triangle` + TODO: Compare me to the original triangle and note changes. = Rewrote all of `Line` - TODO: Compare me to the original line and note changes. + + : IFromTuple + + : IIndexAll + + : IIndexRangeAll + + : ISplittable + + IWithinRange + + Slope + + Line() + + ToFloatArrayAll(params Line[]) + + WithinRange(Float3, float) + + WithinRange(Float3, float, float) + + operator +(Line, Float3) + + operator -(Line, Float3) + + operator *(Line, Float3) + + operator /(Line, Float3) + + operator ==(Line, Line) + + operator !=(Line, Line) + + implicit operator Line((Float3 a, Float3 b)) + - : IAbsolute + - : ICeiling + - : IClamp + - : IComparable + - : IFloor + - : IFromTuple + - : IIndexAll + - : IIndexRangeAll + - : IRound + - : ISplittable + - Line(Fill) + - Absolute(Line) + - Ceiling(Line) + - Clamp(Line, Line, Line) + - Floor(Line) + - Round(Line) + - CompareTo(Line?) + - ToFloatList() + - PrintMembers(StringBuilder) + - operator +(Line, Line) + - operator +(Line, Vert) + - operator -(Line) + - operator -(Line, Line) + - operator -(Line, Vert) + - operator *(Line, Line) + - operator *(Line, Vert) + - operator /(Line, Line) + - operator /(Line, Vert) + - operator >(Line, Line) + - operator <(Line, Line) + - operator >=(Line, Line) + - operator <=(Line, Line) + - implicit operator Line(Fill) + - implicit operator Line((Vert start, Vert end)) + = Changed the parameter type of the parameter `vert` in `Contains(Vert)` from `Vert` to `Float3` and renamed it to `point` + = Changed the parameter type of the parameter `vert` in `ClosestTo(Vert)` from `Vert` to `Float3` and renamed it to `point` + = Changed the parameter type of the parameter `vert` in `ClosestTo(Vert, float)` from `Vert` to `Float3` and renamed it to `point` + = Changed the return type of `Midpoint` from `Vert` to `Float3` + = Changed the return type of `this[int]` from `Vert` to `Float3` + = Changed the return type of `this[Index]` from `Vert` to `Float3` + = Changed the return type of `this[Range]` from `Vert` to `Float3` + = Changed the return type of `SplitArray(params Line[])` from `(Vert[] starts, Vert[] ends)` to `(Float3[] As, Float3[] Bs)` + = Changed the return type of `ToArray()` from `Vert[]` to `Float3[]` + = Changed the return type of `ToFill()` from `Fill` to `Fill` + = Changed the return type of `ToList()` from `List` to `List` + = Changed the return type of `ClosestTo(Vert)` from `Vert` to `Float3` + = Changed the return type of `ClosestTo(Vert, float)` from `Vert` to `Float3` + = Changed the return type of `GetEnumerator()` from `IEnumerator` to `IEnumerator` + = Changed the variable type of `a` from `Vert` to `Float3` + = Changed the variable type of `b` from `Vert` to `Float3` + = Expanded `Line(float, float, float, float)` so as to reduce confusion + = Expanded `Line(float, float, float, float, float, float)` so as to reduce confusion + = Improved the `Contains(Vert)` function + = Improved the `ClosestTo(Vert, float)` function + = Made the `Subdivide(int)` function split into n+1 lines rather than 2^(n-1) lines + = Renamed a parameter of `Average(params Line[])` from `vals` to `lines` + = Renamed a parameter of `Median(params Line[])` from `vals` to `lines` + = Renamed a parameter of `SplitArray(params Line[])` from `vals` to `lines` + = Replaced references to `Vert` with references to `Float3` in `Back` + = Replaced references to `Vert` with references to `Float3` in `Down` + = Replaced references to `Vert` with references to `Float3` in `Forward` + = Replaced references to `Vert` with references to `Float3` in `Left` + = Replaced references to `Vert` with references to `Float3` in `Right` + = Replaced references to `Vert` with references to `Float3` in `Up` + = Replaced references to `Vert` with references to `Float3` in `One` + = Replaced references to `Vert` with references to `Float3` in `Zero` + = Replaced references to `Vert` with references to `Float3` in `Line(Vert, Vert)` + = Replaced references to `Vert` with references to `Float3` in `Average(params Line[])` + = Replaced references to `Vert` with references to `Float3` in `Lerp(Line, Line, float, bool)` + = Replaced references to `Vert` with references to `Float3` in `Median(params Line[])` + = Replaced references to `Vert` with references to `Float3` in `SplitArray(params Line[])` + = Replaced references to `Vert` with references to `Float3` in `ClosestTo(Vert, float)` + = Replaced references to `Vert` with references to `Float3` in `Subdivide()` + = Replaced references to `Vert` with references to `Float3` in `Subdivide(int)` + = Simplified `Equals(Line?)` and removed the `virtual` keyword * NumberSystems * Complex = Replaced all references to `Vert` with references to `Float3` diff --git a/Nerd_STF/Mathematics/Geometry/Line.cs b/Nerd_STF/Mathematics/Geometry/Line.cs index ab21320..0e8971a 100644 --- a/Nerd_STF/Mathematics/Geometry/Line.cs +++ b/Nerd_STF/Mathematics/Geometry/Line.cs @@ -2,8 +2,8 @@ public class Line : IAverage, IClosestTo, IContains, IEquatable, IFloatArray, IFromTuple, IGroup, - ILerp, IMedian, IPresets3d, - ISplittable, ISubdivide, + IIndexAll, IIndexRangeAll, ILerp, IMedian, + IPresets3d, ISplittable, ISubdivide, IWithinRange { public static Line Back => (Float3.Zero, Float3.Back); @@ -172,8 +172,8 @@ public class Line : IAverage, IClosestTo, IContains, IEqua return builder.ToString(); } - public Float3 ClosestTo(Float3 item) => ClosestTo(item, Calculus.DefaultStep); - public Float3 ClosestTo(Float3 item, float step) + public Float3 ClosestTo(Float3 point) => ClosestTo(point, Calculus.DefaultStep); + public Float3 ClosestTo(Float3 point, float step) { // Probably could optimize this with some weird formula but whatever. // This isn't the optimization update. @@ -182,7 +182,7 @@ public class Line : IAverage, IClosestTo, IContains, IEqua for (float f = 0; f < 1; f += step) { Float3 check = Float3.Lerp(a, b, f); - float dist = (check - item).Magnitude; + float dist = (check - point).Magnitude; if (dist < min.dist) min = (check, dist); } @@ -240,5 +240,18 @@ public class Line : IAverage, IClosestTo, IContains, IEqua return false; } - public static implicit operator Line((Float3 a, Float3 b) tuple) => new(tuple.a, tuple.b); + public static Line operator +(Line l, Float3 offset) => (l.a + offset, l.b + offset); + public static Line operator -(Line l, Float3 offset) => (l.a + offset, l.b + offset); + public static Line operator *(Line l, float factor) => (l.a * factor, l.b * factor); + public static Line operator *(Line l, Float3 factor) => (l.a * factor, l.b * factor); + public static Line operator /(Line l, float factor) => (l.a / factor, l.b / factor); + public static Line operator /(Line l, Float3 factor) => (l.a / factor, l.b / factor); + public static bool operator ==(Line a, Line b) => a.Equals(b); + public static bool operator !=(Line a, Line b) => !a.Equals(b); + + public static implicit operator Line(Fill fill) => new(fill); + public static implicit operator Line(Fill fill) => new(fill); + public static implicit operator Line(Fill fill) => new(fill); + public static implicit operator Line(Fill fill) => new(fill); + public static implicit operator Line((Float3 a, Float3 b) tuple) => (tuple.a, tuple.b); }