-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1049 from hypar-io/Snapping
Added optional snapping points generation;
- Loading branch information
Showing
13 changed files
with
214 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
Elements/src/Serialization/JSON/VectorListToByteArrayConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Elements.Geometry; | ||
using Newtonsoft.Json; | ||
|
||
namespace Elements.Serialization.JSON | ||
{ | ||
internal class VectorListToByteArrayConverter : JsonConverter | ||
{ | ||
public override bool CanRead => false; | ||
|
||
public override bool CanConvert(Type objectType) | ||
{ | ||
return objectType == typeof(List<Vector3>); | ||
} | ||
|
||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) | ||
{ | ||
throw new NotImplementedException(); | ||
|
||
} | ||
|
||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) | ||
{ | ||
var points = value as List<Vector3>; | ||
var valueAsArray = new double[points.Count * 3]; | ||
for (int i = 0; i < points.Count; i++) | ||
{ | ||
valueAsArray[i * 3] = points[i].X; | ||
valueAsArray[i * 3 + 1] = points[i].Y; | ||
valueAsArray[i * 3 + 2] = points[i].Z; | ||
} | ||
serializer.Serialize(writer, valueAsArray); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
namespace Elements | ||
{ | ||
/// <summary> | ||
/// Enumerates the modes for creating snap edges. | ||
/// </summary> | ||
public enum SnappingEdgeMode | ||
{ | ||
/// <summary> | ||
/// No edges are created; only individual point snaps. | ||
/// </summary> | ||
Points, | ||
/// <summary> | ||
/// A snap edge is drawn between every pair of points, creating a network of edges. | ||
/// </summary> | ||
Lines, | ||
/// <summary> | ||
/// Snap edges connect each subsequent point and also close the shape by connecting the last to the first point. | ||
/// </summary> | ||
LineLoop, | ||
/// <summary> | ||
/// Snap edges connect each subsequent point, without closing the shape. | ||
/// </summary> | ||
LineStrip | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using System.Collections.Generic; | ||
using Elements.Geometry; | ||
using Elements.Serialization.JSON; | ||
using Newtonsoft.Json; | ||
|
||
namespace Elements | ||
{ | ||
/// <summary> | ||
/// Provides information about snapping points. | ||
/// </summary> | ||
public class SnappingPoints | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of SnappingPoints class. | ||
/// </summary> | ||
/// <param name="points">The set of points.</param> | ||
/// <param name="edgeMode">The mode for creating snap edges.</param> | ||
public SnappingPoints(IEnumerable<Vector3> points, SnappingEdgeMode edgeMode = SnappingEdgeMode.LineStrip) | ||
{ | ||
Points.AddRange(points); | ||
EdgeMode = edgeMode; | ||
} | ||
|
||
/// <summary> | ||
/// Snapping points. | ||
/// </summary> | ||
[JsonProperty("points")] | ||
[JsonConverter(typeof(VectorListToByteArrayConverter))] | ||
public List<Vector3> Points { get; } = new List<Vector3>(); | ||
|
||
/// <summary> | ||
/// The modes for creating snap edges. | ||
/// </summary> | ||
[JsonProperty("edgeMode")] | ||
public SnappingEdgeMode EdgeMode { get; set; } | ||
} | ||
} |