Geometry_Engine: IsRectangle and LongestEdgeDirection added#3588
Geometry_Engine: IsRectangle and LongestEdgeDirection added#3588WojciechBuda00 wants to merge 6 commits into
Conversation
| [Input("angleTolerance", "Angular tolerance used when comparing edge directions for parallelism.")] | ||
| [Output("direction", "Direction vector of the longest edge.")] | ||
|
|
||
| public static Vector LongestEdgeDirection(this Polyline polyline, double tolerance, double angleTolerance = Tolerance.Angle) |
There was a problem hiding this comment.
| public static Vector LongestEdgeDirection(this Polyline polyline, double tolerance, double angleTolerance = Tolerance.Angle) | |
| public static Vector LongestEdgeDirection(this Polyline polyline, double tolerance = Tolerance.Distance, double angleTolerance = Tolerance.Angle) |
| foreach (Line edge in edges) | ||
| { | ||
| Vector direction = edge.Direction(); | ||
| direction.Z = 0; |
There was a problem hiding this comment.
Do not project the direction on XY, the method should work for any polyline
| if (direction.Length() <= tolerance) | ||
| continue; |
There was a problem hiding this comment.
I do not think this is needed, should be implicitly eliminated by edge length filter ln46
| if (direction.X < 0 || (Math.Abs(direction.X) < tolerance && direction.Y < 0)) | ||
| { | ||
| direction = -direction; | ||
| } |
There was a problem hiding this comment.
No need to flip the direction vector, IsParallel will work regardless
|
|
||
| if (existDir != null) | ||
| { | ||
| dirLen[existDir] = edge.Length(); |
There was a problem hiding this comment.
My idea was to find the dominant edge direction, not the direction of a single longest edge. May have miscommunicated that originally
| dirLen[existDir] = edge.Length(); | |
| dirLen[existDir] += edge.Length(); |
| [Input("angleTolerance", "Angular tolerance used when comparing edge directions for parallelism.")] | ||
| [Output("direction", "Direction vector of the longest edge.")] | ||
|
|
||
| public static Vector LongestEdgeDirection(this Polyline polyline, double tolerance = Tolerance.Distance, double angleTolerance = Tolerance.Angle) |
There was a problem hiding this comment.
I think we may have missed each other when talking about this method's functionality: what I meant was not the direction of a single longest edge, but rather dominant direction in a polyline, i.e. a sum of lengths of all parallel edges. I think the method name should reflect this
| public static Vector LongestEdgeDirection(this Polyline polyline, double tolerance = Tolerance.Distance, double angleTolerance = Tolerance.Angle) | |
| public static Vector DominantEdgeDirection(this Polyline polyline, double tolerance = Tolerance.Distance, double angleTolerance = Tolerance.Angle) |
...also please remember to tweak the descriptions accordingly
NOTE: Depends on
Issues addressed by this PR
Closes #3586
Test files
Changelog
Additional comments