<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: compare XYZ in Revit API Forum</title>
    <link>https://forums.autodesk.com/t5/revit-api-forum/compare-xyz/m-p/10382213#M25466</link>
    <description>&lt;P&gt;Thank you for the valid question, and thanks to Maxim for his very helpful answer.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Afaik, the correct best practice in .NET is to implement a comparison operator named Compare or a Comparer class:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://duckduckgo.com/?q=.net+comparer" target="_blank" rel="noopener"&gt;https://duckduckgo.com/?q=.net+comparer&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, since the X, Y and Z coordinates are real values, you need to define a tolerance and add some fuzz to be able to determine equality.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is The Building Coder comparer method for XYZ objects:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/jeremytammik/the_building_coder_samples/blob/master/BuildingCoder/BuildingCoder/Util.cs#L32-L349" target="_blank"&gt;https://github.com/jeremytammik/the_building_coder_samples/blob/master/BuildingCoder/BuildingCoder/Util.cs#L32-L349&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;  /// &amp;lt;summary&amp;gt;
  /// Default tolerance used to add fuzz 
  /// for real number equality detection
  /// &amp;lt;/summary&amp;gt;
  public const double _eps = 1.0e-9;

  /// &amp;lt;summary&amp;gt;
  /// Predicate to determine whether the given 
  /// real number should be considered equal to
  /// zero, adding fuzz according to the specified 
  /// tolerance
  /// &amp;lt;/summary&amp;gt;
  public static bool IsZero(
    double a,
    double tolerance = _eps )
  {
    return tolerance &amp;gt; Math.Abs( a );
  }

  /// &amp;lt;summary&amp;gt;
  /// Predicate to determine whether the two given 
  /// real numbers should be considered equal, adding 
  /// fuzz according to the specified tolerance
  /// &amp;lt;/summary&amp;gt;
  public static bool IsEqual(
    double a,
    double b,
    double tolerance = _eps )
  {
    return IsZero( b - a, tolerance );
  }

  /// &amp;lt;summary&amp;gt;
  /// Comparison method for two real numbers
  /// returning 0 if they are to be considered equal,
  /// -1 if the first is smaller and +1 otherwise
  /// &amp;lt;/summary&amp;gt;
  public static int Compare(
    double a,
    double b,
    double tolerance = _eps )
  {
    return IsEqual( a, b, tolerance )
      ? 0
      : (a &amp;lt; b ? -1 : 1);
  }

  /// &amp;lt;summary&amp;gt;
  /// Comparison method for two XYZ objects
  /// returning 0 if they are to be considered equal,
  /// -1 if the first is smaller and +1 otherwise
  /// &amp;lt;/summary&amp;gt;
  public static int Compare(
    XYZ p,
    XYZ q,
    double tolerance = _eps )
  {
    int d = Compare( p.X, q.X, tolerance );

    if( 0 == d )
    {
      d = Compare( p.Y, q.Y, tolerance );

      if( 0 == d )
      {
        d = Compare( p.Z, q.Z, tolerance );
      }
    }
    return d;
  }&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 11 Jun 2021 10:15:49 GMT</pubDate>
    <dc:creator>jeremy_tammik</dc:creator>
    <dc:date>2021-06-11T10:15:49Z</dc:date>
    <item>
      <title>compare XYZ</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/compare-xyz/m-p/10381691#M25463</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To determine if a point is in a boundingbox I have to determine if the X, Y and Z coordinate of that point is greater than the min point of the boundingbox and smaller than the max point of the boundingbox. When searching for this I could only find the XYZ.IsAlmostEqualTo() method but there was no method to determine if an XYZ is greater than or smaller than another XYZ.&lt;/P&gt;&lt;P&gt;Did I miss something or are the methods to compare XYZs with the API just a little limited? If so it would be really nice to have the above mentioned comparison methods were added to the API in a later version of Revit.&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kind regards,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Jeroen van Halderen&lt;/P&gt;</description>
      <pubDate>Fri, 11 Jun 2021 06:55:38 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/compare-xyz/m-p/10381691#M25463</guid>
      <dc:creator>jeroen.van.halderen</dc:creator>
      <dc:date>2021-06-11T06:55:38Z</dc:date>
    </item>
    <item>
      <title>Re: compare XYZ</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/compare-xyz/m-p/10382067#M25464</link>
      <description>&lt;P&gt;Hi!&lt;/P&gt;
&lt;P&gt;I think such functionality is a bit narrow and unlikely will appear in API. But you can implement it on your own by inheriting the base XYZ class and &lt;A href="https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/operator-overloading" target="_blank" rel="noopener"&gt;overloading&lt;/A&gt; necessary operators. I am not good enough with C# but in Python it looks like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;class XYZExtended(DB.XYZ):
    def __gt__(self, other):
        if any([self.X &amp;lt; other.X,
                self.Y &amp;lt; other.Y,
                self.Z &amp;lt; other.Z]):
            return False
        return any([self.X &amp;gt; other.X,
                    self.Y &amp;gt; other.Y,
                    self.Z &amp;gt; other.Z])

    def __lt__(self, other):
        if any([self.X &amp;gt; other.X,
                self.Y &amp;gt; other.Y,
                self.Z &amp;gt; other.Z]):
            return False
        return any([self.X &amp;lt; other.X,
                    self.Y &amp;lt; other.Y,
                    self.Z &amp;lt; other.Z])


xyz_1 = XYZExtended()
xyz_2 = XYZExtended(1, 1, 1)
xyz_3 = XYZExtended(-3, -5, -2)

print xyz_1 &amp;gt; xyz_2
print xyz_1 &amp;gt; xyz_3
print xyz_3 &amp;lt; xyz_2

# results
False
True
True&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Jun 2021 09:40:51 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/compare-xyz/m-p/10382067#M25464</guid>
      <dc:creator>architect.bim</dc:creator>
      <dc:date>2021-06-11T09:40:51Z</dc:date>
    </item>
    <item>
      <title>Re: compare XYZ</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/compare-xyz/m-p/10382085#M25465</link>
      <description>&lt;P&gt;P.S. The logic of comaring two XYZ objects may be more complex than in the exapmle above, but the main idea is there: overload method, define rules which allow you to say that one object is greater than the other.&lt;/P&gt;
&lt;P&gt;Good luck! &lt;span class="lia-unicode-emoji" title=":grinning_face_with_big_eyes:"&gt;😃&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Jun 2021 09:42:56 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/compare-xyz/m-p/10382085#M25465</guid>
      <dc:creator>architect.bim</dc:creator>
      <dc:date>2021-06-11T09:42:56Z</dc:date>
    </item>
    <item>
      <title>Re: compare XYZ</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/compare-xyz/m-p/10382213#M25466</link>
      <description>&lt;P&gt;Thank you for the valid question, and thanks to Maxim for his very helpful answer.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Afaik, the correct best practice in .NET is to implement a comparison operator named Compare or a Comparer class:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://duckduckgo.com/?q=.net+comparer" target="_blank" rel="noopener"&gt;https://duckduckgo.com/?q=.net+comparer&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, since the X, Y and Z coordinates are real values, you need to define a tolerance and add some fuzz to be able to determine equality.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is The Building Coder comparer method for XYZ objects:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/jeremytammik/the_building_coder_samples/blob/master/BuildingCoder/BuildingCoder/Util.cs#L32-L349" target="_blank"&gt;https://github.com/jeremytammik/the_building_coder_samples/blob/master/BuildingCoder/BuildingCoder/Util.cs#L32-L349&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;  /// &amp;lt;summary&amp;gt;
  /// Default tolerance used to add fuzz 
  /// for real number equality detection
  /// &amp;lt;/summary&amp;gt;
  public const double _eps = 1.0e-9;

  /// &amp;lt;summary&amp;gt;
  /// Predicate to determine whether the given 
  /// real number should be considered equal to
  /// zero, adding fuzz according to the specified 
  /// tolerance
  /// &amp;lt;/summary&amp;gt;
  public static bool IsZero(
    double a,
    double tolerance = _eps )
  {
    return tolerance &amp;gt; Math.Abs( a );
  }

  /// &amp;lt;summary&amp;gt;
  /// Predicate to determine whether the two given 
  /// real numbers should be considered equal, adding 
  /// fuzz according to the specified tolerance
  /// &amp;lt;/summary&amp;gt;
  public static bool IsEqual(
    double a,
    double b,
    double tolerance = _eps )
  {
    return IsZero( b - a, tolerance );
  }

  /// &amp;lt;summary&amp;gt;
  /// Comparison method for two real numbers
  /// returning 0 if they are to be considered equal,
  /// -1 if the first is smaller and +1 otherwise
  /// &amp;lt;/summary&amp;gt;
  public static int Compare(
    double a,
    double b,
    double tolerance = _eps )
  {
    return IsEqual( a, b, tolerance )
      ? 0
      : (a &amp;lt; b ? -1 : 1);
  }

  /// &amp;lt;summary&amp;gt;
  /// Comparison method for two XYZ objects
  /// returning 0 if they are to be considered equal,
  /// -1 if the first is smaller and +1 otherwise
  /// &amp;lt;/summary&amp;gt;
  public static int Compare(
    XYZ p,
    XYZ q,
    double tolerance = _eps )
  {
    int d = Compare( p.X, q.X, tolerance );

    if( 0 == d )
    {
      d = Compare( p.Y, q.Y, tolerance );

      if( 0 == d )
      {
        d = Compare( p.Z, q.Z, tolerance );
      }
    }
    return d;
  }&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Jun 2021 10:15:49 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/compare-xyz/m-p/10382213#M25466</guid>
      <dc:creator>jeremy_tammik</dc:creator>
      <dc:date>2021-06-11T10:15:49Z</dc:date>
    </item>
    <item>
      <title>Re: compare XYZ</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/compare-xyz/m-p/10382622#M25467</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/824630"&gt;@jeremy_tammik&lt;/a&gt;&amp;nbsp;thank you for your suggestion, I will take a look at it!&lt;/P&gt;</description>
      <pubDate>Fri, 11 Jun 2021 13:24:22 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/compare-xyz/m-p/10382622#M25467</guid>
      <dc:creator>jeroen.van.halderen</dc:creator>
      <dc:date>2021-06-11T13:24:22Z</dc:date>
    </item>
  </channel>
</rss>

