-
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.
- Loading branch information
Showing
11 changed files
with
230 additions
and
8 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
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,103 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using CitizenFX.Core; | ||
using GeoJSON.Text; | ||
using GeoJSON.Text.Feature; | ||
using GeoJSON.Text.Geometry; | ||
using PolyZone.Shapes.Interfaces; | ||
using Polygon = PolyZone.Shapes.Polygon; | ||
|
||
namespace PolyZone.Tests; | ||
|
||
public static class Helpers | ||
{ | ||
public static string GetPolygonArrayString(List<IPolygon> polygons) | ||
{ | ||
var resultBuilder = new StringBuilder(); | ||
|
||
for (var index = 0; index < polygons.Count; index++) | ||
{ | ||
var polygon = polygons[index]; | ||
|
||
resultBuilder.AppendLine($"[{index}]"); | ||
|
||
foreach (var point in polygon.Points) | ||
{ | ||
resultBuilder.AppendLine($" X: {point.X}, Y: {point.Y}"); | ||
} | ||
} | ||
|
||
return resultBuilder.ToString(); | ||
} | ||
|
||
public static IEnumerable<Vector2> GetPointsFromGeoCollection(FeatureCollection featureCollection) | ||
{ | ||
var points = new List<Vector2>(); | ||
|
||
foreach (var feature in featureCollection.Features) | ||
{ | ||
switch (feature.Geometry.Type) | ||
{ | ||
case GeoJSONObjectType.Point: | ||
{ | ||
var point = feature.Geometry as Point; | ||
|
||
points.Add(new Vector2 { X = (float) point.Coordinates.Longitude, Y = (float) point.Coordinates.Latitude }); | ||
|
||
break; | ||
} | ||
} | ||
} | ||
|
||
return points; | ||
} | ||
|
||
public static IEnumerable<Polygon> GetPolygonsFromGeoCollection(FeatureCollection featureCollection) | ||
{ | ||
var polygons = new List<Polygon>(); | ||
|
||
foreach (var feature in featureCollection.Features) | ||
{ | ||
switch (feature.Geometry.Type) | ||
{ | ||
case GeoJSONObjectType.MultiPolygon: | ||
{ | ||
var multiPolygon = feature.Geometry as MultiPolygon; | ||
foreach (var polygon in multiPolygon!.Coordinates) | ||
{ | ||
var points = new List<Vector2>(); | ||
|
||
foreach (var lines in polygon.Coordinates) | ||
{ | ||
foreach (var line in lines.Coordinates) | ||
{ | ||
points.Add(new Vector2 { X = (float) line.Longitude, Y = (float) line.Latitude }); | ||
} | ||
} | ||
|
||
polygons.Add(new Polygon(points)); | ||
} | ||
break; | ||
} | ||
case GeoJSONObjectType.Polygon: | ||
{ | ||
var polygon = feature.Geometry as GeoJSON.Text.Geometry.Polygon; | ||
|
||
var points = new List<Vector2>(); | ||
|
||
foreach (var line in polygon!.Coordinates.First().Coordinates) | ||
{ | ||
points.Add(new Vector2 { X = (float) line.Longitude, Y = (float) line.Latitude }); | ||
} | ||
|
||
polygons.Add(new Polygon(points)); | ||
|
||
break; | ||
} | ||
} | ||
} | ||
|
||
return polygons; | ||
} | ||
} |
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
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,42 @@ | ||
using CitizenFX.Core; | ||
using PolyZone.Shapes.Interfaces; | ||
|
||
namespace PolyZone.Shapes; | ||
|
||
public class Box(float x, float y, float z, float length, float width, float height) : IBox | ||
{ | ||
private readonly float _x = x; | ||
private readonly float _y = y; | ||
private readonly float _z = z; | ||
private readonly float _length = length; | ||
private readonly float _width = width; | ||
private readonly float _height = height; | ||
|
||
/// <summary> | ||
/// Calculated corners of the <see cref="Box"/>, starts with the Upper Left | ||
/// </summary> | ||
public Vector3[] Corners { get; } = | ||
[ | ||
// Upper face | ||
new Vector3 { X = x, Y = y, Z = z }, // Upper Left (Front) | ||
new Vector3 { X = x + length, Y = y, Z = z }, // Upper Right (Front) | ||
new Vector3 { X = x + length, Y = y + width, Z = z }, // Lower Right (Front) | ||
new Vector3 { X = x, Y = y + width, Z = z }, // Lower Left (Front) | ||
|
||
// Lower face | ||
new Vector3 { X = x, Y = y, Z = z + height }, // Upper Left (Back) | ||
new Vector3 { X = x + length, Y = y, Z = z + height }, // Upper Right (Back) | ||
new Vector3 { X = x + length, Y = y + width, Z = z + height }, // Lower Right (Back) | ||
new Vector3 { X = x, Y = y + width, Z = z + height } // Lower Left (Back) | ||
]; | ||
|
||
public Box(in Vector3 upperLeft, float length, float width, float height) : this(upperLeft.X, upperLeft.Y, upperLeft.Z, length, width, height) | ||
{ | ||
|
||
} | ||
|
||
public bool Contains(in Vector3 point) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} |
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; | ||
|
||
public interface IBox : 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 |
---|---|---|
@@ -1,6 +1,11 @@ | ||
namespace PolyZone.Shapes.Interfaces; | ||
using CitizenFX.Core; | ||
|
||
namespace PolyZone.Shapes.Interfaces; | ||
|
||
/// <summary> | ||
/// A 2d polygon | ||
/// </summary> | ||
public interface IPolygon : ISpatial2dShape; | ||
public interface IPolygon : ISpatial2dShape | ||
{ | ||
public IReadOnlyList<Vector2> Points { get; } | ||
} |
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,13 @@ | ||
using CitizenFX.Core; | ||
|
||
namespace PolyZone.Shapes.Interfaces; | ||
|
||
public interface ISpatial3dShape | ||
{ | ||
/// <summary> | ||
/// Spatially tests a given <see cref="Vector2"/> to determine if it lies within the shape | ||
/// </summary> | ||
/// <param name="point"><see cref="Vector2"/>, otherwise known as a 2d position</param> | ||
/// <returns>True if the <see cref="Vector2"/> is inside the shape</returns> | ||
bool Contains(in Vector3 point); | ||
} |
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