Skip to content

Commit

Permalink
Merge pull request #79 from DmytroMuravskyi/dmuravskyi/distance-analyzer
Browse files Browse the repository at this point in the history
Add Travel Distance Analyzer function. (#79)
  • Loading branch information
katehryhorenko authored Dec 20, 2023
2 parents 0f6d1fa + 3bf40df commit 274f9ae
Show file tree
Hide file tree
Showing 32 changed files with 3,085 additions and 0 deletions.
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

0 comments on commit 274f9ae

Please sign in to comment.