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

Add Travel Distance Analyzer function. #79

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
ea79b83
Initial implementation of TravelDistanceAnalyzer function
DmytroMuravskyi Dec 1, 2023
d28941e
Add minimal cost to the turns
DmytroMuravskyi Dec 1, 2023
58248b2
All Level support
DmytroMuravskyi Dec 1, 2023
5ef8dad
Use RepsentationInstances for visualization
DmytroMuravskyi Dec 4, 2023
6336ad4
Merge remote-tracking branch 'origin/master' into dmuravskyi/distance…
DmytroMuravskyi Dec 4, 2023
0dc80e3
Set of improvements
DmytroMuravskyi Dec 4, 2023
3608c38
Add hack for WallCandidates with 0 thickness
DmytroMuravskyi Dec 6, 2023
4d21bd7
Connect non collinear exits
DmytroMuravskyi Dec 6, 2023
d3f91ea
Add support for multiple Door on a single line. Check for sections on…
DmytroMuravskyi Dec 7, 2023
6239e53
Extend connections from exit to corridor until the exit of the corridor
DmytroMuravskyi Dec 7, 2023
c054f3f
Distinguish end points inside and outside of a room
DmytroMuravskyi Dec 7, 2023
94c3fd2
Use only wall parts, adjacent to corridor if doors not present.
DmytroMuravskyi Dec 7, 2023
c199824
Don't show grid.
DmytroMuravskyi Dec 7, 2023
f7917b0
Eliminate warnings
DmytroMuravskyi Dec 7, 2023
de3c577
Add Epsiplon check to negate noise in CombineLines
DmytroMuravskyi Dec 7, 2023
9bd53a1
Prepare to PR
DmytroMuravskyi Dec 7, 2023
806920a
Mention repository URL
DmytroMuravskyi Dec 7, 2023
9dad486
Fix average distance calculation
DmytroMuravskyi Dec 7, 2023
e85ee87
Code review changes
DmytroMuravskyi Dec 13, 2023
a7b6944
Add Exception, remove unused default parameters
DmytroMuravskyi Dec 14, 2023
aaca8f0
Rename several functions
DmytroMuravskyi Dec 15, 2023
3bf40df
Restructure classes for better readability
DmytroMuravskyi Dec 19, 2023
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
9 changes: 9 additions & 0 deletions TravelDistanceAnalyzer/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

bin/
obj/
*.glb
output.json
input.json
.vs/
server/
test/Generated/
19 changes: 19 additions & 0 deletions TravelDistanceAnalyzer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@


# Travel Distance Analyzer

The Travel Distance Analyzer function.

|Input Name|Type|Description|
|---|---|---|


<br>

|Output Name|Type|Description|
|---|---|---|


<br>

## Additional Information
34 changes: 34 additions & 0 deletions TravelDistanceAnalyzer/TravelDistanceAnalyzer.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TravelDistanceAnalyzer", "src\TravelDistanceAnalyzer.csproj", "{732A2ECC-586C-43EA-9CE9-79C719E18BF9}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TravelDistanceAnalyzer.Dependencies", "dependencies\TravelDistanceAnalyzer.Dependencies.csproj", "{0CB6C856-E6D1-462C-951D-23043D7BCF88}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TravelDistanceAnalyzer.Tests", "test\TravelDistanceAnalyzer.Tests.csproj", "{695D9D11-8B3A-42C5-930A-4DE906364BB7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{732A2ECC-586C-43EA-9CE9-79C719E18BF9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{732A2ECC-586C-43EA-9CE9-79C719E18BF9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{732A2ECC-586C-43EA-9CE9-79C719E18BF9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{732A2ECC-586C-43EA-9CE9-79C719E18BF9}.Release|Any CPU.Build.0 = Release|Any CPU
{0CB6C856-E6D1-462C-951D-23043D7BCF88}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0CB6C856-E6D1-462C-951D-23043D7BCF88}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0CB6C856-E6D1-462C-951D-23043D7BCF88}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0CB6C856-E6D1-462C-951D-23043D7BCF88}.Release|Any CPU.Build.0 = Release|Any CPU
{695D9D11-8B3A-42C5-930A-4DE906364BB7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{695D9D11-8B3A-42C5-930A-4DE906364BB7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{695D9D11-8B3A-42C5-930A-4DE906364BB7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{695D9D11-8B3A-42C5-930A-4DE906364BB7}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
49 changes: 49 additions & 0 deletions TravelDistanceAnalyzer/dependencies/CirculationSegment.g.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//----------------------
// <auto-generated>
// Generated using the NJsonSchema v10.1.21.0 (Newtonsoft.Json v13.0.0.0) (http://NJsonSchema.org)
// </auto-generated>
//----------------------
using Elements;
using Elements.GeoJSON;
using Elements.Geometry;
using Elements.Geometry.Solids;
using Elements.Spatial;
using Elements.Validators;
using Elements.Serialization.JSON;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using Line = Elements.Geometry.Line;
using Polygon = Elements.Geometry.Polygon;

namespace Elements
{
#pragma warning disable // Disable all warnings

/// <summary>Represents a section of a circulation network, such as a corridor.</summary>
[JsonConverter(typeof(Elements.Serialization.JSON.JsonInheritanceConverter), "discriminator")]
[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "10.1.21.0 (Newtonsoft.Json v13.0.0.0)")]
public partial class CirculationSegment : Floor
{
[JsonConstructor]
public CirculationSegment(ThickenedPolyline @geometry, Profile @profile, double @thickness, System.Guid? @level, Transform @transform, Material @material, Representation @representation, bool @isElementDefinition, System.Guid @id, string @name)
: base(profile, thickness, level, transform, material, representation, isElementDefinition, id, name)
{
this.Geometry = @geometry;
}


// Empty constructor
public CirculationSegment()
: base()
{
}

/// <summary>The geometry of this circulation segment</summary>
[JsonProperty("Geometry", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public ThickenedPolyline Geometry { get; set; }


}
}
58 changes: 58 additions & 0 deletions TravelDistanceAnalyzer/dependencies/Level.g.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//----------------------
// <auto-generated>
// Generated using the NJsonSchema v10.1.21.0 (Newtonsoft.Json v13.0.0.0) (http://NJsonSchema.org)
// </auto-generated>
//----------------------
using Elements;
using Elements.GeoJSON;
using Elements.Geometry;
using Elements.Geometry.Solids;
using Elements.Spatial;
using Elements.Validators;
using Elements.Serialization.JSON;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using Line = Elements.Geometry.Line;
using Polygon = Elements.Geometry.Polygon;

namespace Elements
{
#pragma warning disable // Disable all warnings

/// <summary>A horizontal datum representing a building level at a specific elevation.</summary>
[JsonConverter(typeof(Elements.Serialization.JSON.JsonInheritanceConverter), "discriminator")]
[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "10.1.21.0 (Newtonsoft.Json v13.0.0.0)")]
public partial class Level : Element
{
[JsonConstructor]
public Level(double @elevation, double? @height, System.Guid? @planView, System.Guid @id = default, string @name = null)
: base(id, name)
{
this.Elevation = @elevation;
this.Height = @height;
this.PlanView = @planView;
}


// Empty constructor
public Level()
: base()
{
}

[JsonProperty("Elevation", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public double Elevation { get; set; }

/// <summary>The vertical distance from this level to the next. May be null for a top level, like a roof.</summary>
[JsonProperty("Height", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public double? Height { get; set; }

/// <summary>The default plan view for this level</summary>
[JsonProperty("Plan View", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public System.Guid? PlanView { get; set; }


}
}
153 changes: 153 additions & 0 deletions TravelDistanceAnalyzer/dependencies/RouteDistanceOverride.g.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
using Elements;
using System.Collections.Generic;
using System;
using System.Linq;

namespace TravelDistanceAnalyzer
{
/// <summary>
/// Override metadata for RouteDistanceOverride
/// </summary>
public partial class RouteDistanceOverride : IOverride
{
public static string Name = "Route Distance";
public static string Dependency = null;
public static string Context = "[*discriminator=Elements.RouteDistanceConfiguration]";
public static string Paradigm = "Edit";

/// <summary>
/// Get the override name for this override.
/// </summary>
public string GetName() {
return Name;
}

public object GetIdentity() {

return Identity;
}

}
public static class RouteDistanceOverrideExtensions
{
/// <summary>
/// Apply Route Distance edit overrides to a collection of existing elements
/// </summary>
/// <param name="overrideData">The Route Distance Overrides to apply</param>
/// <param name="existingElements">A collection of existing elements to which to apply the overrides.</param>
/// <param name="identityMatch">A function returning a boolean which indicates whether an element is a match for an override's identity.</param>
/// <param name="modifyElement">A function to modify a matched element, returning the modified element.</param>
/// <typeparam name="T">The element type this override applies to. Should match the type(s) in the override's context.</typeparam>
/// <returns>A collection of elements, including unmodified and modified elements from the supplied collection.</returns>
public static List<T> Apply<T>(
this IList<RouteDistanceOverride> overrideData,
IEnumerable<T> existingElements,
Func<T, RouteDistanceIdentity, bool> identityMatch,
Func<T, RouteDistanceOverride, T> modifyElement) where T : Element
{
var resultElements = new List<T>(existingElements);
if (overrideData != null)
{
foreach (var overrideValue in overrideData)
{
// Assuming there will only be one match per identity, find the first element that matches.
var matchingElement = existingElements.FirstOrDefault(e => identityMatch(e, overrideValue.Identity));
// if we found a match,
if (matchingElement != null)
{
// remove the old matching element
resultElements.Remove(matchingElement);
// apply the modification function to it
var modifiedElement = modifyElement(matchingElement, overrideValue);
// set the identity
Identity.AddOverrideIdentity(modifiedElement, overrideValue);
//and re-add it to the collection
resultElements.Add(modifiedElement);
}
}
}
return resultElements;
}

/// <summary>
/// Apply Route Distance edit overrides to a collection of existing elements
/// </summary>
/// <param name="existingElements">A collection of existing elements to which to apply the overrides.</param>
/// <param name="overrideData">The Route Distance Overrides to apply — typically `input.Overrides.RouteDistance`</param>
/// <param name="identityMatch">A function returning a boolean which indicates whether an element is a match for an override's identity.</param>
/// <param name="modifyElement">A function to modify a matched element, returning the modified element.</param>
/// <typeparam name="T">The element type this override applies to. Should match the type(s) in the override's context.</typeparam>
/// <returns>A collection of elements, including unmodified and modified elements from the supplied collection.</returns>
public static void ApplyOverrides<T>(
this List<T> existingElements,
IList<RouteDistanceOverride> overrideData,
Func<T, RouteDistanceIdentity, bool> identityMatch,
Func<T, RouteDistanceOverride, T> modifyElement
) where T : Element
{
var updatedElements = overrideData.Apply(existingElements, identityMatch, modifyElement);
existingElements.Clear();
existingElements.AddRange(updatedElements);
}

/// <summary>
/// Create elements from add/removeoverrides, and apply any edits.
/// </summary>
/// <param name="edits">The collection of edit overrides (Overrides.RouteDistance)</param>
/// <param name="additions">The collection of add overrides (Overrides.Additions.RouteDistance)</param>
/// <param name="removals">The collection of remove overrides (Overrides.Removals.RouteDistance)</param> /// <param name="identityMatch">A function returning a boolean which indicates whether an element is a match for an override's identity.</param>
/// <param name="createElement">A function to create a new element, returning the created element.</param>
/// <param name="modifyElement">A function to modify a matched element, returning the modified element.</param>
/// <param name="existingElements">An optional collection of existing elements to which to apply any edit overrides, or remove if remove overrides are found.</param>
/// <typeparam name="T">The element type this override applies to. Should match the type(s) in the override's context.</typeparam>
/// <returns>A collection of elements, including new, unmodified, and modified elements from the supplied collection.</returns>
public static List<T> CreateElements<T>(
this IList<RouteDistanceOverride> edits,
IList<RouteDistanceOverrideAddition> additions,
IList<RouteDistanceOverrideRemoval> removals, Func<RouteDistanceOverrideAddition, T> createElement,
Func<T, RouteDistanceIdentity, bool> identityMatch,
Func<T, RouteDistanceOverride, T> modifyElement,
IEnumerable<T> existingElements = null
) where T : Element
{
List<T> resultElements = existingElements == null ? new List<T>() : new List<T>(existingElements);
if (removals != null)
{
foreach (var removedElement in removals)
{
var elementToRemove = resultElements.FirstOrDefault(e => identityMatch(e, removedElement.Identity));
if (elementToRemove != null)
{
resultElements.Remove(elementToRemove);
}
}
} if (additions != null)
{
foreach (var addedElement in additions)
{
var elementToAdd = createElement(addedElement);
resultElements.Add(elementToAdd);
Identity.AddOverrideIdentity(elementToAdd, addedElement);
}
}
if (edits != null)
{
foreach (var editedElement in edits)
{
var elementToEdit = resultElements.FirstOrDefault(e => identityMatch(e, editedElement.Identity));
if (elementToEdit != null)
{
resultElements.Remove(elementToEdit);
var newElement = modifyElement(elementToEdit, editedElement);
resultElements.Add(newElement);
Identity.AddOverrideIdentity(newElement, editedElement);
}
}
}
return resultElements;
}

}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using Elements;
using System.Collections.Generic;
using System;
using System.Linq;

namespace TravelDistanceAnalyzer
{
/// <summary>
/// Override metadata for RouteDistanceOverrideAddition
/// </summary>
public partial class RouteDistanceOverrideAddition : IOverride
{
public static string Name = "Route Distance Addition";
public static string Dependency = null;
public static string Context = "[*discriminator=Elements.RouteDistanceConfiguration]";
public static string Paradigm = "Edit";

/// <summary>
/// Get the override name for this override.
/// </summary>
public string GetName() {
return Name;
}

public object GetIdentity() {

return Identity;
}

}

}
Loading
Loading