Skip to content

Geometry_Engine: IsRectangle and LongestEdgeDirection added#3588

Open
WojciechBuda00 wants to merge 6 commits into
developfrom
Revit_Toolkit-#1650-SupportRevitPadFoundation_Push
Open

Geometry_Engine: IsRectangle and LongestEdgeDirection added#3588
WojciechBuda00 wants to merge 6 commits into
developfrom
Revit_Toolkit-#1650-SupportRevitPadFoundation_Push

Conversation

@WojciechBuda00
Copy link
Copy Markdown

@WojciechBuda00 WojciechBuda00 commented May 21, 2026

NOTE: Depends on

Issues addressed by this PR

Closes #3586

Test files

Changelog

Additional comments

[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)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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)

Comment thread Geometry_Engine/Query/IsRectangle.cs Outdated
foreach (Line edge in edges)
{
Vector direction = edge.Direction();
direction.Z = 0;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not project the direction on XY, the method should work for any polyline

Comment on lines +55 to +56
if (direction.Length() <= tolerance)
continue;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not think this is needed, should be implicitly eliminated by edge length filter ln46

Comment on lines +58 to +61
if (direction.X < 0 || (Math.Abs(direction.X) < tolerance && direction.Y < 0))
{
direction = -direction;
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to flip the direction vector, IsParallel will work regardless


if (existDir != null)
{
dirLen[existDir] = edge.Length();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My idea was to find the dominant edge direction, not the direction of a single longest edge. May have miscommunicated that originally

Suggested change
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)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Suggested change
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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GeometryEngine: Add IsRectangle and LongestEdgeDirection methods

2 participants