This repository has been archived by the owner on Jul 31, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
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 #9 from Amsterdam/bugfix/threshold-vertex-merging
Bugfix/threshold vertex merging
- Loading branch information
Showing
15 changed files
with
391 additions
and
211 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
* Copyright (C) X Gemeente | ||
* X Amsterdam | ||
* X Economic Services Departments | ||
* | ||
* Licensed under the EUPL, Version 1.2 or later (the "License"); | ||
* You may not use this work except in compliance with the License. | ||
* You may obtain a copy of the License at: | ||
* | ||
* https://joinup.ec.europa.eu/software/page/eupl | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" basis, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or | ||
* implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
using System; | ||
using System.Numerics; | ||
using TileBakeLibrary.Coordinates; | ||
|
||
namespace TileBakeLibrary | ||
{ | ||
public struct VertexNormalCombination : IEquatable<VertexNormalCombination> | ||
{ | ||
/// <summary> | ||
/// Angle in degrees | ||
/// </summary> | ||
public static float vertexDistanceComparisonThreshold = 0.01f; //1mm | ||
public static float normalAngleComparisonThreshold = 5.0f; | ||
|
||
public Vector3 normal; | ||
|
||
public Vector3Double vertex; | ||
public VertexNormalCombination(Vector3Double vertex, Vector3 normal) | ||
{ | ||
this.vertex = vertex; | ||
this.normal = normal; | ||
} | ||
|
||
/// <summary> | ||
/// Compares vert+normal with thresholds determining if they are the same | ||
/// </summary> | ||
/// <returns></returns> | ||
public bool Equals(VertexNormalCombination other) | ||
{ | ||
if (Vector3Double.Distance(other.vertex,vertex) < vertexDistanceComparisonThreshold) | ||
{ | ||
if (AngleBetweenNormals(normal, other.normal) < normalAngleComparisonThreshold) | ||
{ | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
/// <summary> | ||
/// Forces comparison using Equals | ||
/// </summary> | ||
/// <returns></returns> | ||
public override int GetHashCode() | ||
{ | ||
return 0; | ||
} | ||
|
||
/// <summary> | ||
/// Normal in degrees | ||
/// </summary> | ||
/// <param name="a"></param> | ||
/// <param name="b"></param> | ||
/// <param name="radiansInsteadOfDegrees">Return the angle in radians</param> | ||
/// <returns></returns> | ||
public static double AngleBetweenNormals(Vector3 a, Vector3 b, bool radiansInsteadOfDegrees = false) | ||
{ | ||
Vector3 normalA = Vector3.Normalize(a); | ||
Vector3 normalB = Vector3.Normalize(b); | ||
|
||
var radians = 2.0d * Math.Atan((normalA - normalB).Length() / (normalA + normalB).Length()); | ||
if(radiansInsteadOfDegrees) | ||
{ | ||
return radians; | ||
} | ||
return (180.0f / Math.PI) * radians; | ||
} | ||
|
||
public override string ToString() | ||
{ | ||
return $"v({vertex.X},{vertex.X},{vertex.X}), n({normal.X},{normal.Y},{normal.Z})"; | ||
} | ||
} | ||
} |
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,7 @@ | ||
{ | ||
"profiles": { | ||
"TileBakeLibrary": { | ||
"commandName": "Project" | ||
} | ||
} | ||
} |
Oops, something went wrong.