Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit configs based on ConfigId property #88

Merged
merged 4 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions LayoutFunctions/ClassroomLayout/dependencies/SpaceBoundary.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
using Elements.Geometry;
using Newtonsoft.Json;

namespace Elements
{
public partial class SpaceBoundary : GeometricElement, ISpaceBoundary
{
public Vector3? ParentCentroid { get; set; }

[JsonProperty("Config Id")]
public string ConfigId { get; set; }
}
}
4 changes: 4 additions & 0 deletions LayoutFunctions/CustomLayout/dependencies/SpaceBoundary.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
using Elements.Geometry;
using Newtonsoft.Json;

namespace Elements
{
public partial class SpaceBoundary : GeometricElement, ISpaceBoundary
{
public Vector3? ParentCentroid { get; set; }

[JsonProperty("Config Id")]
public string ConfigId { get; set; }
}
}
3 changes: 3 additions & 0 deletions LayoutFunctions/LayoutFunctionCommon/ISpaceBoundary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ public interface ISpaceBoundary

public string DefaultWallType { get; set; }

[JsonProperty("Config Id", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public string ConfigId { get; set; }

}

}
10 changes: 8 additions & 2 deletions LayoutFunctions/LayoutFunctionCommon/LayoutGeneration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,20 @@ public virtual LayoutGenerationResult StandardLayoutOnAllLevels(string programTy
};
boundaryCurves.AddRange(spaceBoundary.Voids ?? new List<Polygon>());

var configsForRoom = configs;
if (room.ConfigId != null)
{
configsForRoom = LayoutStrategies.LimitConfigsToId(configs, room, wallCandidateOptions);
}

var possibleConfigs = new List<(ConfigInfo configInfo, List<RoomEdge> wallCandidates)>();
foreach (var (OrientationGuideEdge, WallCandidates) in wallCandidateOptions)
{
var orientationTransform = new Transform(Vector3.Origin, OrientationGuideEdge.Direction, Vector3.ZAxis);
var grid = new Grid2d(boundaryCurves, orientationTransform);
foreach (var cell in grid.GetCells())
{
var config = FindConfigByFit(configs, cell);
var config = FindConfigByFit(configsForRoom, cell);
if (config != null)
{
possibleConfigs.Add((config.Value, WallCandidates));
Expand Down Expand Up @@ -238,7 +244,7 @@ protected virtual SpaceConfiguration DeserializeConfigJson(string configJson)
KeyValuePair<string, ContentConfiguration>? selectedConfigPair = null;
foreach (var configPair in orderedConfigs)
{
if (configPair.Value.CellBoundary.Width < width && configPair.Value.CellBoundary.Depth < length)
if (configPair.Value.CellBoundary.Width < (width + Vector3.EPSILON) && configPair.Value.CellBoundary.Depth < (length + Vector3.EPSILON))
{
selectedConfigPair = configPair;
break;
Expand Down
40 changes: 39 additions & 1 deletion LayoutFunctions/LayoutFunctionCommon/LayoutStrategies.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,13 @@ public static HashSet<Guid> StandardLayoutOnAllLevels<TLevelElements, TLevelVolu
foreach (var room in roomBoundaries)
{
var wallCandidateLines = new List<RoomEdge>();
var layoutSucceeded = ProcessRoom(room, outputModel, countSeats, configs, corridorSegments, levelVolume, wallCandidateLines);

var configsForRoom = configs;
if (room.ConfigId != null)
{
configsForRoom = LimitConfigsToId(configs, room);
}
var layoutSucceeded = ProcessRoom(room, outputModel, countSeats, configsForRoom, corridorSegments, levelVolume, wallCandidateLines);
if (layoutSucceeded) { processedSpaces.Add(room.Id); }

double height = room.Height == 0 ? 3 : room.Height;
Expand Down Expand Up @@ -240,6 +246,38 @@ public static HashSet<Guid> StandardLayoutOnAllLevels<TLevelElements, TLevelVolu
return processedSpaces;
}

/// <summary>
/// Pringle-specific behavior to pick a specific config and orientation. This code only executes if the room has a `ConfigId` property, which is only set on pringle.
/// </summary>
public static SpaceConfiguration LimitConfigsToId<TSpaceBoundary>(SpaceConfiguration originalConfigs, TSpaceBoundary room, List<(RoomEdge OrientationGuideEdge, List<RoomEdge> WallCandidates)> wallCandidateOptions = null) where TSpaceBoundary : Element, ISpaceBoundary
{
// If a set of wall candidate options are provided, limit to the one that aligns with the boundary's first edge.
// In the future, as room shapes become more editable, we might want to pass in an explicit "orientation edge" instead of just using the first edge.
if (wallCandidateOptions != null)
{
var roomOrientationEdge = room.Boundary.Perimeter.Segments().First();
for (int i = wallCandidateOptions.Count - 1; i >= 0; i--)
{
var (OrientationGuideEdge, _) = wallCandidateOptions[i];
if (OrientationGuideEdge.Line.Mid().DistanceTo(roomOrientationEdge.Mid()) > 0.01)
{
wallCandidateOptions.RemoveAt(i);
}
}
}

// Limit the possible configs to the one specified by the room's ConfigId property, if it's found in the set.
var configId = room.ConfigId;
var newConfigs = new SpaceConfiguration();
if (originalConfigs.ContainsKey(configId))
{
newConfigs.Add(configId, originalConfigs[configId]);
return newConfigs;
}

return originalConfigs;
}


/// <summary>
/// Basically the same as StandardLayoutOnAllLevels, but without the actual furniture layout part — just the wall creation.
Expand Down
3 changes: 3 additions & 0 deletions LayoutFunctions/LoungeLayout/dependencies/SpaceBoundary.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
using Elements.Geometry;
using Newtonsoft.Json;

namespace Elements
{
public partial class SpaceBoundary : ISpaceBoundary
{
public Vector3? ParentCentroid { get; set; }
[JsonProperty("Config Id")]
public string ConfigId { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using Elements.Geometry;
using Newtonsoft.Json;
namespace Elements
{
public partial class SpaceBoundary : GeometricElement, ISpaceBoundary
{
public Vector3? ParentCentroid { get; set; }

[JsonProperty("Config Id")]
public string ConfigId { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using Elements.Geometry;
using Newtonsoft.Json;
namespace Elements
{
public partial class SpaceBoundary : GeometricElement, ISpaceBoundary
{
public Vector3? ParentCentroid { get; set; }

[JsonProperty("Config Id")]
public string ConfigId { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Elements.Geometry;
using Elements.Geometry.Solids;
using LayoutFunctionCommon;
using Newtonsoft.Json;

namespace Elements
{
Expand All @@ -24,6 +25,9 @@ public partial class SpaceBoundary : ISpaceBoundary

public int SpaceCount { get; set; } = 1;

[JsonProperty("Config Id")]
public string ConfigId { get; set; } // unused by this layout type

[Newtonsoft.Json.JsonIgnore]
public LevelElements LevelElements { get; set; }

Expand Down
4 changes: 4 additions & 0 deletions LayoutFunctions/PantryLayout/dependencies/SpaceBoundary.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
using Elements.Geometry;
using Newtonsoft.Json;

namespace Elements
{
public partial class SpaceBoundary : GeometricElement, ISpaceBoundary
{
public Vector3? ParentCentroid { get; set; }

[JsonProperty("Config Id")]
public string ConfigId { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
using Elements.Geometry;
using Newtonsoft.Json;

namespace Elements
{
public partial class SpaceBoundary : GeometricElement, ISpaceBoundary
{
public Vector3? ParentCentroid { get; set; }

[JsonProperty("Config Id")]
public string ConfigId { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
using Elements.Geometry;
using Newtonsoft.Json;

namespace Elements
{
public partial class SpaceBoundary : GeometricElement, ISpaceBoundary
{
public Vector3? ParentCentroid { get; set; }

public Vector3? IndividualCentroid { get; set; }

[JsonProperty("Config Id")]
public string ConfigId { get; set; }
}
}
4 changes: 4 additions & 0 deletions LayoutFunctions/ReceptionLayout/dependencies/SpaceBoundary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
using System.Linq;
using System.Collections.Generic;
using Elements.Geometry;
using Newtonsoft.Json;

namespace Elements
{
public partial class SpaceBoundary : ISpaceBoundary
{
public Vector3? ParentCentroid { get; set; }
[JsonProperty("Config Id")]
public string ConfigId { get; set; }
}
}
3 changes: 3 additions & 0 deletions SpaceConfigurationFromModel/dependencies/SpaceBoundary.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
using Elements.Geometry;
using Newtonsoft.Json;
namespace Elements
{
public partial class SpaceBoundary : GeometricElement, ISpaceBoundary
{
public Vector3? ParentCentroid { get; set; }

[JsonProperty("Config Id")]
public string ConfigId { get; set; }
}
}
Loading