Skip to content
This repository has been archived by the owner on Jun 8, 2024. It is now read-only.

Commit

Permalink
add rebar group and polygon class (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
molostovvs authored Nov 21, 2023
1 parent 5fb74f1 commit f3fcf51
Show file tree
Hide file tree
Showing 5 changed files with 844 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Fluent.Structures.Model/Fluent.Structures.Model.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<Nullable>enable</Nullable>
<LangVersion>latestmajor</LangVersion>
<PackageId>Fluent.Structures.Model</PackageId>
<Version>0.1.2</Version>
<Version>0.2.0</Version>
<Authors>ConcreteEcho</Authors>
<Product>Fluent.Structures.Model</Product>
<Title>Fluent.Structures.Model</Title>
Expand Down
100 changes: 100 additions & 0 deletions src/Fluent.Structures.Model/Polygon.cs
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

View workflow job for this annotation

GitHub Actions / build

Using the generic type 'IEnumerable<T>' requires 1 type arguments

Check failure on line 86 in src/Fluent.Structures.Model/Polygon.cs

View workflow job for this annotation

GitHub Actions / build

Using the generic type 'IEnumerator<T>' requires 1 type arguments

Check failure on line 86 in src/Fluent.Structures.Model/Polygon.cs

View workflow job for this annotation

GitHub Actions / build

'IEnumerable' in explicit interface declaration is not an interface
=> 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();
}
37 changes: 37 additions & 0 deletions src/Fluent.Structures.Model/PolygonBuilderInterfaces.cs
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);

Check failure on line 12 in src/Fluent.Structures.Model/PolygonBuilderInterfaces.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'ArrayList' could not be found (are you missing a using directive or an assembly reference?)

/// <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();
}
Loading

0 comments on commit f3fcf51

Please sign in to comment.