This repository has been archived by the owner on Jun 8, 2024. It is now read-only.
-
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.
add rebar group and polygon class (#3)
- Loading branch information
1 parent
5fb74f1
commit f3fcf51
Showing
5 changed files
with
844 additions
and
1 deletion.
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,100 @@ | ||
using System; | ||
using System.Linq; | ||
|
||
namespace Fluent.Structures.Model; | ||
|
||
/// <summary> | ||
/// Represents a Polygon in a Tekla Structures Model with fluent interface for construction. | ||
/// </summary> | ||
public class Polygon : IEnumerable<TSG.Point> | ||
{ | ||
/// <summary> | ||
/// Gets the Tekla Structures Polygon associated with this Polygon instance. | ||
/// </summary> | ||
public TSM.Polygon TeklaPolygon { get; } | ||
|
||
private Polygon() | ||
=> TeklaPolygon = new TSM.Polygon(); | ||
|
||
/// <summary> | ||
/// Builder class for creating a Polygon. | ||
/// Implements various interfaces for a fluent and type-safe construction process. | ||
/// </summary> | ||
public class BuildPolygon : IEmptyPolygon, ICompletedPolygon | ||
{ | ||
private readonly Polygon _polygon = new(); | ||
|
||
private BuildPolygon() {} | ||
|
||
/// <summary> | ||
/// Entry point to start configuring the Polygon class | ||
/// </summary> | ||
/// <returns>An interface for starting the construction process.</returns> | ||
public static IEmptyPolygon With() | ||
=> new BuildPolygon(); | ||
|
||
public ICompletedPolygon Points(ArrayList points) | ||
{ | ||
var list = new List<TSG.Point>(); | ||
|
||
foreach (var point in points) | ||
if (point is TSG.Point p) | ||
list.Add(p); | ||
else | ||
throw new ArgumentException( | ||
$"Array list contains {point.GetType()} which is not Tekla Structures Point" | ||
); | ||
|
||
_polygon.Points = list; | ||
return this; | ||
} | ||
|
||
public ICompletedPolygon Points(List<TSG.Point> points) | ||
{ | ||
_polygon.Points = points; | ||
return this; | ||
} | ||
|
||
public ICompletedPolygon Points(params TSG.Point[] points) | ||
{ | ||
_polygon.Points = points.ToList(); | ||
return this; | ||
} | ||
|
||
public Polygon Build() | ||
=> _polygon; | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets the points of the Polygon. | ||
/// </summary> | ||
public List<TSG.Point> Points | ||
{ | ||
get => new(TeklaPolygon.Points.Cast<TSG.Point>()); | ||
private set => TeklaPolygon.Points = new ArrayList(value); | ||
} | ||
|
||
/// <summary> | ||
/// Returns an enumerator that iterates through the points of the Polygon. | ||
/// </summary> | ||
public IEnumerator<TSG.Point> GetEnumerator() | ||
=> Points.GetEnumerator(); | ||
|
||
/// <summary> | ||
/// Returns an enumerator that iterates through the points of the Polygon. | ||
/// </summary> | ||
IEnumerator IEnumerable.GetEnumerator() | ||
Check failure on line 86 in src/Fluent.Structures.Model/Polygon.cs GitHub Actions / build
Check failure on line 86 in src/Fluent.Structures.Model/Polygon.cs GitHub Actions / build
|
||
=> GetEnumerator(); | ||
|
||
/// <summary> | ||
/// Implicitly converts a Polygon to a Tekla Structures Polygon. | ||
/// </summary> | ||
public static implicit operator TSM.Polygon(Polygon polygon) | ||
=> polygon.TeklaPolygon; | ||
|
||
/// <summary> | ||
/// Implicitly converts a Tekla Structures Polygon to a Polygon. | ||
/// </summary> | ||
public static implicit operator Polygon(TSM.Polygon polygon) | ||
=> BuildPolygon.With().Points(polygon.Points).Build(); | ||
} |
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,37 @@ | ||
namespace Fluent.Structures.Model; | ||
|
||
/// <summary> | ||
/// Represents an interface for starting the construction of a Polygon with the builder pattern. | ||
/// </summary> | ||
public interface IEmptyPolygon | ||
{ | ||
/// <summary> | ||
/// Sets the points of the Polygon from an ArrayList. | ||
/// </summary> | ||
/// <param name="points">ArrayList of points to set.</param> | ||
public ICompletedPolygon Points(ArrayList points); | ||
|
||
/// <summary> | ||
/// Sets the points of the Polygon from a List of TSG.Points. | ||
/// </summary> | ||
/// <param name="points">List of points to set.</param> | ||
public ICompletedPolygon Points(List<TSG.Point> points); | ||
|
||
/// <summary> | ||
/// Sets the points of the Polygon from an array of TSG.Points. | ||
/// </summary> | ||
/// <param name="points">Array of points to set.</param> | ||
public ICompletedPolygon Points(params TSG.Point[] points); | ||
} | ||
|
||
/// <summary> | ||
/// Represents an interface for finalizing the construction of a Polygon with the builder pattern. | ||
/// </summary> | ||
public interface ICompletedPolygon | ||
{ | ||
/// <summary> | ||
/// Finalizes the construction and returns the Polygon object. | ||
/// </summary> | ||
/// <returns>The finalized Polygon object.</returns> | ||
public Polygon Build(); | ||
} |
Oops, something went wrong.