Skip to content

Commit

Permalink
more clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonie-kramer committed Nov 21, 2023
1 parent d392ddf commit 41e2ac7
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 38 deletions.
20 changes: 10 additions & 10 deletions LayoutFunctions/Doors/dependencies/DoorsInputs.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -329,19 +329,19 @@ public partial class DoorPositionsValue

{
[Newtonsoft.Json.JsonConstructor]
public DoorPositionsValue(Transform @transform, double @doorWidth, double @doorHeight, DoorPositionsValueDefaultDoorOpeningSide @defaultDoorOpeningSide, DoorPositionsValueDefaultDoorOpeningType @defaultDoorOpeningType)
public DoorPositionsValue(Transform @transform, double @doorWidth, double @doorHeight, DoorPositionsValueDoorOpeningSide @doorOpeningSide, DoorPositionsValueDoorOpeningType @doorOpeningType)
{
var validator = Validator.Instance.GetFirstValidatorForType<DoorPositionsValue>();
if(validator != null)
{
validator.PreConstruct(new object[]{ @transform, @doorWidth, @doorHeight, @defaultDoorOpeningSide, @defaultDoorOpeningType});
validator.PreConstruct(new object[]{ @transform, @doorWidth, @doorHeight, @doorOpeningSide, @doorOpeningType});
}

this.Transform = @transform;
this.DoorWidth = @doorWidth;
this.DoorHeight = @doorHeight;
this.DefaultDoorOpeningSide = @defaultDoorOpeningSide;
this.DefaultDoorOpeningType = @defaultDoorOpeningType;
this.DoorOpeningSide = @doorOpeningSide;
this.DoorOpeningType = @doorOpeningType;

if(validator != null)
{
Expand All @@ -363,14 +363,14 @@ public DoorPositionsValue(Transform @transform, double @doorWidth, double @doorH
public double DoorHeight { get; set; } = 2.1D;

/// <summary>The opening side of a door.</summary>
[Newtonsoft.Json.JsonProperty("Default Door Opening Side", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
[Newtonsoft.Json.JsonProperty("Door Opening Side", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
[Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))]
public DoorPositionsValueDefaultDoorOpeningSide DefaultDoorOpeningSide { get; set; } = DoorPositionsValueDefaultDoorOpeningSide.Left_Hand;
public DoorPositionsValueDoorOpeningSide DoorOpeningSide { get; set; } = DoorPositionsValueDoorOpeningSide.Left_Hand;

/// <summary>The type of a door.</summary>
[Newtonsoft.Json.JsonProperty("Default Door Opening Type", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
[Newtonsoft.Json.JsonProperty("Door Opening Type", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
[Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))]
public DoorPositionsValueDefaultDoorOpeningType DefaultDoorOpeningType { get; set; } = DoorPositionsValueDefaultDoorOpeningType.Single_Swing;
public DoorPositionsValueDoorOpeningType DoorOpeningType { get; set; } = DoorPositionsValueDoorOpeningType.Single_Swing;

}

Expand Down Expand Up @@ -426,7 +426,7 @@ public DoorPositionsOverrideAdditionValue(Transform @transform, double @doorWidt
}

[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "10.1.21.0 (Newtonsoft.Json v13.0.0.0)")]
public enum DoorPositionsValueDefaultDoorOpeningSide
public enum DoorPositionsValueDoorOpeningSide
{
[System.Runtime.Serialization.EnumMember(Value = @"Left Hand")]
Left_Hand = 0,
Expand All @@ -440,7 +440,7 @@ public enum DoorPositionsValueDefaultDoorOpeningSide
}

[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "10.1.21.0 (Newtonsoft.Json v13.0.0.0)")]
public enum DoorPositionsValueDefaultDoorOpeningType
public enum DoorPositionsValueDoorOpeningType
{
[System.Runtime.Serialization.EnumMember(Value = @"Single Swing")]
Single_Swing = 0,
Expand Down
4 changes: 2 additions & 2 deletions LayoutFunctions/Doors/hypar.json
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@
"$hyparUnitType": "length",
"minimum": 2.032
},
"Default Door Opening Side": {
"Door Opening Side": {
"default": "Left Hand",
"description": "The opening side of a door.",
"type": "string",
Expand All @@ -190,7 +190,7 @@
"Double Door"
]
},
"Default Door Opening Type": {
"Door Opening Type": {
"default": "Single Swing",
"description": "The type of a door.",
"type": "string",
Expand Down
53 changes: 27 additions & 26 deletions LayoutFunctions/Doors/src/Doors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,23 @@ public static DoorsOutputs Execute(Dictionary<string, Model> inputModels, DoorsI
foreach (var room in rooms)
{
var pair = RoomDefaultDoorWall(room, levelCorridorsSegments, walls);
if (pair == null || pair.Value.RoomEdge == null || pair.Value.Segment == null)
if (pair == null || pair.Value.Wall == null || pair.Value.Segment == null)
{
continue;
}

var wallCandidate = pair.Value.RoomEdge;
var wall = pair.Value.Wall;
var openingSide = ConvertOpeningSideEnum(input.DefaultDoorOpeningSide);
var openingType = ConvertOpeningTypeEnum(input.DefaultDoorOpeningType);

if (!wallCandidate.Thickness.HasValue) continue;
var wallThickness = wallCandidate.Thickness.Value.innerWidth + wallCandidate.Thickness.Value.outerWidth;
if (!wall.Thickness.HasValue) continue;
var wallThickness = wall.Thickness.Value.innerWidth + wall.Thickness.Value.outerWidth;

// Don't add door if the wall is zero thickness.
if (wallThickness == 0.0) continue;

// Don't add door if the wall length is too short.
if (wallCandidate.Line.Length() < doorOffset + input.DefaultDoorWidth) continue;
if (wall.Line.Length() < doorOffset + input.DefaultDoorWidth) continue;

var doorOriginalPosition = pair.Value.Segment.PointAt(doorOffset + input.DefaultDoorWidth / 2);

Expand All @@ -59,15 +59,15 @@ public static DoorsOutputs Execute(Dictionary<string, Model> inputModels, DoorsI
if (doorOverride != null && doorOverride.Value.Transform != null)
{
doorCurrentPosition = doorOverride.Value.Transform.Origin;
openingSide = ConvertOpeningSideEnum(doorOverride.Value.DefaultDoorOpeningSide);
openingType = ConvertOpeningTypeEnum(doorOverride.Value.DefaultDoorOpeningType);
wallCandidate = GetClosestWallCandidate(doorCurrentPosition, walls, out doorCurrentPosition);
openingSide = ConvertOpeningSideEnum(doorOverride.Value.DoorOpeningSide);
openingType = ConvertOpeningTypeEnum(doorOverride.Value.DoorOpeningType);
wall = GetClosestWallCandidate(doorCurrentPosition, walls, out doorCurrentPosition);
}

double width = doorOverride?.Value.DoorWidth ?? input.DefaultDoorWidth;
double height = doorOverride?.Value.DoorHeight ?? input.DefaultDoorHeight;

var door = CreateDoor(wallCandidate, doorOriginalPosition, doorCurrentPosition, width, height, Door.DOOR_THICKNESS, openingSide, openingType, doorOverride);
var door = CreateDoor(wall, doorOriginalPosition, doorCurrentPosition, width, height, Door.DOOR_THICKNESS, openingSide, openingType, doorOverride);
if (door != null)
{
doors.Add(door);
Expand All @@ -78,7 +78,7 @@ public static DoorsOutputs Execute(Dictionary<string, Model> inputModels, DoorsI
AddDoors(doors, input.Overrides.Additions.DoorPositions, walls, input.Overrides);
RemoveDoors(doors, input.Overrides.Removals.DoorPositions);

output.Model.AddElements(doors);
// output.Model.AddElements(doors);
return output;
}

Expand Down Expand Up @@ -140,7 +140,7 @@ private static List<RoomEdge> GetWallCandidates(Dictionary<string, Model> inputM
return roomEdges;
}

private static (Line Segment, RoomEdge RoomEdge)? RoomDefaultDoorWall(
private static (Line Segment, RoomEdge Wall)? RoomDefaultDoorWall(
SpaceBoundary room,
IEnumerable<Line> corridorsSegments,
IEnumerable<RoomEdge> wallCandidates)
Expand All @@ -159,7 +159,7 @@ private static (Line Segment, RoomEdge RoomEdge)? RoomDefaultDoorWall(
return null;
}

var wall = RoomLongestWallCandidate(roomWalls);
var wall = RoomLongestWallCandidate(room, roomWalls);

wall = roomWalls.FirstOrDefault(x => x.Item2.PrimaryEntryEdge == true);

Expand All @@ -168,16 +168,16 @@ private static (Line Segment, RoomEdge RoomEdge)? RoomDefaultDoorWall(

private static void AddDoors(List<Door> doors,
IEnumerable<DoorPositionsOverrideAddition> additions,
List<RoomEdge> roomEdges,
List<RoomEdge> walls,
Overrides overrides)
{
foreach (var addition in additions)
{
var originalPosition = addition.Value.Transform.Origin;
var openingSide = ConvertOpeningSideEnum(addition.Value.DoorOpeningSide);
var openingType = ConvertOpeningTypeEnum(addition.Value.DoorOpeningType);
var wallCandidate = GetClosestWallCandidate(originalPosition, roomEdges, out originalPosition);
if (wallCandidate == null)
var wall = GetClosestWallCandidate(originalPosition, walls, out originalPosition);
if (wall == null)
{
continue;
}
Expand All @@ -192,12 +192,12 @@ private static void AddDoors(List<Door> doors,
currentPosition = doorOverride.Value.Transform.Origin;
width = doorOverride.Value.DoorWidth;
height = doorOverride.Value.DoorHeight;
wallCandidate = GetClosestWallCandidate(currentPosition, roomEdges, out currentPosition);
openingSide = ConvertOpeningSideEnum(doorOverride.Value.DefaultDoorOpeningSide);
openingType = ConvertOpeningTypeEnum(doorOverride.Value.DefaultDoorOpeningType);
wall = GetClosestWallCandidate(currentPosition, walls, out currentPosition);
openingSide = ConvertOpeningSideEnum(doorOverride.Value.DoorOpeningSide);
openingType = ConvertOpeningTypeEnum(doorOverride.Value.DoorOpeningType);
}

var door = CreateDoor(wallCandidate, originalPosition, currentPosition, width, height, Door.DOOR_THICKNESS, openingSide, openingType, doorOverride);
var door = CreateDoor(wall, originalPosition, currentPosition, width, height, Door.DOOR_THICKNESS, openingSide, openingType, doorOverride);
if (door != null)
{
doors.Add(door);
Expand Down Expand Up @@ -227,29 +227,30 @@ private static void RemoveDoors(List<Door> doors,
.Select(edge => edge.Line).ToList();
return corridorEdges;
}
private static List<(Line, RoomEdge)> GetRoomWallCandidates(List<Line> corridorEdges,

private static List<(Line, RoomEdge)> GetRoomWallCandidates(List<Line> corridorEdges,
IEnumerable<RoomEdge> wallCandidates)
{
var roomEdges = new List<(Line, RoomEdge)>();
var roomWalls = new List<(Line, RoomEdge)>();
foreach (var rs in corridorEdges)
{
var wall = wallCandidates.FirstOrDefault(wc => IsWallCoverRoomSegment(rs, wc));
if (wall != null)
{
roomEdges.Add((rs, wall));
roomWalls.Add((rs, wall));
}
}
return roomEdges;
return roomWalls;
}

private static (Line, RoomEdge)? RoomLongestWallCandidate(
IEnumerable<(Line CorridorEdge, RoomEdge RoomEdge)> roomEdges)
SpaceBoundary room,
IEnumerable<(Line CorridorEdge, RoomEdge Wall)> roomWalls)
{
double maxLength = 0;
(Line, RoomEdge)? longestWall = null;

foreach (var (edge, wall) in roomEdges)
foreach (var (edge, wall) in roomWalls)
{
var wallLength = edge.Length();
if (wallLength > maxLength)
Expand Down Expand Up @@ -309,7 +310,7 @@ private static bool IsWallCoverRoomSegment(Line segment, RoomEdge wallCandidate)
return null;
}

double minDist = double.MaxValue;
double minDist = Double.MaxValue;
RoomEdge? closestWall = null;

foreach (var wall in wallCandidates)
Expand Down

0 comments on commit 41e2ac7

Please sign in to comment.