SetComparisonResult incorrectly returns Equal with elliptical arcs

thomas
Advocate

SetComparisonResult incorrectly returns Equal with elliptical arcs

thomas
Advocate
Advocate

I have found that SetComparisonResult incorrectly returns Equal (instead of the expected result: Disjoint) when testing two 'identical' 180-degree elliptical arcs mirrored along their axis.

 

In the below example, two ellipse arcs are input to the SetComparisonResult - note that the result incorrectly states Equal. I also only output curveB (in Dynamo) if it is equal to cruveA, otherwise both curves are output (ie. the expected result):

set comparison result wrong.PNG

 

It seems the result is checking start/end points for coincidence, normals (which will all be the same if the absolute value of the dot product is computed) and length, but is failing to check a sample point for coincidence along the curve which would determine that the two curves are dissimilar (Incidentally, this is my workaround for the time being). It would be good to get some insight into why this is happening, given that circular arcs under the same conditions report correctly:

set comparison result correct.PNG

 

0 Likes
Reply
2,039 Views
9 Replies
Replies (9)

jeremytammik
Autodesk
Autodesk

Dear Thomas,

 

Thank you for your report.

 

I would be rather surprised if this is an error in the underlying Revit .NET API.

 

I strongly suspect something is going awry higher up, e.g., in the Python or Dynamo level.

 

Can you provide exact .NET source code reproducing the problem?

 

Optimally, a sample model with an embedded .NET macro or two demonstrating the error, either C# or Python, with exact step-by-step instructions to reproduce, that I can take a look at myself and pass on to the development team if needed?

 

http://thebuildingcoder.typepad.com/blog/about-the-author.html#1b

 

Thank you!

 

I hope this helps.

 

Best regards,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes

thomas
Advocate
Advocate

Hi Jeremy 

 

Thanks for your quick response and insights - you are spot-on. The problem seems to be related to Dynamo as I've since written a simple macro to compare two model curves under the same conditions and now the Equal result is consistent. Even with arc's I am now seeing consistent results, different from my initial post (Equal instead of Disjoint).

 

However, I am now in the dark with what exactly I should expect to see with the SetComparionResult. Before going any further, here is the macro I am using to test. It simply requires the user to pick two model curves and the result of the SetComparisonResult will be output in a dialog:

 

/*
 * Created by SharpDevelop.
 * User: Thomas
 * Date: 08/01/2018
 * Time: 20:56
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI.Selection;
using System.Collections.Generic;
using System.Linq;

namespace test
{
    [Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
    [Autodesk.Revit.DB.Macros.AddInId("6046A84C-61B3-4320-9FB5-52633967440F")]
	public partial class ThisDocument
	{
		private void Module_Startup(object sender, EventArgs e)
		{

		}

		private void Module_Shutdown(object sender, EventArgs e)
		{

		}

		#region Revit Macros generated code
		private void InternalStartup()
		{
			this.Startup += new System.EventHandler(Module_Startup);
			this.Shutdown += new System.EventHandler(Module_Shutdown);
		}
		#endregion
		
		private void MakeBoundCurve(ref Curve crv)
		{
            double length;
            try
            {
                length = crv.Period;
            }
            catch
            {
                length = crv.Length;
            }
            crv.MakeBound(0.0, length);
		}
		
		public void ComparisonResultError()
		{
			Document doc = Application.ActiveUIDocument.Document;
			UIDocument uiDoc = new UIDocument(doc);
			
			//Pick the first ellipse arc element
			Reference refCrvA = uiDoc.Selection.PickObject(ObjectType.Element);
			ModelCurve modelCurveA = (ModelCurve)doc.GetElement(refCrvA.ConvertToStableRepresentation(doc));
			
			//Pick the first ellipse arc element
			Reference refCrvB = uiDoc.Selection.PickObject(ObjectType.Element);
			ModelCurve modelCurveB = (ModelCurve)doc.GetElement(refCrvB.ConvertToStableRepresentation(doc));
			
			Curve crvA = modelCurveA.GeometryCurve;
			Curve crvB = modelCurveB.GeometryCurve;
			
			MakeBoundCurve(ref crvA);
			MakeBoundCurve(ref crvB);
			
			SetComparisonResult intersectTest = crvA.Intersect(crvB);
			
			TaskDialog td = new TaskDialog("Bimorph")
            {
                Title = "Comparison Result",
                MainContent = "SetComparisonResult : " + intersectTest.ToString()
            };
            td.Show();
		}
	}
}

 

In the API, I see the following explanation:

set comparison result text.PNG

 

My interpretation of the explanation of "Equal - The two curves are identical", is that they occupy the same space and are identical; i.e., duplicates. 

 

However, with the macro, I see that even the following two arcs return 'Equal':

set comparison result wrong.PNG

 

I thought it might be cause by the curves being treated as 'unbound', so I tested by adding a simple function in the macro to make sure the curves are bound, but the result is still the same. The problem then, has now shifted! 

 

0 Likes

jeremytammik
Autodesk
Autodesk

Dear Thomas,

 

Thank you for your updated report and careful analysis.

 

I am glad to hear that you are getting consistent results now, and that the Dynamo confusion is clarified.

 

Sorry to hear there is still a problem remaining.

 

Can you please provide the RVT sample model with the two different arcs and the macro that reports them as being equal, so I can pass that on to the development team?

 

Thank you!

 

Best regards,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes

thomas
Advocate
Advocate

Hi Jeremy

 

Sure, please find attached. I'm using Revit 2018.2. Thanks for your support on this matter!

 

Tom

0 Likes

jeremytammik
Autodesk
Autodesk

Dear Thomas,

 

Thank you for the RVT sample model and macro.

 

For the sake of completeness and convenience for others reading this thread, here is the macro code, adapted to run in Revit 2018.2:

 

 

  private void MakeBoundCurve(ref Curve crv)
  {
    double length;
    try
    {
      length = crv.Period;
    }
    catch
    {
      length = crv.Length;
    }
    crv.MakeBound(0.0, length);
  }
  
  public void ComparisonResultError()
  {
    //Document doc = ActiveUIDocument.Document;
    Document doc = this.Document;

    UIDocument uiDoc = new UIDocument(doc);
    
    //Pick the first ellipse arc element
    Reference refCrvA = uiDoc.Selection.PickObject(ObjectType.Element);
    ModelCurve modelCurveA = (ModelCurve)doc.GetElement(refCrvA.ConvertToStableRepresentation(doc));
    
    //Pick the first ellipse arc element
    Reference refCrvB = uiDoc.Selection.PickObject(ObjectType.Element);
    ModelCurve modelCurveB = (ModelCurve)doc.GetElement(refCrvB.ConvertToStableRepresentation(doc));
    
    Curve crvA = modelCurveA.GeometryCurve;
    Curve crvB = modelCurveB.GeometryCurve;
    
    MakeBoundCurve(ref crvA);
    MakeBoundCurve(ref crvB);
    
    SetComparisonResult intersectTest = crvA.Intersect(crvB);
    
    TaskDialog td = new TaskDialog("Bimorph")
    {
      Title = "Comparison Result",
      MainContent = "SetComparisonResult : " + intersectTest.ToString()
    };
    td.Show();
  }

 

It does indeed display 'Equal' for the two different halves of each ellipse, e.g., top and bottom, or left and right.

 

I logged the issue REVIT-125235 [Curve.Intersect returns SetComparisonResult.Equal for different ellipses -- 13761690] with our development team for this on your behalf as it requires further exploration and possibly a modification to our software. Please make a note of this number for future reference.

 

You are welcome to request an update on the status of this issue or to provide additional information on it at any time quoting this change request number.

 

This issue is important to me. What can I do to help?

 

This issue needs to be assessed by our engineering team, and prioritised against all other outstanding change requests. Any information that you can provide to influence this assessment will help. Please provide the following where possible:

 

  • Impact on your application and/or your development.
  • The number of users affected.
  • The potential revenue impact to you.
  • The potential revenue impact to Autodesk.
  • Realistic timescale over which a fix would help you.
  • In the case of a request for a new feature or a feature enhancement, please also provide detailed Use cases for the workflows that this change would address.

 

This information is extremely important. Our engineering team have limited resources, and so must focus their efforts on the highest impact items. We do understand that this will cause you delays and affect your development planning, and we appreciate your cooperation and patience.

 

Thank you!

 

Best regards,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes

thomas
Advocate
Advocate

Hi Jeremy

 

Thanks for the response and logging the 

 

  • Impact on your application and/or your development: Significant - I need to reliably establish what elements are compatible with the Element.IntersectsElements methods

 

 

  • The number of users affected: 250+

 

  • Realistic timescale over which a fix would help you: 2 months

 

 

 

0 Likes

jeremytammik
Autodesk
Autodesk

Dear Tom,

 

Thank you for the business case information, which I added to the development issue REVIT-125235 [Curve.Intersect returns SetComparisonResult.Equal for different ellipses -- 13761690] for you.

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes

thomas
Advocate
Advocate

Thanks Jeremy, it's appreciated.

 

Regards

 

Tom 

0 Likes

jeremytammik
Autodesk
Autodesk

Dear Tom,

 

Thank you for your patience. The development team analysed the issue REVIT-125235 [Curve.Intersect returns SetComparisonResult.Equal for different ellipses -- 13761690] and confirm the problematic behaviour you reported.

 

The function Autodesk::Revit::DB::Curve::Intersect intersects two curves. It calls the internal function intersectCurves, which returns CS_EQUAL if the unbounded curves are coincident as in this case.

 

The function does not yet handle partial coincidences.

 

When I run the macro in ellipse.rvt and select the two halves of one of the ellipses, the curves that are passed to intersectCurves are full ellipses, not half-ellipses. Revit's geometry kernel does not permit closed curves (or edges), so something's wrong with the way the selection is done, or perhaps in the way the API function calls the internal function.

 

Therefore, a code fix is needed.

 

A possible workaround is for the API author to check for a return value of CS_EQUAL and in such a case, to invoke a hand-written function that analyses the two curves to determine discrete intersection points and intervals of overlap.

 

I hope this helps.

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes