From de13e8edcca6ca59b4e72cc6eb87171d82a4212f Mon Sep 17 00:00:00 2001 From: "Nathan Alden, Sr" <1189759+nathan-alden-sr@users.noreply.github.com> Date: Sat, 23 Oct 2021 11:46:47 -0400 Subject: [PATCH] #656 Helper constructors --- src/Maths/Silk.NET.Maths/Box2D.cs | 38 ++++++++++++++++- src/Maths/Silk.NET.Maths/Box3D.cs | 42 ++++++++++++++++++- src/Maths/Silk.NET.Maths/Circle.cs | 11 +++++ src/Maths/Silk.NET.Maths/Cube.cs | 40 +++++++++++++++++- .../Silk.NET.Maths/PublicAPI.Shipped.txt | 20 +++++++++ src/Maths/Silk.NET.Maths/Ray2D.cs | 34 +++++++++++++++ src/Maths/Silk.NET.Maths/Ray3D.cs | 38 +++++++++++++++++ src/Maths/Silk.NET.Maths/Rectangle.cs | 36 +++++++++++++++- src/Maths/Silk.NET.Maths/Sphere.cs | 12 ++++++ 9 files changed, 265 insertions(+), 6 deletions(-) diff --git a/src/Maths/Silk.NET.Maths/Box2D.cs b/src/Maths/Silk.NET.Maths/Box2D.cs index 865328242b..3b24ab441d 100644 --- a/src/Maths/Silk.NET.Maths/Box2D.cs +++ b/src/Maths/Silk.NET.Maths/Box2D.cs @@ -30,14 +30,48 @@ public struct Box2D /// /// Constructs a Box2D from a min and a max /// - /// The min of the rect. - /// The max of the rect. + /// The min of the box. + /// The max of the box. public Box2D(Vector2D min, Vector2D max) { Min = min; Max = max; } + /// + /// Constructs a Box2D from a min and components of a max + /// + /// The min of the box. + /// The max X component of the box. + /// The max Y component of the box. + public Box2D(Vector2D min, T maxX, T maxY) + : this(min, new Vector2D(maxX, maxY)) + { + } + + /// + /// Constructs a Box2D from components of a min and a max + /// + /// The min X component of the box. + /// The min Y component of the box. + /// The max of the box. + public Box2D(T minX, T minY, Vector2D max) + : this(new Vector2D(minX, minY), max) + { + } + + /// + /// Constructs a Box2D from components of a min and components of a max + /// + /// The min X component of the box. + /// The min Y component of the box. + /// The max X component of the box. + /// The max Y component of the box. + public Box2D(T minX, T minY, T maxX, T maxY) + : this(new Vector2D(minX, minY), new Vector2D(maxX, maxY)) + { + } + /// /// The center of this box. /// diff --git a/src/Maths/Silk.NET.Maths/Box3D.cs b/src/Maths/Silk.NET.Maths/Box3D.cs index 86a499b996..a3d386d067 100644 --- a/src/Maths/Silk.NET.Maths/Box3D.cs +++ b/src/Maths/Silk.NET.Maths/Box3D.cs @@ -30,14 +30,52 @@ public struct Box3D /// /// Constructs a Box3D from a min and a max /// - /// The min of the rect. - /// The max of the rect. + /// The min of the box. + /// The max of the box. public Box3D(Vector3D min, Vector3D max) { Min = min; Max = max; } + /// + /// Constructs a Box3D from a min and components of a max + /// + /// The min of the box. + /// The max X component of the box. + /// The max Y component of the box. + /// The max Z component of the box. + public Box3D(Vector3D min, T maxX, T maxY, T maxZ) + : this(min, new Vector3D(maxX, maxY, maxZ)) + { + } + + /// + /// Constructs a Box3D from components of a min and a max + /// + /// The min X component of the box. + /// The min Y component of the box. + /// The min Z component of the box. + /// The max of the box. + public Box3D(T minX, T minY, T minZ, Vector3D max) + : this(new Vector3D(minX, minY, minZ), max) + { + } + + /// + /// Constructs a Box3D from components of a min and a max + /// + /// The min X component of the box. + /// The min Y component of the box. + /// The min Z component of the box. + /// The max X component of the box. + /// The max Y component of the box. + /// The max Z component of the box. + public Box3D(T minX, T minY, T minZ, T maxX, T maxY, T maxZ) + : this(new Vector3D(minX, minY, minZ), new Vector3D(maxX, maxY, maxZ)) + { + } + /// /// The center of this box. /// diff --git a/src/Maths/Silk.NET.Maths/Circle.cs b/src/Maths/Silk.NET.Maths/Circle.cs index 42044aaa2c..fafcc12f4d 100644 --- a/src/Maths/Silk.NET.Maths/Circle.cs +++ b/src/Maths/Silk.NET.Maths/Circle.cs @@ -36,6 +36,17 @@ public Circle(Vector2D center, T radius) Radius = radius; } + /// + /// Constructs a circle from components of a center and a + /// + /// The X component of the center. + /// The Y component of the center. + /// The radius. + public Circle(T centerX, T centerY, T radius) + : this(new Vector2D(centerX, centerY), radius) + { + } + /// /// The diameter. /// diff --git a/src/Maths/Silk.NET.Maths/Cube.cs b/src/Maths/Silk.NET.Maths/Cube.cs index 33ef772565..c5ef00cca7 100644 --- a/src/Maths/Silk.NET.Maths/Cube.cs +++ b/src/Maths/Silk.NET.Maths/Cube.cs @@ -28,7 +28,7 @@ public struct Cube public Vector3D Size; /// - /// Constructs a Cube from an origin and it's size + /// Constructs a Cube from an origin and a size /// /// The origin of the cube. /// The size of the cube. @@ -38,6 +38,44 @@ public Cube(Vector3D origin, Vector3D size) Size = size; } + /// + /// Constructs a Cube from an origin and components of a size + /// + /// The origin of the cube. + /// The X component of the size of the cube. + /// The Y component of the size of the cube. + /// The Z component of the size of the cube. + public Cube(Vector3D origin, T sizeX, T sizeY, T sizeZ) + : this(origin, new Vector3D(sizeX, sizeY, sizeZ)) + { + } + + /// + /// Constructs a Cube from components of an origin and a size + /// + /// The X component of the origin of the cube. + /// The Y component of the origin of the cube. + /// The Z component of the origin of the cube. + /// The size of the cube. + public Cube(T originX, T originY, T originZ, Vector3D size) + : this(new Vector3D(originX, originY, originZ), size) + { + } + + /// + /// Constructs a Cube from components of an origin and components of a size + /// + /// The X component of the origin of the cube. + /// The Y component of the origin of the cube. + /// The Z component of the origin of the cube. + /// The X component of the size of the cube. + /// The Y component of the size of the cube. + /// The Z component of the size of the cube. + public Cube(T originX, T originY, T originZ, T sizeX, T sizeY, T sizeZ) + : this(new Vector3D(originX, originY, originZ), new Vector3D(sizeX, sizeY, sizeZ)) + { + } + /// /// The center of this cube. /// diff --git a/src/Maths/Silk.NET.Maths/PublicAPI.Shipped.txt b/src/Maths/Silk.NET.Maths/PublicAPI.Shipped.txt index dade5ed786..2e35936b4a 100644 --- a/src/Maths/Silk.NET.Maths/PublicAPI.Shipped.txt +++ b/src/Maths/Silk.NET.Maths/PublicAPI.Shipped.txt @@ -60,6 +60,9 @@ override Silk.NET.Maths.Vector4D.ToString() -> string! Silk.NET.Maths.Box2D Silk.NET.Maths.Box2D.Box2D() -> void Silk.NET.Maths.Box2D.Box2D(Silk.NET.Maths.Vector2D min, Silk.NET.Maths.Vector2D max) -> void +Silk.NET.Maths.Box2D.Box2D(Silk.NET.Maths.Vector2D min, T maxX, T maxY) -> void +Silk.NET.Maths.Box2D.Box2D(T minX, T minY, Silk.NET.Maths.Vector2D max) -> void +Silk.NET.Maths.Box2D.Box2D(T minX, T minY, T maxX, T maxY) -> void Silk.NET.Maths.Box2D.Center.get -> Silk.NET.Maths.Vector2D Silk.NET.Maths.Box2D.Contains(Silk.NET.Maths.Box2D other) -> bool Silk.NET.Maths.Box2D.Contains(Silk.NET.Maths.Vector2D point) -> bool @@ -74,6 +77,9 @@ Silk.NET.Maths.Box2D.Size.get -> Silk.NET.Maths.Vector2D Silk.NET.Maths.Box3D Silk.NET.Maths.Box3D.Box3D() -> void Silk.NET.Maths.Box3D.Box3D(Silk.NET.Maths.Vector3D min, Silk.NET.Maths.Vector3D max) -> void +Silk.NET.Maths.Box3D.Box3D(Silk.NET.Maths.Vector3D min, T maxX, T maxY, T maxZ) -> void +Silk.NET.Maths.Box3D.Box3D(T minX, T minY, T minZ, Silk.NET.Maths.Vector3D max) -> void +Silk.NET.Maths.Box3D.Box3D(T minX, T minY, T minZ, T maxX, T maxY, T maxZ) -> void Silk.NET.Maths.Box3D.Center.get -> Silk.NET.Maths.Vector3D Silk.NET.Maths.Box3D.Contains(Silk.NET.Maths.Box3D other) -> bool Silk.NET.Maths.Box3D.Contains(Silk.NET.Maths.Vector3D point) -> bool @@ -89,6 +95,7 @@ Silk.NET.Maths.Circle Silk.NET.Maths.Circle.Center -> Silk.NET.Maths.Vector2D Silk.NET.Maths.Circle.Circle() -> void Silk.NET.Maths.Circle.Circle(Silk.NET.Maths.Vector2D center, T radius) -> void +Silk.NET.Maths.Circle.Circle(T centerX, T centerY, T radius) -> void Silk.NET.Maths.Circle.Circumference.get -> T Silk.NET.Maths.Circle.Contains(Silk.NET.Maths.Circle other) -> bool Silk.NET.Maths.Circle.Contains(Silk.NET.Maths.Vector2D point) -> bool @@ -106,6 +113,9 @@ Silk.NET.Maths.Cube.Contains(Silk.NET.Maths.Cube other) -> bool Silk.NET.Maths.Cube.Contains(Silk.NET.Maths.Vector3D point) -> bool Silk.NET.Maths.Cube.Cube() -> void Silk.NET.Maths.Cube.Cube(Silk.NET.Maths.Vector3D origin, Silk.NET.Maths.Vector3D size) -> void +Silk.NET.Maths.Cube.Cube(Silk.NET.Maths.Vector3D origin, T sizeX, T sizeY, T sizeZ) -> void +Silk.NET.Maths.Cube.Cube(T originX, T originY, T originZ, Silk.NET.Maths.Vector3D size) -> void +Silk.NET.Maths.Cube.Cube(T originX, T originY, T originZ, T sizeX, T sizeY, T sizeZ) -> void Silk.NET.Maths.Cube.Equals(Silk.NET.Maths.Cube other) -> bool Silk.NET.Maths.Cube.GetDistanceToNearestEdge(Silk.NET.Maths.Vector3D point) -> T Silk.NET.Maths.Cube.GetInflated(Silk.NET.Maths.Vector3D point) -> Silk.NET.Maths.Cube @@ -495,6 +505,9 @@ Silk.NET.Maths.Ray2D.GetPoint(T distance) -> Silk.NET.Maths.Vector2D Silk.NET.Maths.Ray2D.Origin -> Silk.NET.Maths.Vector2D Silk.NET.Maths.Ray2D.Ray2D() -> void Silk.NET.Maths.Ray2D.Ray2D(Silk.NET.Maths.Vector2D origin, Silk.NET.Maths.Vector2D direction) -> void +Silk.NET.Maths.Ray2D.Ray2D(Silk.NET.Maths.Vector2D origin, T directionX, T directionY) -> void +Silk.NET.Maths.Ray2D.Ray2D(T originX, T originY, Silk.NET.Maths.Vector2D direction) -> void +Silk.NET.Maths.Ray2D.Ray2D(T originX, T originY, T directionX, T directionY) -> void Silk.NET.Maths.Ray3D Silk.NET.Maths.Ray3D.Direction -> Silk.NET.Maths.Vector3D Silk.NET.Maths.Ray3D.Equals(Silk.NET.Maths.Ray3D other) -> bool @@ -502,6 +515,9 @@ Silk.NET.Maths.Ray3D.GetPoint(T distance) -> Silk.NET.Maths.Vector3D Silk.NET.Maths.Ray3D.Origin -> Silk.NET.Maths.Vector3D Silk.NET.Maths.Ray3D.Ray3D() -> void Silk.NET.Maths.Ray3D.Ray3D(Silk.NET.Maths.Vector3D origin, Silk.NET.Maths.Vector3D direction) -> void +Silk.NET.Maths.Ray3D.Ray3D(Silk.NET.Maths.Vector3D origin, T directionX, T directionY, T directionZ) -> void +Silk.NET.Maths.Ray3D.Ray3D(T originX, T originY, T originZ, Silk.NET.Maths.Vector3D direction) -> void +Silk.NET.Maths.Ray3D.Ray3D(T originX, T originY, T originZ, T directionX, T directionY, T directionZ) -> void Silk.NET.Maths.Rectangle Silk.NET.Maths.Rectangle Silk.NET.Maths.Rectangle.Center.get -> Silk.NET.Maths.Vector2D @@ -517,6 +533,9 @@ Silk.NET.Maths.Rectangle.Max.get -> Silk.NET.Maths.Vector2D Silk.NET.Maths.Rectangle.Origin -> Silk.NET.Maths.Vector2D Silk.NET.Maths.Rectangle.Rectangle() -> void Silk.NET.Maths.Rectangle.Rectangle(Silk.NET.Maths.Vector2D origin, Silk.NET.Maths.Vector2D size) -> void +Silk.NET.Maths.Rectangle.Rectangle(Silk.NET.Maths.Vector2D origin, T sizeX, T sizeY) -> void +Silk.NET.Maths.Rectangle.Rectangle(T originX, T originY, Silk.NET.Maths.Vector2D size) -> void +Silk.NET.Maths.Rectangle.Rectangle(T originX, T originY, T sizeX, T sizeY) -> void Silk.NET.Maths.Rectangle.Size -> Silk.NET.Maths.Vector2D Silk.NET.Maths.Scalar Silk.NET.Maths.Scalar @@ -533,6 +552,7 @@ Silk.NET.Maths.Sphere.GetTranslated(Silk.NET.Maths.Vector3D distance) -> S Silk.NET.Maths.Sphere.Radius -> T Silk.NET.Maths.Sphere.Sphere() -> void Silk.NET.Maths.Sphere.Sphere(Silk.NET.Maths.Vector3D center, T radius) -> void +Silk.NET.Maths.Sphere.Sphere(T centerX, T centerY, T centerZ, T radius) -> void Silk.NET.Maths.Sphere.SquaredRadius.get -> T Silk.NET.Maths.SystemNumericsExtensions Silk.NET.Maths.Vector2D diff --git a/src/Maths/Silk.NET.Maths/Ray2D.cs b/src/Maths/Silk.NET.Maths/Ray2D.cs index 8ab9ee06ef..91b181f2fd 100644 --- a/src/Maths/Silk.NET.Maths/Ray2D.cs +++ b/src/Maths/Silk.NET.Maths/Ray2D.cs @@ -39,6 +39,40 @@ public Ray2D(Vector2D origin, Vector2D direction) Direction = direction; } + /// + /// Constructs a Ray using an origin and components of a direction. + /// + /// The origin of the ray. + /// The X component of the direction of the ray. + /// The Y component of the direction of the ray. + public Ray2D(Vector2D origin, T directionX, T directionY) + : this(origin, new Vector2D(directionX, directionY)) + { + } + + /// + /// Constructs a Ray using components of an origin and a direction. + /// + /// The X component of the origin of the ray. + /// The Y component of the origin of the ray. + /// The direction of the ray. + public Ray2D(T originX, T originY, Vector2D direction) + : this(new Vector2D(originX, originY), direction) + { + } + + /// + /// Constructs a Ray using components of an origin and components of a direction. + /// + /// The X component of the origin of the ray. + /// The Y component of the origin of the ray. + /// The X component of the direction of the ray. + /// The Y component of the direction of the ray. + public Ray2D(T originX, T originY, T directionX, T directionY) + : this(new Vector2D(originX, originY), new Vector2D(directionX, directionY)) + { + } + /// /// Calculates a point at a distance along the ray. /// diff --git a/src/Maths/Silk.NET.Maths/Ray3D.cs b/src/Maths/Silk.NET.Maths/Ray3D.cs index 87e9f064a8..14797d6756 100644 --- a/src/Maths/Silk.NET.Maths/Ray3D.cs +++ b/src/Maths/Silk.NET.Maths/Ray3D.cs @@ -39,6 +39,44 @@ public Ray3D(Vector3D origin, Vector3D direction) Direction = direction; } + /// + /// Constructs a Ray using an origin and components of a direction. + /// + /// The origin of the ray. + /// The X component of the direction of the ray. + /// The Y component of the direction of the ray. + /// The Z component of the direction of the ray. + public Ray3D(Vector3D origin, T directionX, T directionY, T directionZ) + : this(origin, new Vector3D(directionX, directionY, directionZ)) + { + } + + /// + /// Constructs a Ray using components of an origin and a direction. + /// + /// The X component of the origin of the ray. + /// The Y component of the origin of the ray. + /// The Z component of the origin of the ray. + /// The direction of the ray. + public Ray3D(T originX, T originY, T originZ, Vector3D direction) + : this(new Vector3D(originX, originY, originZ), direction) + { + } + + /// + /// Constructs a Ray using components of an origin and components of a direction. + /// + /// The X component of the origin of the ray. + /// The Y component of the origin of the ray. + /// The Z component of the origin of the ray. + /// The X component of the direction of the ray. + /// The Y component of the direction of the ray. + /// The Z component of the direction of the ray. + public Ray3D(T originX, T originY, T originZ, T directionX, T directionY, T directionZ) + : this(new Vector3D(originX, originY, originZ), new Vector3D(directionX, directionY, directionZ)) + { + } + /// /// Calculates a point at a distance along the ray. /// diff --git a/src/Maths/Silk.NET.Maths/Rectangle.cs b/src/Maths/Silk.NET.Maths/Rectangle.cs index 9b2dba39cf..344d8f02a9 100644 --- a/src/Maths/Silk.NET.Maths/Rectangle.cs +++ b/src/Maths/Silk.NET.Maths/Rectangle.cs @@ -27,7 +27,7 @@ public struct Rectangle public Vector2D Size; /// - /// Constructs a Rectangle from an origin and an size + /// Constructs a Rectangle from an origin and a size /// /// The origin of the rect. /// The size of the rect. @@ -37,6 +37,40 @@ public Rectangle(Vector2D origin, Vector2D size) Size = size; } + /// + /// Constructs a Rectangle from an origin and components of a size + /// + /// The origin of the rect. + /// The X component of the size of the rect. + /// The Y component of the size of the rect. + public Rectangle(Vector2D origin, T sizeX, T sizeY) + : this(origin, new Vector2D(sizeX, sizeY)) + { + } + + /// + /// Constructs a Rectangle from components of an origin and a size + /// + /// The X component of the origin of the rect. + /// The Y component of the origin of the rect. + /// The size of the rect. + public Rectangle(T originX, T originY, Vector2D size) + : this(new Vector2D(originX, originY), size) + { + } + + /// + /// Constructs a Rectangle from components of an origin and components of a size + /// + /// The X component of the origin of the rect. + /// The Y component of the origin of the rect. + /// The X component of the size of the rect. + /// The Y component of the size of the rect. + public Rectangle(T originX, T originY, T sizeX, T sizeY) + : this(new Vector2D(originX, originY), new Vector2D(sizeX, sizeY)) + { + } + /// /// The center of this rectangle. /// diff --git a/src/Maths/Silk.NET.Maths/Sphere.cs b/src/Maths/Silk.NET.Maths/Sphere.cs index b548fe6dbf..5985308774 100644 --- a/src/Maths/Silk.NET.Maths/Sphere.cs +++ b/src/Maths/Silk.NET.Maths/Sphere.cs @@ -36,6 +36,18 @@ public Sphere(Vector3D center, T radius) Radius = radius; } + /// + /// Constructs a sphere from components of a center and a + /// + /// The X component of the center. + /// The Y component of the center. + /// The Z component of the center. + /// The radius. + public Sphere(T centerX, T centerY, T centerZ, T radius) + : this(new Vector3D(centerX, centerY, centerZ), radius) + { + } + /// /// The diameter. ///