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

updates to layout functions #83

Merged
merged 17 commits into from
Dec 14, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<ProjectReference Include="..\..\LayoutFunctionCommon\LayoutFunctionCommon.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Hypar.Elements" Version="2.2.0-alpha.17" />
<PackageReference Include="Hypar.Functions" Version="1.11.0-alpha.10" />
<PackageReference Include="Hypar.Elements" Version="2.2.0-alpha.21" />
<PackageReference Include="Hypar.Functions" Version="1.11.0-alpha.13" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Hypar.Elements" Version="2.2.0-alpha.17" />
<PackageReference Include="Hypar.Functions" Version="1.11.0-alpha.10" />
<PackageReference Include="Hypar.Elements.Components" Version="2.2.0-alpha.17" />
<PackageReference Include="Hypar.Elements" Version="2.2.0-alpha.21" />
<PackageReference Include="Hypar.Functions" Version="1.11.0-alpha.13" />
<PackageReference Include="Hypar.Elements.Components" Version="2.2.0-alpha.21" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Hypar.Elements" Version="2.2.0-alpha.17" />
<PackageReference Include="Hypar.Functions" Version="1.11.0-alpha.10" />
<PackageReference Include="Hypar.Elements" Version="2.2.0-alpha.21" />
<PackageReference Include="Hypar.Functions" Version="1.11.0-alpha.13" />
</ItemGroup>
</Project>
4 changes: 2 additions & 2 deletions LayoutFunctions/Doors/dependencies/Doors.Dependencies.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

<ItemGroup>
<ProjectReference Include="..\..\LayoutFunctionCommon\LayoutFunctionCommon.csproj" />
<PackageReference Include="Hypar.Elements" Version="2.2.0-alpha.17" />
<PackageReference Include="Hypar.Functions" Version="1.11.0-alpha.10" />
<PackageReference Include="Hypar.Elements" Version="2.2.0-alpha.21" />
<PackageReference Include="Hypar.Functions" Version="1.11.0-alpha.13" />
</ItemGroup>

</Project>
3 changes: 2 additions & 1 deletion LayoutFunctions/Doors/hypar.json
Original file line number Diff line number Diff line change
Expand Up @@ -284,5 +284,6 @@
"https://schemas.hypar.io/WallCandidate.json"
],
"repository_url": "",
"filters": {}
"filters": {},
"stream_model": true
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\LayoutFunctionCommon\LayoutFunctionCommon.csproj" />
<PackageReference Include="Hypar.Elements" Version="2.2.0-alpha.17" />
<PackageReference Include="Hypar.Functions" Version="1.11.0-alpha.10" />
<PackageReference Include="Hypar.Elements" Version="2.2.0-alpha.21" />
<PackageReference Include="Hypar.Functions" Version="1.11.0-alpha.13" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Hypar.Server" Version="1.11.0-alpha.10" />
<PackageReference Include="Hypar.Server" Version="1.11.0-alpha.13" />
</ItemGroup>

<PropertyGroup>
Expand Down
37 changes: 26 additions & 11 deletions LayoutFunctions/InteriorPartitions/src/InteriorPartitions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ public static class InteriorPartitions
/// <returns>A InteriorPartitionsOutputs instance containing computed results and the model with any new elements.</returns>
public static InteriorPartitionsOutputs Execute(Dictionary<string, Model> inputModels, InteriorPartitionsInputs input)
{
// Initializing a dummy InteriorPartitionCandidate to ensure that the InteriorPartitionCandidate type is loaded
var interiorPartitionDummy = new InteriorPartitionCandidate();

var interiorPartitionCandidates = new List<InteriorPartitionCandidate>();
var modelDependencies = new[] {
"Private Office Layout",
Expand All @@ -53,7 +56,8 @@ public static InteriorPartitionsOutputs Execute(Dictionary<string, Model> inputM
{
if (inputModels.TryGetValue(md, out var mdModel))
{
interiorPartitionCandidates.AddRange(mdModel?.AllElementsOfType<InteriorPartitionCandidate>());
var interiorPartitions = mdModel?.AllElementsOfType<InteriorPartitionCandidate>();
interiorPartitionCandidates.AddRange(interiorPartitions);
}
}

Expand All @@ -68,9 +72,17 @@ public static InteriorPartitionsOutputs Execute(Dictionary<string, Model> inputM

var wallCandidatesDictionary = wallCandidates.ToDictionary(w => w.Id, w => (false, false));

var removals = new List<WallCandidate>();

foreach (var wallCandidate in wallCandidates)
{
TrimWallCandidate(wallCandidate, wallCandidates, wallCandidatesDictionary);
TrimWallCandidate(wallCandidate, wallCandidates, wallCandidatesDictionary, removals);
}

// Just in case there is a wall that is perfectly inside of a joint
foreach (var removal in removals)
{
wallCandidates.Remove(removal);
}

foreach (var wallCandidate in wallCandidates)
Expand All @@ -85,7 +97,7 @@ public static InteriorPartitionsOutputs Execute(Dictionary<string, Model> inputM
return output;
}

private static void TrimWallCandidate(WallCandidate wallCandidate, List<WallCandidate> wallCandidates, Dictionary<Guid, (bool StartModified, bool EndModified)> wallCandidatesDictionary)
private static void TrimWallCandidate(WallCandidate wallCandidate, List<WallCandidate> wallCandidates, Dictionary<Guid, (bool StartModified, bool EndModified)> wallCandidatesDictionary, List<WallCandidate> removals)
{
var nonCollinearList = wallCandidates.Where(x => !x.Line.IsCollinear(wallCandidate.Line, 0.1) && (wallCandidatesDictionary[x.Id].StartModified == false || wallCandidatesDictionary[x.Id].EndModified == false));

Expand All @@ -96,19 +108,25 @@ private static void TrimWallCandidate(WallCandidate wallCandidate, List<WallCand
// This ensures that we are always extending the wall with the larger thickness
if (GetTotalWidth(wallCandidateCheck.Thickness.Value) < GetTotalWidth(wallCandidate.Thickness.Value)) continue;

UpdateWallCandidateLines(wallCandidate, wallCandidateCheck, wallCandidates, wallCandidatesDictionary);

UpdateWallCandidateLines(wallCandidate, wallCandidateCheck, wallCandidates, wallCandidatesDictionary, removals);
}
}

private static void UpdateWallCandidateLines(WallCandidate wallCandidate, WallCandidate wallCandidateCheck, List<WallCandidate> wallCandidates, Dictionary<Guid, (bool StartModified, bool EndModified)> wallCandidatesDictionary)
private static void UpdateWallCandidateLines(WallCandidate wallCandidate, WallCandidate wallCandidateCheck, List<WallCandidate> wallCandidates, Dictionary<Guid, (bool StartModified, bool EndModified)> wallCandidatesDictionary, List<WallCandidate> removals)
{
var wallCandidateCheckWidth = GetTotalWidth(wallCandidateCheck.Thickness.Value);
var wallCandidateWidth = GetTotalWidth(wallCandidate.Thickness.Value);

var wallCandidateOffset = wallCandidate.Line.Direction() * wallCandidateCheckWidth / 2;
var wallCandidateCheckOffset = wallCandidateCheck.Line.Direction() * wallCandidateWidth / 2;

// Short wall that is inside of a joint that we should probably remove
if (Math.Abs(wallCandidateCheckWidth / 2 - wallCandidate.Line.Length()) < 0.01)
{
removals.Add(wallCandidate);
return;
}

var wallCandidateVector = wallCandidateCheck.Line.Direction();

var wallCandidateCheckCollinear = wallCandidates.Where(x => Math.Abs(x.Line.Direction().Dot(wallCandidateVector)) > 0.99 && x.Id != wallCandidateCheck.Id).ToList();
Expand Down Expand Up @@ -375,6 +393,7 @@ internal static List<WallCandidate> CreateWallCandidates(InteriorPartitionsInput
foreach (var levelGroup in levelGroups)
{
var candidates = WallGeneration.DeduplicateWallLines(levelGroup.ToList());

var height = levelGroup.OrderBy(l => l.Height).FirstOrDefault()?.Height ?? defaultWallHeight;
var levelWallCandidates = candidates.Select(c =>
new WallCandidate(c.Line,
Expand All @@ -386,10 +405,6 @@ internal static List<WallCandidate> CreateWallCandidates(InteriorPartitionsInput
Thickness = c.Thickness,
PrimaryEntryEdge = c.PrimaryEntryEdge
});
if (input.Overrides?.InteriorPartitionTypes != null)
{
levelWallCandidates = UpdateLevelWallCandidates(levelWallCandidates, input.Overrides.InteriorPartitionTypes);
}

var splittedCandidates = WallGeneration.SplitOverlappingWallCandidates(
levelWallCandidates.Select(w => new RoomEdge
Expand Down Expand Up @@ -546,7 +561,7 @@ public static void AttachOverrides(this IList<InteriorPartitionTypesOverride> ov
{
foreach (var overrideValue in overrideData)
{
var matchingElement = existingElements.FirstOrDefault(e => overrideValue.Identity.Line.IsAlmostEqualTo(e.Line, false, 0.01));
var matchingElement = existingElements.FirstOrDefault(e => overrideValue.Identity.Line.Mid().DistanceTo(e.Line) < 0.01);

if (overrideValue.Identity.AddId != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ public void TestExecute()
var input = GetInput();

var modelDependencies = new Dictionary<string, Model> {
{"Private Office Layout", Model.FromJson(File.ReadAllText(@"/Users/andrewheumann/Dev/HyparSpace/LayoutFunctions/InteriorPartitions/test/Generated/InteriorPartitionsTest/model_dependencies/Private Office Layout/912857ec-9688-4f85-9a40-165c4f03ffea.json")) },
{"Phone Booth Layout", Model.FromJson(File.ReadAllText(@"/Users/andrewheumann/Dev/HyparSpace/LayoutFunctions/InteriorPartitions/test/Generated/InteriorPartitionsTest/model_dependencies/Phone Booth Layout/ee7a93ac-949b-47c9-a1fb-a3667faed95f.json")) },
{"Classroom Layout", Model.FromJson(File.ReadAllText(@"/Users/andrewheumann/Dev/HyparSpace/LayoutFunctions/InteriorPartitions/test/Generated/InteriorPartitionsTest/model_dependencies/Classroom Layout/0663619a-d1e8-4241-9544-0a483dee4645.json")) },
{"Meeting Room Layout", Model.FromJson(File.ReadAllText(@"/Users/andrewheumann/Dev/HyparSpace/LayoutFunctions/InteriorPartitions/test/Generated/InteriorPartitionsTest/model_dependencies/Meeting Room Layout/a8ea6cfc-96fc-4b27-9687-0b1059703f62.json")) },
{"Space Planning Zones", Model.FromJson(File.ReadAllText(@"/Users/andrewheumann/Dev/HyparSpace/LayoutFunctions/InteriorPartitions/test/Generated/InteriorPartitionsTest/model_dependencies/Space Planning Zones/8c76d4ce-acf5-4327-ba37-23a4169f135a.json")) },
{"Private Office Layout", Model.FromJson(File.ReadAllText(@"C:\dev\Hypar\HyparSpace\LayoutFunctions\InteriorPartitions\test\Generated\InteriorPartitionsTest\model_dependencies\Private Office Layout\a7b37cd9-8ec2-4035-bd40-a1b3fbff1524.json")) },
{"Phone Booth Layout", Model.FromJson(File.ReadAllText(@"C:\dev\Hypar\HyparSpace\LayoutFunctions\InteriorPartitions\test\Generated\InteriorPartitionsTest\model_dependencies\Phone Booth Layout\55c48eb7-fb0c-42ec-aff7-e9e651d1896a.json")) },
{"Classroom Layout", Model.FromJson(File.ReadAllText(@"C:\dev\Hypar\HyparSpace\LayoutFunctions\InteriorPartitions\test\Generated\InteriorPartitionsTest\model_dependencies\Classroom Layout\718f17e9-a4a0-4c0e-9abb-6e9378f58227.json")) },
{"Meeting Room Layout", Model.FromJson(File.ReadAllText(@"C:\dev\Hypar\HyparSpace\LayoutFunctions\InteriorPartitions\test\Generated\InteriorPartitionsTest\model_dependencies\Meeting Room Layout\6ed714fe-85c6-4911-aad5-ff4f3c9e48c7.json")) },
{"Space Planning Zones", Model.FromJson(File.ReadAllText(@"C:\dev\Hypar\HyparSpace\LayoutFunctions\InteriorPartitions\test\Generated\InteriorPartitionsTest\model_dependencies\Space Planning Zones\5b0ce623-8e60-4d13-928a-b31ea609934e.json")) },
{"Furniture and Equipment", Model.FromJson(File.ReadAllText(@"C:\dev\Hypar\HyparSpace\LayoutFunctions\InteriorPartitions\test\Generated\InteriorPartitionsTest\model_dependencies\Furniture and Equipment\27ed00af-dcc3-4d5a-8124-a993ac3eab62.json")) },
{"Doors", Model.FromJson(File.ReadAllText(@"C:\dev\Hypar\HyparSpace\LayoutFunctions\InteriorPartitions\test\Generated\InteriorPartitionsTest\model_dependencies\Doors\ee4fe433-9de6-4899-923e-2a02b4ba2a11.json")) },
};

var result = InteriorPartitions.Execute(modelDependencies, input);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"Transform":{"Matrix":{"Components":[1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0]}},"Elements":{"5b3fb2fd-1621-4282-b443-edf65c35d601":{"discriminator":"Elements.InteriorPartitionCandidate","WallCandidateLines":[],"Height":3.0,"LevelTransform":{"Matrix":{"Components":[1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0]}},"Id":"5b3fb2fd-1621-4282-b443-edf65c35d601","Name":null}}}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"Transform":{"Matrix":{"Components":[1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0]}},"Elements":{"6c7a846d-1f72-45d6-be46-07175b63c34c":{"discriminator":"Elements.Material","Color":{"Red":0.5,"Green":0.5,"Blue":0.5,"Alpha":1.0},"SpecularFactor":0.5,"GlossinessFactor":0.25,"Unlit":false,"DoubleSided":false,"RepeatTexture":false,"InterpolateTexture":false,"EmissiveFactor":0.0,"Draw In Front":false,"EdgeDisplaySettings":null,"Id":"6c7a846d-1f72-45d6-be46-07175b63c34c","Name":"Silver Frame"},"9babb829-9b96-4e73-97f4-9658d4d6c31c":{"discriminator":"Elements.Material","Color":{"Red":1.0,"Green":1.0,"Blue":1.0,"Alpha":1.0},"SpecularFactor":0.0,"GlossinessFactor":0.0,"Unlit":false,"DoubleSided":false,"RepeatTexture":true,"InterpolateTexture":true,"EmissiveFactor":0.0,"Draw In Front":false,"EdgeDisplaySettings":null,"Id":"9babb829-9b96-4e73-97f4-9658d4d6c31c","Name":"default"},"4a023687-f85d-4ac4-b170-ca57e75d8328":{"discriminator":"Elements.Door","FrameMaterial":"6c7a846d-1f72-45d6-be46-07175b63c34c","Door Opening Type":"Single Swing","Door Opening Side":"Left Hand","Door Width":0.9144,"Door Height":2.1,"Door Type":"Solid","DoorThickness":0.0508,"FrameDepth":0.1778,"FrameWidth":0.0508,"HandleHeight":1.0668,"HandleBaseRadius":0.03429,"HandleRadius":0.01143,"HandleLength":0.127,"HandleDepth":0.0508,"OriginalPosition":{"X":15.843159889984504,"Y":5.802675283599605,"Z":0.0},"Transform":{"Matrix":{"Components":[1.837589179357618E-15,-1.0,0.0,15.843159889984504,1.0,1.837589179357618E-15,0.0,5.802675283599605,0.0,0.0,1.0,0.0]}},"Material":"9babb829-9b96-4e73-97f4-9658d4d6c31c","Representation":null,"IsElementDefinition":false,"Id":"4a023687-f85d-4ac4-b170-ca57e75d8328","Name":"Door"}}}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"Transform":{"Matrix":{"Components":[1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0]}},"Elements":{"f0feba4b-bf85-49a5-8b6b-8601e973ecde":{"discriminator":"Elements.InteriorPartitionCandidate","WallCandidateLines":[],"Height":4.0,"LevelTransform":{"Matrix":{"Components":[1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0]}},"Id":"f0feba4b-bf85-49a5-8b6b-8601e973ecde","Name":null}}}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"Transform":{"Matrix":{"Components":[1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0]}},"Elements":{"574c057b-77b7-4159-b3ce-756653877ebe":{"discriminator":"Elements.InteriorPartitionCandidate","WallCandidateLines":[],"Height":3.0,"LevelTransform":{"Matrix":{"Components":[1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0]}},"Id":"574c057b-77b7-4159-b3ce-756653877ebe","Name":null}}}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"Transform":{"Matrix":{"Components":[1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0]}},"Elements":{"56c8f9b4-5977-45cb-ba98-4d20a6c3afb1":{"discriminator":"Elements.InteriorPartitionCandidate","WallCandidateLines":[],"Height":3.0,"LevelTransform":{"Matrix":{"Components":[1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0]}},"Id":"56c8f9b4-5977-45cb-ba98-4d20a6c3afb1","Name":null}}}
Loading
Loading