| | | 1 | | //======================================================================= |
| | | 2 | | // GridTopologyFactory.cs |
| | | 3 | | //======================================================================= |
| | | 4 | | // MIT License, Copyright (c) 2024–present David Oravsky (mrdav30) |
| | | 5 | | // See LICENSE file in the project root for full license information. |
| | | 6 | | //======================================================================= |
| | | 7 | | |
| | | 8 | | using GridForge.Configuration; |
| | | 9 | | |
| | | 10 | | namespace GridForge.Grids.Topology; |
| | | 11 | | |
| | | 12 | | internal static class GridTopologyFactory |
| | | 13 | | { |
| | | 14 | | public static bool TryCreate(GridConfiguration configuration, out IGridTopology? topology) |
| | | 15 | | { |
| | 434 | 16 | | topology = null; |
| | | 17 | | |
| | 434 | 18 | | switch (configuration.TopologyKind) |
| | | 19 | | { |
| | | 20 | | case GridTopologyKind.RectangularPrism: |
| | | 21 | | { |
| | 369 | 22 | | if (!GridTopologyMetrics.IsValid(configuration.TopologyKind, configuration.TopologyMetrics)) |
| | | 23 | | { |
| | 3 | 24 | | GridForgeLogger.Channel.Warn($"Rectangular-prism topology requires positive cell width, layer he |
| | 3 | 25 | | return false; |
| | | 26 | | } |
| | | 27 | | |
| | 366 | 28 | | topology = new RectangularPrismTopology(configuration.TopologyMetrics); |
| | 366 | 29 | | return true; |
| | | 30 | | } |
| | | 31 | | case GridTopologyKind.HexPrism: |
| | | 32 | | { |
| | 62 | 33 | | if (!GridTopologyMetrics.IsValid(configuration.TopologyKind, configuration.TopologyMetrics)) |
| | | 34 | | { |
| | 5 | 35 | | GridForgeLogger.Channel.Warn($"Hex-prism topology requires positive cell radius and layer height |
| | 5 | 36 | | return false; |
| | | 37 | | } |
| | | 38 | | |
| | 57 | 39 | | topology = new HexPrismTopology(configuration.TopologyMetrics); |
| | 57 | 40 | | return true; |
| | | 41 | | } |
| | | 42 | | default: |
| | 3 | 43 | | GridForgeLogger.Channel.Warn($"Grid topology '{configuration.TopologyKind}' is not implemented."); |
| | 3 | 44 | | return false; |
| | | 45 | | } |
| | | 46 | | } |
| | | 47 | | } |