-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/Twinki14/CitizenFX.Extensio…
- Loading branch information
Showing
12 changed files
with
156 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using CitizenFX.Core; | ||
using PolyZone.Shapes.Interfaces; | ||
|
||
namespace PolyZone.Extensions; | ||
|
||
public static class Vector3Extensions | ||
{ | ||
public static bool IsInside(this Vector3 vector2, in ISpatial3dShape shape) => shape.Contains(vector2); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using CitizenFX.Core; | ||
using PolyZone.Shapes.Interfaces; | ||
|
||
namespace PolyZone.Shapes; | ||
|
||
/// <summary> | ||
/// A 3d cuboid shape, constructed from an upper left 3d point | ||
/// </summary> | ||
/// <param name="upperLeft">Upper left point</param> | ||
/// <param name="length">Length of the cuboid</param> | ||
/// <param name="width">Width of the cuboid</param> | ||
/// <param name="height">Height of the cuboid</param> | ||
public class Cuboid(in Vector3 upperLeft, float length, float width, float height) : ICuboid | ||
{ | ||
public Vector3 UpperLeft { get; } = upperLeft; | ||
public float Length { get; } = length; | ||
public float Width { get; } = width; | ||
public float Height { get; } = height; | ||
|
||
/// <summary> | ||
/// Calculated corners of the <see cref="Cuboid"/>, starts with the Upper Left | ||
/// </summary> | ||
public Vector3[] Corners { get; } = | ||
[ | ||
// Upper face | ||
new Vector3 { X = upperLeft.X, Y = upperLeft.Y, Z = upperLeft.Z }, // Upper Left (Front) | ||
new Vector3 { X = upperLeft.X + length, Y = upperLeft.Y, Z = upperLeft.Z }, // Upper Right (Front) | ||
new Vector3 { X = upperLeft.X + length, Y = upperLeft.Y + width, Z = upperLeft.Z }, // Lower Right (Front) | ||
new Vector3 { X = upperLeft.X, Y = upperLeft.Y + width, Z = upperLeft.Z }, // Lower Left (Front) | ||
|
||
// Lower face | ||
new Vector3 { X = upperLeft.X, Y = upperLeft.Y, Z = upperLeft.Z + height }, // Upper Left (Back) | ||
new Vector3 { X = upperLeft.X + length, Y = upperLeft.Y, Z = upperLeft.Z + height }, // Upper Right (Back) | ||
new Vector3 { X = upperLeft.X + length, Y = upperLeft.Y + width, Z = upperLeft.Z + height }, // Lower Right (Back) | ||
new Vector3 { X = upperLeft.X, Y = upperLeft.Y + width, Z = upperLeft.Z + height } // Lower Left (Back) | ||
]; | ||
|
||
/// <inheritdoc cref="ISpatial3dShape.Contains"/> | ||
public bool Contains(in Vector3 point) | ||
{ | ||
// Check if the point is within the bounds defined by the corners of the cuboid | ||
return point.X >= UpperLeft.X && point.X <= UpperLeft.X + Length && | ||
point.Y >= UpperLeft.Y && point.Y <= UpperLeft.Y + Width && | ||
point.Z >= UpperLeft.Z && point.Z <= UpperLeft.Z + Height; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace PolyZone.Shapes.Interfaces; | ||
|
||
/// <summary> | ||
/// A 3d cuboid shape | ||
/// </summary> | ||
public interface ICuboid : ISpatial3dShape; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace PolyZone.Shapes.Interfaces; | ||
|
||
/// <summary> | ||
/// A 2d rectangle / box | ||
/// </summary> | ||
public interface IRectangle : ISpatial2dShape; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace PolyZone.Shapes.Interfaces; | ||
|
||
/// <summary> | ||
/// A 3d spherical shape | ||
/// </summary> | ||
public interface ISphere : ISpatial3dShape; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using CitizenFX.Core; | ||
using PolyZone.Shapes.Interfaces; | ||
|
||
namespace PolyZone.Shapes; | ||
|
||
/// <summary> | ||
/// A 2d rectangular shape, constructed from an upperLeft and bottomRight point | ||
/// </summary> | ||
/// <param name="upperLeft">Upper left point of the rectangle</param> | ||
/// <param name="bottomRight">Bottom right point of the rectangle</param> | ||
public class Rectangle(in Vector2 upperLeft, in Vector2 bottomRight) : IRectangle | ||
{ | ||
public Vector2 UpperLeft { get; } = upperLeft; | ||
public Vector2 BottomRight { get; } = bottomRight; | ||
|
||
/// <inheritdoc cref="ISpatial2dShape.Contains"/> | ||
public bool Contains(in Vector2 point) | ||
{ | ||
return point.X >= UpperLeft.X && point.X <= BottomRight.X && | ||
point.Y >= UpperLeft.Y && point.Y <= BottomRight.Y; | ||
} | ||
|
||
/// <inheritdoc cref="ISpatial2dShape.DistanceFrom"/> | ||
public float DistanceFrom(in Vector2 point) | ||
{ | ||
// Calculate the distance using Euclidean distance formula | ||
var dx = Math.Max(Math.Max(UpperLeft.X - point.X, 0), point.X - BottomRight.X); | ||
var dy = Math.Max(Math.Max(UpperLeft.Y - point.Y, 0), point.Y - BottomRight.Y); | ||
|
||
return (float) Math.Sqrt(dx * dx + dy * dy); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using CitizenFX.Core; | ||
using PolyZone.Shapes.Interfaces; | ||
|
||
namespace PolyZone.Shapes; | ||
|
||
/// <summary> | ||
/// A 3d sphere constructed from a center 3d point and a radius | ||
/// </summary> | ||
/// <param name="center">Center of the sphere</param> | ||
/// <param name="radius">Radius of the sphere</param> | ||
public class Sphere(in Vector3 center, float radius) : ISphere | ||
{ | ||
public Vector3 Center { get; } = center; | ||
public float Radius { get; } = radius; | ||
|
||
/// <inheritdoc cref="ISpatial3dShape.Contains"/> | ||
public bool Contains(in Vector3 point) | ||
{ | ||
// Calculate the distance from the center of the sphere to the given point | ||
var distance = (float) Math.Sqrt(Math.Pow(point.X - Center.X, 2) + Math.Pow(point.Y - Center.Y, 2) + Math.Pow(point.Z - Center.Z, 2)); | ||
|
||
// Check if the distance is less than or equal to the radius | ||
return distance <= Radius; | ||
|
||
} | ||
} |