Version 2.1.1

This commit is contained in:
That-One-Nerd 2022-04-17 17:55:56 -04:00
parent 4be41701cd
commit 97c189c296
34 changed files with 2810 additions and 3063 deletions

View File

@ -1,82 +1,12 @@
# Nerd_STF v2.1.0 # Nerd_STF v2.1.1
This update doesn't add any new features, simply a code simplification, using some of the .net 6 tools, such as global usings and file-scoped namespace declarations.
``` ```
* Nerd_STF * Nerd_STF
+ Exceptions = Removed unused or unrequired usings in all files.
+ Nerd_STFException = Replaced all namespace declarations with file-scoped declarations.
+ DifferingVertCountException * Miscellaneous
+ DisconnectedLinesException * GlobalUsings
+ Miscellaneous + global using System.Diagnostics.CodeAnalysis
+ `GlobalUsings.cs`
+ IClosest<T>
+ IContainer<T>
* Logger
* DefaultLogHandler(LogMessage)
= Replaced a `throw new Exception` with a `throw new ArgumentException`
* Mathematics
+ Angle
+ Calculus
+ delegate double Equation(double)
* Double2
= Made `CompareTo(Double2)` better
* Double3
= Made `CompareTo(Double3)` better
* Double4
= Made `CompareTo(Double4)` better
* Int2
+ operator &(Int2, Int2)
+ operator |(Int2, Int2)
+ operator ^(Int2, Int2)
= Made `CompareTo(Int2)` better
* Int3
+ operator &(Int3, Int3)
+ operator |(Int3, Int3)
+ operator ^(Int3, Int3)
= Made `CompareTo(Int3)` better
* Int4
+ operator &(Int4, Int4)
+ operator |(Int4, Int4)
+ operator ^(Int4, Int4)
= Made `CompareTo(Int4)` better
* Mathf
+ Average(Equation, double, double, double)
+ GetValues(Equation)
+ MakeEquation(Dictionary<double, double>)
+ Max(Equation, double, double, double)
+ Min(Equation, double, double, double)
= Swapped the names of "RadToDeg" and "DegToRad"
* Geometry
+ Box2D
+ Box3D
+ Polygon
+ Quadrilateral
+ Sphere
+ ISubdividable
* ITriangulatable
+ Triangle[] TriangulateAll(params ITriangulatable[])
* Line
+ : IComparable<Line>
+ : IContainer<Vert>
+ : IClosest<Vert>
+ : ISubdividable<Line[]>
+ ClosestTo(Vert)
+ ClosestTo(Vert, double)
+ CompareTo(Line)
+ Contains(Vert)
+ Subdivide()
+ operator -(Line)
+ operator >(Line)
+ operator <(Line)
+ operator >=(Line)
+ operator <=(Line)
= Renamed all instances of "start" to "a"
= Renamed all instances of "end" to "b"
* Triangle
+ operator -(Triangle)
+ ToDoubleArrayAll(params Triangle[])
= Replaced the variable assignings in the Triangle to not re-assign the lines.
= Now uses custom exception in line constructor
= Renamed "L1" to "AB"
= Renamed "L2" to "BC"
= Renamed "L3" to "CA"
``` ```

View File

@ -1,11 +1,10 @@
using System.Runtime.Serialization; using System.Runtime.Serialization;
namespace Nerd_STF.Exceptions namespace Nerd_STF.Exceptions;
{
[Serializable] [Serializable]
public class DifferingVertCountException : Nerd_STFException public class DifferingVertCountException : Nerd_STFException
{ {
public string? ParamName; public string? ParamName;
public Polygon[]? Polygons; public Polygon[]? Polygons;
@ -26,5 +25,4 @@ namespace Nerd_STF.Exceptions
Polygons = polys; Polygons = polys;
} }
protected DifferingVertCountException(SerializationInfo info, StreamingContext context) : base(info, context) { } protected DifferingVertCountException(SerializationInfo info, StreamingContext context) : base(info, context) { }
}
} }

View File

@ -1,16 +1,10 @@
using Nerd_STF.Mathematics.Geometry; using System.Runtime.Serialization;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
namespace Nerd_STF.Exceptions namespace Nerd_STF.Exceptions;
[Serializable]
public class DisconnectedLinesException : Nerd_STFException
{ {
[Serializable]
public class DisconnectedLinesException : Nerd_STFException
{
public string? ParamName; public string? ParamName;
public Line[]? Lines; public Line[]? Lines;
@ -31,5 +25,4 @@ namespace Nerd_STF.Exceptions
Lines = lines; Lines = lines;
} }
protected DisconnectedLinesException(SerializationInfo info, StreamingContext context) : base(info, context) { } protected DisconnectedLinesException(SerializationInfo info, StreamingContext context) : base(info, context) { }
}
} }

View File

@ -1,18 +1,12 @@
using System; using System.Runtime.Serialization;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
namespace Nerd_STF.Exceptions namespace Nerd_STF.Exceptions;
[Serializable]
public class Nerd_STFException : Exception
{ {
[Serializable]
public class Nerd_STFException : Exception
{
public Nerd_STFException() { } public Nerd_STFException() { }
public Nerd_STFException(string message) : base(message) { } public Nerd_STFException(string message) : base(message) { }
public Nerd_STFException(string message, Exception inner) : base(message, inner) { } public Nerd_STFException(string message, Exception inner) : base(message, inner) { }
protected Nerd_STFException(SerializationInfo info, StreamingContext context) : base(info, context) { } protected Nerd_STFException(SerializationInfo info, StreamingContext context) : base(info, context) { }
}
} }

View File

@ -1,4 +1,3 @@
namespace Nerd_STF namespace Nerd_STF;
{
public delegate T Fill<T>(int index); public delegate T Fill<T>(int index);
}

View File

@ -1,13 +1,6 @@
using System; namespace Nerd_STF;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Nerd_STF public interface IClosest<T> where T : IEquatable<T>
{ {
public interface IClosest<T> where T : IEquatable<T>
{
public T ClosestTo(T item); public T ClosestTo(T item);
}
} }

View File

@ -1,13 +1,6 @@
using System; namespace Nerd_STF;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Nerd_STF public interface IContainer<T> where T : IEquatable<T>
{ {
public interface IContainer<T> where T : IEquatable<T>
{
public bool Contains(T item); public bool Contains(T item);
}
} }

View File

@ -1,13 +1,6 @@
using System; namespace Nerd_STF;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Nerd_STF public interface IEncapsulator<T, TE> : IContainer<TE> where T : IEquatable<T> where TE : IEquatable<TE>
{ {
public interface IEncapsulator<T, TE> : IContainer<TE> where T : IEquatable<T> where TE : IEquatable<TE>
{
public T Encapsulate(TE val); public T Encapsulate(TE val);
}
} }

View File

@ -1,8 +1,7 @@
namespace Nerd_STF namespace Nerd_STF;
public interface IGroup<T> : IEnumerable<T>
{ {
public interface IGroup<T> : IEnumerable<T>
{
public T[] ToArray(); public T[] ToArray();
public List<T> ToList(); public List<T> ToList();
}
} }

View File

@ -1,13 +1,7 @@
using System; namespace Nerd_STF;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Nerd_STF public struct LogMessage
{ {
public struct LogMessage
{
public string Message; public string Message;
public LogSeverity Severity; public LogSeverity Severity;
public DateTime Timestamp; public DateTime Timestamp;
@ -21,5 +15,4 @@ namespace Nerd_STF
} }
public override string ToString() => Timestamp + " " + Severity.ToString().ToUpper() + ": " + Message; public override string ToString() => Timestamp + " " + Severity.ToString().ToUpper() + ": " + Message;
}
} }

View File

@ -1,11 +1,10 @@
namespace Nerd_STF namespace Nerd_STF;
public enum LogSeverity
{ {
public enum LogSeverity
{
Debug = 1, Debug = 1,
Information = 2, Information = 2,
Warning = 4, Warning = 4,
Error = 8, Error = 8,
Fatal = 16, Fatal = 16,
}
} }

View File

@ -1,9 +1,9 @@
using System.Text; using System.Text;
namespace Nerd_STF namespace Nerd_STF;
public class Logger
{ {
public class Logger
{
public event Action<LogMessage> OnMessageRecieved = DefaultLogHandler; public event Action<LogMessage> OnMessageRecieved = DefaultLogHandler;
public LogMessage[] Cache => msgs.ToArray(); public LogMessage[] Cache => msgs.ToArray();
@ -68,5 +68,4 @@ namespace Nerd_STF
Console.ForegroundColor = originalCol; Console.ForegroundColor = originalCol;
} }
}
} }

View File

@ -1,14 +1,7 @@
using System; namespace Nerd_STF.Mathematics;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Nerd_STF.Mathematics public struct Angle : ICloneable, IComparable<Angle>, IEquatable<Angle>
{ {
public struct Angle : ICloneable, IComparable<Angle>, IEquatable<Angle>
{
public static Angle Full => new(360); public static Angle Full => new(360);
public static Angle Half => new(180); public static Angle Half => new(180);
public static Angle One => new(1); public static Angle One => new(1);
@ -120,5 +113,4 @@ namespace Nerd_STF.Mathematics
Gradians, Gradians,
Radians, Radians,
} }
}
} }

View File

@ -1,13 +1,7 @@
using System; namespace Nerd_STF.Mathematics;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Nerd_STF.Mathematics public static class Calculus
{ {
public static class Calculus
{
public const double DefaultStep = 0.001; public const double DefaultStep = 0.001;
public static Equation GetDerivative(Equation equ, double min, double max, double step = DefaultStep) public static Equation GetDerivative(Equation equ, double min, double max, double step = DefaultStep)
@ -37,5 +31,4 @@ namespace Nerd_STF.Mathematics
for (int i = 0; i < stepCount; i++) val -= GetDerivativeAtPoint(equ, val, step) * rate; for (int i = 0; i < stepCount; i++) val -= GetDerivativeAtPoint(equ, val, step) * rate;
return val; return val;
} }
}
} }

View File

@ -1,11 +1,7 @@
using Nerd_STF.Mathematics.Geometry; namespace Nerd_STF.Mathematics;
using System.Collections;
using System.Diagnostics.CodeAnalysis;
namespace Nerd_STF.Mathematics public struct Double2 : ICloneable, IComparable<Double2>, IEquatable<Double2>, IGroup<double>
{ {
public struct Double2 : ICloneable, IComparable<Double2>, IEquatable<Double2>, IGroup<double>
{
public static Double2 Down => new(0, -1); public static Double2 Down => new(0, -1);
public static Double2 Left => new(-1, 0); public static Double2 Left => new(-1, 0);
public static Double2 Right => new(1, 0); public static Double2 Right => new(1, 0);
@ -182,5 +178,4 @@ namespace Nerd_STF.Mathematics
public static explicit operator Double2(Vert val) => new(val.position.x, val.position.y); public static explicit operator Double2(Vert val) => new(val.position.x, val.position.y);
public static implicit operator Double2(Fill<double> fill) => new(fill); public static implicit operator Double2(Fill<double> fill) => new(fill);
public static implicit operator Double2(Fill<int> fill) => new(fill); public static implicit operator Double2(Fill<int> fill) => new(fill);
}
} }

View File

@ -1,11 +1,7 @@
using Nerd_STF.Mathematics.Geometry; namespace Nerd_STF.Mathematics;
using System.Collections;
using System.Diagnostics.CodeAnalysis;
namespace Nerd_STF.Mathematics public struct Double3 : ICloneable, IComparable<Double3>, IEquatable<Double3>, IGroup<double>
{ {
public struct Double3 : ICloneable, IComparable<Double3>, IEquatable<Double3>, IGroup<double>
{
public static Double3 Back => new(0, 0, -1); public static Double3 Back => new(0, 0, -1);
public static Double3 Down => new(0, -1, 0); public static Double3 Down => new(0, -1, 0);
public static Double3 Forward => new(0, 0, 1); public static Double3 Forward => new(0, 0, 1);
@ -203,5 +199,4 @@ namespace Nerd_STF.Mathematics
public static implicit operator Double3(Vert val) => new(val.position.x, val.position.y, val.position.z); public static implicit operator Double3(Vert val) => new(val.position.x, val.position.y, val.position.z);
public static implicit operator Double3(Fill<double> fill) => new(fill); public static implicit operator Double3(Fill<double> fill) => new(fill);
public static implicit operator Double3(Fill<int> fill) => new(fill); public static implicit operator Double3(Fill<int> fill) => new(fill);
}
} }

View File

@ -1,11 +1,7 @@
using Nerd_STF.Mathematics.Geometry; namespace Nerd_STF.Mathematics;
using System.Collections;
using System.Diagnostics.CodeAnalysis;
namespace Nerd_STF.Mathematics public struct Double4 : ICloneable, IComparable<Double4>, IEquatable<Double4>, IGroup<double>
{ {
public struct Double4 : ICloneable, IComparable<Double4>, IEquatable<Double4>, IGroup<double>
{
public static Double4 Back => new(0, 0, -1, 0); public static Double4 Back => new(0, 0, -1, 0);
public static Double4 Deep => new(0, 0, 0, -1); public static Double4 Deep => new(0, 0, 0, -1);
public static Double4 Down => new(0, -1, 0, 0); public static Double4 Down => new(0, -1, 0, 0);
@ -219,5 +215,4 @@ namespace Nerd_STF.Mathematics
public static implicit operator Double4(Vert val) => new(val.position.x, val.position.y, val.position.z, 0); public static implicit operator Double4(Vert val) => new(val.position.x, val.position.y, val.position.z, 0);
public static implicit operator Double4(Fill<double> fill) => new(fill); public static implicit operator Double4(Fill<double> fill) => new(fill);
public static implicit operator Double4(Fill<int> fill) => new(fill); public static implicit operator Double4(Fill<int> fill) => new(fill);
}
} }

View File

@ -1,10 +1,3 @@
using System; namespace Nerd_STF.Mathematics;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Nerd_STF.Mathematics public delegate double Equation(double x);
{
public delegate double Equation(double x);
}

View File

@ -1,14 +1,7 @@
using System; namespace Nerd_STF.Mathematics.Geometry;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Nerd_STF.Mathematics.Geometry public struct Box2D : ICloneable, IContainer<Vert>, IEquatable<Box2D>
{ {
public struct Box2D : ICloneable, IContainer<Vert>, IEquatable<Box2D>
{
public static Box2D Unit => new(Vert.Zero, Double2.One); public static Box2D Unit => new(Vert.Zero, Double2.One);
public Vert MaxVert public Vert MaxVert
@ -126,5 +119,4 @@ namespace Nerd_STF.Mathematics.Geometry
public static implicit operator Box2D(Fill<double> fill) => new(fill); public static implicit operator Box2D(Fill<double> fill) => new(fill);
public static explicit operator Box2D(Box3D box) => new(box.center, (Double2)box.size); public static explicit operator Box2D(Box3D box) => new(box.center, (Double2)box.size);
}
} }

View File

@ -1,14 +1,7 @@
using System; namespace Nerd_STF.Mathematics.Geometry;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Nerd_STF.Mathematics.Geometry public struct Box3D : ICloneable, IContainer<Vert>, IEquatable<Box3D>
{ {
public struct Box3D : ICloneable, IContainer<Vert>, IEquatable<Box3D>
{
public static Box3D Unit => new(Vert.Zero, Double3.One); public static Box3D Unit => new(Vert.Zero, Double3.One);
public Vert MaxVert public Vert MaxVert
@ -110,7 +103,6 @@ namespace Nerd_STF.Mathematics.Geometry
Double3 diff = Double3.Absolute(center - vert); Double3 diff = Double3.Absolute(center - vert);
return diff.x <= size.x && diff.y <= size.y && diff.z <= size.z; return diff.x <= size.x && diff.y <= size.y && diff.z <= size.z;
} }
public object Clone() => new Box3D(center, size); public object Clone() => new Box3D(center, size);
public static Box3D operator +(Box3D a, Vert b) => new(a.center + b, a.size); public static Box3D operator +(Box3D a, Vert b) => new(a.center + b, a.size);
@ -127,5 +119,4 @@ namespace Nerd_STF.Mathematics.Geometry
public static implicit operator Box3D(Fill<double> fill) => new(fill); public static implicit operator Box3D(Fill<double> fill) => new(fill);
public static implicit operator Box3D(Box2D box) => new(box); public static implicit operator Box3D(Box2D box) => new(box);
}
} }

View File

@ -1,14 +1,7 @@
using System; namespace Nerd_STF.Mathematics.Geometry;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Nerd_STF.Mathematics.Geometry public interface ISubdividable<T>
{ {
public interface ISubdividable<T>
{
public T Subdivide(); public T Subdivide();
public T Subdivide(int iterations); public T Subdivide(int iterations);
}
} }

View File

@ -1,13 +1,7 @@
using System; namespace Nerd_STF.Mathematics.Geometry;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Nerd_STF.Mathematics.Geometry public interface ITriangulatable
{ {
public interface ITriangulatable
{
public static Triangle[] TriangulateAll(params ITriangulatable[] triangulatables) public static Triangle[] TriangulateAll(params ITriangulatable[] triangulatables)
{ {
List<Triangle> res = new(); List<Triangle> res = new();
@ -16,5 +10,4 @@ namespace Nerd_STF.Mathematics.Geometry
} }
public Triangle[] Triangulate(); public Triangle[] Triangulate();
}
} }

View File

@ -1,16 +1,8 @@
using System; namespace Nerd_STF.Mathematics.Geometry;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Nerd_STF.Mathematics.Geometry public struct Line : ICloneable, IClosest<Vert>, IComparable<Line>, IContainer<Vert>, IEquatable<Line>,
{
public struct Line : ICloneable, IClosest<Vert>, IComparable<Line>, IContainer<Vert>, IEquatable<Line>,
IGroup<Vert>, ISubdividable<Line[]> IGroup<Vert>, ISubdividable<Line[]>
{ {
public static Line Back => new(Vert.Zero, Vert.Back); public static Line Back => new(Vert.Zero, Vert.Back);
public static Line Down => new(Vert.Zero, Vert.Down); public static Line Down => new(Vert.Zero, Vert.Down);
public static Line Forward => new(Vert.Zero, Vert.Forward); public static Line Forward => new(Vert.Zero, Vert.Forward);
@ -198,5 +190,4 @@ namespace Nerd_STF.Mathematics.Geometry
public static implicit operator Line(Fill<Int3> fill) => new(fill); public static implicit operator Line(Fill<Int3> fill) => new(fill);
public static implicit operator Line(Fill<double> fill) => new(fill); public static implicit operator Line(Fill<double> fill) => new(fill);
public static implicit operator Line(Fill<int> fill) => new(fill); public static implicit operator Line(Fill<int> fill) => new(fill);
}
} }

View File

@ -1,15 +1,7 @@
using Nerd_STF.Exceptions; namespace Nerd_STF.Mathematics.Geometry;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Nerd_STF.Mathematics.Geometry public struct Polygon : ICloneable, IEquatable<Polygon>, IGroup<Vert>, ISubdividable<Polygon>, ITriangulatable
{ {
public struct Polygon : ICloneable, IEquatable<Polygon>, IGroup<Vert>, ISubdividable<Polygon>, ITriangulatable
{
public Line[] Lines public Line[] Lines
{ {
get => p_lines; get => p_lines;
@ -515,5 +507,4 @@ namespace Nerd_STF.Mathematics.Geometry
public static implicit operator Polygon(Line[] lines) => new(lines); public static implicit operator Polygon(Line[] lines) => new(lines);
public static implicit operator Polygon(Triangle tri) => new(tri.AB, tri.BC, tri.CA); public static implicit operator Polygon(Triangle tri) => new(tri.AB, tri.BC, tri.CA);
public static implicit operator Polygon(Quadrilateral quad) => new(quad.AB, quad.BC, quad.CD, quad.DA); public static implicit operator Polygon(Quadrilateral quad) => new(quad.AB, quad.BC, quad.CD, quad.DA);
}
} }

View File

@ -1,16 +1,7 @@
using Nerd_STF.Exceptions; namespace Nerd_STF.Mathematics.Geometry;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Nerd_STF.Mathematics.Geometry public struct Quadrilateral : ICloneable, IEquatable<Quadrilateral>, IGroup<Vert>, ITriangulatable
{ {
public struct Quadrilateral : ICloneable, IEquatable<Quadrilateral>, IGroup<Vert>, ITriangulatable
{
public Vert A public Vert A
{ {
get => p_a; get => p_a;
@ -338,5 +329,4 @@ namespace Nerd_STF.Mathematics.Geometry
public static implicit operator Quadrilateral(Fill<int> fill) => new(fill); public static implicit operator Quadrilateral(Fill<int> fill) => new(fill);
public static explicit operator Quadrilateral(Polygon poly) => new(poly.Lines[0], poly.Lines[1], public static explicit operator Quadrilateral(Polygon poly) => new(poly.Lines[0], poly.Lines[1],
poly.Lines[2], poly.Lines[3]); poly.Lines[2], poly.Lines[3]);
}
} }

View File

@ -1,15 +1,8 @@
using System; namespace Nerd_STF.Mathematics.Geometry;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Nerd_STF.Mathematics.Geometry public struct Sphere : ICloneable, IClosest<Vert>, IComparable<Sphere>, IComparable<double>, IContainer<Vert>,
{
public struct Sphere : ICloneable, IClosest<Vert>, IComparable<Sphere>, IComparable<double>, IContainer<Vert>,
IEquatable<Sphere>, IEquatable<double> IEquatable<Sphere>, IEquatable<double>
{ {
public static Sphere Unit => new(Vert.Zero, 1); public static Sphere Unit => new(Vert.Zero, 1);
public Vert center; public Vert center;
@ -122,5 +115,4 @@ namespace Nerd_STF.Mathematics.Geometry
public static bool operator <=(Sphere a, Sphere b) => a < b || a == b; public static bool operator <=(Sphere a, Sphere b) => a < b || a == b;
public static bool operator >=(Sphere a, double b) => a > b || a == b; public static bool operator >=(Sphere a, double b) => a > b || a == b;
public static bool operator <=(Sphere a, double b) => a < b || a == b; public static bool operator <=(Sphere a, double b) => a < b || a == b;
}
} }

View File

@ -1,11 +1,7 @@
using Nerd_STF.Exceptions; namespace Nerd_STF.Mathematics.Geometry;
using System.Collections;
using System.Diagnostics.CodeAnalysis;
namespace Nerd_STF.Mathematics.Geometry public struct Triangle : ICloneable, IEquatable<Triangle>, IGroup<Vert>
{ {
public struct Triangle : ICloneable, IEquatable<Triangle>, IGroup<Vert>
{
public Vert A public Vert A
{ {
get => p_a; get => p_a;
@ -110,11 +106,9 @@ namespace Nerd_STF.Mathematics.Geometry
public Triangle(Fill<Vert> fill) : this(fill(0), fill(1), fill(2)) { } public Triangle(Fill<Vert> fill) : this(fill(0), fill(1), fill(2)) { }
public Triangle(Fill<Line> fill) : this(fill(0), fill(1), fill(2)) { } public Triangle(Fill<Line> fill) : this(fill(0), fill(1), fill(2)) { }
public Triangle(Fill<double> fill) : this(fill(0), fill(1), fill(2), fill(3), fill(4), fill(5), fill(6), public Triangle(Fill<double> fill) : this(fill(0), fill(1), fill(2), fill(3), fill(4), fill(5), fill(6),
fill(7), fill(8)) fill(7), fill(8)) { }
{ }
public Triangle(Fill<int> fill) : this(fill(0), fill(1), fill(2), fill(3), fill(4), fill(5), fill(6), public Triangle(Fill<int> fill) : this(fill(0), fill(1), fill(2), fill(3), fill(4), fill(5), fill(6),
fill(7), fill(8)) fill(7), fill(8)) { }
{ }
public Vert this[int index] public Vert this[int index]
{ {
@ -186,7 +180,6 @@ namespace Nerd_STF.Mathematics.Geometry
b[i] = tris[i].B; b[i] = tris[i].B;
c[i] = tris[i].C; c[i] = tris[i].C;
} }
return (a, b, c); return (a, b, c);
} }
public static (Line[] ABs, Line[] BCs, Line[] CAs) SplitLineArray(params Triangle[] tris) public static (Line[] ABs, Line[] BCs, Line[] CAs) SplitLineArray(params Triangle[] tris)
@ -198,7 +191,6 @@ namespace Nerd_STF.Mathematics.Geometry
bc[i] = tris[i].BC; bc[i] = tris[i].BC;
ca[i] = tris[i].CA; ca[i] = tris[i].CA;
} }
return (ab, bc, ca); return (ab, bc, ca);
} }
@ -254,7 +246,6 @@ namespace Nerd_STF.Mathematics.Geometry
public List<double> ToDoubleList() => new() { A.position.x, A.position.y, A.position.z, public List<double> ToDoubleList() => new() { A.position.x, A.position.y, A.position.z,
B.position.x, B.position.y, B.position.z, B.position.x, B.position.y, B.position.z,
C.position.x, C.position.y, C.position.z }; C.position.x, C.position.y, C.position.z };
public static Triangle operator +(Triangle a, Triangle b) => new(a.A + b.A, a.B + b.B, a.C + b.C); public static Triangle operator +(Triangle a, Triangle b) => new(a.A + b.A, a.B + b.B, a.C + b.C);
public static Triangle operator +(Triangle a, Vert b) => new(a.A + b, a.B + b, a.C + b); public static Triangle operator +(Triangle a, Vert b) => new(a.A + b, a.B + b, a.C + b);
public static Triangle operator -(Triangle t) => new(-t.A, -t.B, -t.C); public static Triangle operator -(Triangle t) => new(-t.A, -t.B, -t.C);
@ -276,5 +267,4 @@ namespace Nerd_STF.Mathematics.Geometry
public static implicit operator Triangle(Fill<double> fill) => new(fill); public static implicit operator Triangle(Fill<double> fill) => new(fill);
public static implicit operator Triangle(Fill<int> fill) => new(fill); public static implicit operator Triangle(Fill<int> fill) => new(fill);
public static explicit operator Triangle(Polygon poly) => new(poly.Lines[0], poly.Lines[1], poly.Lines[2]); public static explicit operator Triangle(Polygon poly) => new(poly.Lines[0], poly.Lines[1], poly.Lines[2]);
}
} }

View File

@ -1,10 +1,7 @@
using System.Collections; namespace Nerd_STF.Mathematics.Geometry;
using System.Diagnostics.CodeAnalysis;
namespace Nerd_STF.Mathematics.Geometry public struct Vert : ICloneable, IEquatable<Vert>, IGroup<double>
{ {
public struct Vert : ICloneable, IEquatable<Vert>, IGroup<double>
{
public static Vert Back => new(0, 0, -1); public static Vert Back => new(0, 0, -1);
public static Vert Down => new(0, -1, 0); public static Vert Down => new(0, -1, 0);
public static Vert Forward => new(0, 0, 1); public static Vert Forward => new(0, 0, 1);
@ -98,5 +95,4 @@ namespace Nerd_STF.Mathematics.Geometry
public static explicit operator Vert(Int4 val) => new(val.XYZ); public static explicit operator Vert(Int4 val) => new(val.XYZ);
public static implicit operator Vert(Fill<double> fill) => new(fill); public static implicit operator Vert(Fill<double> fill) => new(fill);
public static implicit operator Vert(Fill<int> fill) => new(fill); public static implicit operator Vert(Fill<int> fill) => new(fill);
}
} }

View File

@ -1,11 +1,7 @@
using Nerd_STF.Mathematics.Geometry; namespace Nerd_STF.Mathematics;
using System.Collections;
using System.Diagnostics.CodeAnalysis;
namespace Nerd_STF.Mathematics public struct Int2 : ICloneable, IComparable<Int2>, IEquatable<Int2>, IGroup<int>
{ {
public struct Int2 : ICloneable, IComparable<Int2>, IEquatable<Int2>, IGroup<int>
{
public static Int2 Down => new(0, -1); public static Int2 Down => new(0, -1);
public static Int2 Left => new(-1, 0); public static Int2 Left => new(-1, 0);
public static Int2 Right => new(1, 0); public static Int2 Right => new(1, 0);
@ -179,5 +175,4 @@ namespace Nerd_STF.Mathematics
public static explicit operator Int2(Int4 val) => new(val.x, val.y); public static explicit operator Int2(Int4 val) => new(val.x, val.y);
public static explicit operator Int2(Vert val) => new((int)val.position.x, (int)val.position.y); public static explicit operator Int2(Vert val) => new((int)val.position.x, (int)val.position.y);
public static implicit operator Int2(Fill<int> fill) => new(fill); public static implicit operator Int2(Fill<int> fill) => new(fill);
}
} }

View File

@ -1,11 +1,7 @@
using Nerd_STF.Mathematics.Geometry; namespace Nerd_STF.Mathematics;
using System.Collections;
using System.Diagnostics.CodeAnalysis;
namespace Nerd_STF.Mathematics public struct Int3 : ICloneable, IComparable<Int3>, IEquatable<Int3>, IGroup<int>
{ {
public struct Int3 : ICloneable, IComparable<Int3>, IEquatable<Int3>, IGroup<int>
{
public static Int3 Back => new(0, 0, -1); public static Int3 Back => new(0, 0, -1);
public static Int3 Down => new(0, -1, 0); public static Int3 Down => new(0, -1, 0);
public static Int3 Forward => new(0, 0, 1); public static Int3 Forward => new(0, 0, 1);
@ -148,7 +144,6 @@ namespace Nerd_STF.Mathematics
foreach (Int3 d in vals) val += d; foreach (Int3 d in vals) val += d;
return val; return val;
} }
public int CompareTo(Int3 other) => Magnitude.CompareTo(other.Magnitude); public int CompareTo(Int3 other) => Magnitude.CompareTo(other.Magnitude);
public override bool Equals([NotNullWhen(true)] object? obj) public override bool Equals([NotNullWhen(true)] object? obj)
{ {
@ -162,9 +157,7 @@ namespace Nerd_STF.Mathematics
"X: " + x.ToString(provider) + " Y: " + y.ToString(provider) + " Z: " + z.ToString(provider); "X: " + x.ToString(provider) + " Y: " + y.ToString(provider) + " Z: " + z.ToString(provider);
public string ToString(IFormatProvider provider) => public string ToString(IFormatProvider provider) =>
"X: " + x.ToString(provider) + " Y: " + y.ToString(provider) + " Z: " + z.ToString(provider); "X: " + x.ToString(provider) + " Y: " + y.ToString(provider) + " Z: " + z.ToString(provider);
public object Clone() => new Int3(x, y, z); public object Clone() => new Int3(x, y, z);
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
public IEnumerator<int> GetEnumerator() public IEnumerator<int> GetEnumerator()
{ {
@ -201,5 +194,4 @@ namespace Nerd_STF.Mathematics
public static explicit operator Int3(Vert val) => new((int)val.position.x, (int)val.position.y, public static explicit operator Int3(Vert val) => new((int)val.position.x, (int)val.position.y,
(int)val.position.z); (int)val.position.z);
public static implicit operator Int3(Fill<int> fill) => new(fill); public static implicit operator Int3(Fill<int> fill) => new(fill);
}
} }

View File

@ -1,11 +1,7 @@
using Nerd_STF.Mathematics.Geometry; namespace Nerd_STF.Mathematics;
using System.Collections;
using System.Diagnostics.CodeAnalysis;
namespace Nerd_STF.Mathematics public struct Int4 : ICloneable, IComparable<Int4>, IEquatable<Int4>, IGroup<int>
{ {
public struct Int4 : ICloneable, IComparable<Int4>, IEquatable<Int4>, IGroup<int>
{
public static Int4 Back => new(0, 0, -1, 0); public static Int4 Back => new(0, 0, -1, 0);
public static Int4 Deep => new(0, 0, 0, -1); public static Int4 Deep => new(0, 0, 0, -1);
public static Int4 Down => new(0, -1, 0, 0); public static Int4 Down => new(0, -1, 0, 0);
@ -217,5 +213,4 @@ namespace Nerd_STF.Mathematics
public static explicit operator Int4(Vert val) => new((int)val.position.x, (int)val.position.y, public static explicit operator Int4(Vert val) => new((int)val.position.x, (int)val.position.y,
(int)val.position.z, 0); (int)val.position.z, 0);
public static implicit operator Int4(Fill<int> fill) => new(fill); public static implicit operator Int4(Fill<int> fill) => new(fill);
}
} }

View File

@ -1,7 +1,7 @@
namespace Nerd_STF.Mathematics namespace Nerd_STF.Mathematics;
public static class Mathf
{ {
public static class Mathf
{
public const double RadToDeg = 0.0174532925199; // Pi / 180 public const double RadToDeg = 0.0174532925199; // Pi / 180
public const double E = 2.71828182846; public const double E = 2.71828182846;
public const double GoldenRatio = 1.61803398875; // (1 + Sqrt(5)) / 2 public const double GoldenRatio = 1.61803398875; // (1 + Sqrt(5)) / 2
@ -249,5 +249,4 @@
} }
public static double Tan(double radians) => Sin(radians) / Cos(radians); public static double Tan(double radians) => Sin(radians) / Cos(radians);
}
} }

View File

@ -1,6 +1,7 @@
global using System; global using System;
global using System.Collections; global using System.Collections;
global using System.Collections.Generic; global using System.Collections.Generic;
global using System.Diagnostics.CodeAnalysis;
global using System.IO; global using System.IO;
global using System.Linq; global using System.Linq;
global using System.Net.Http; global using System.Net.Http;