isPartner, isSame() & isEqual()

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
paullee
Veteran
Posts: 5098
Joined: Wed May 04, 2016 3:58 pm

isPartner, isSame() & isEqual()

Post by paullee »

Have learned about the methods from discussion e.g. https://forum.freecadweb.org/viewtopic.php?t=16572

Curious about the result of below codes.

Any reasons why all comparison results are False ? :D

Thanks.

Code: Select all

>>> import Part
>>> g = Part.LineSegment(FreeCAD.Vector(0,0,0), FreeCAD.Vector(1000,0,0))
>>> e = g.toShape()
>>> ec = e.copy()
>>> e.isEqual(ec)
False
>>> e.isSame(ec)
False
>>> e.isPartner(ec)
False
>>> ec.isPartner(e)
False
>>> ec.isSame(e)
False
>>> ec.isEqual(e)
False

paullee
Veteran
Posts: 5098
Joined: Wed May 04, 2016 3:58 pm

Re: isPartner, isSame() & isEqual()

Post by paullee »

When both edges are constructed from same geometry ...

Code: Select all

>>> import Part
>>> g = Part.LineSegment(FreeCAD.Vector(0,0,0), FreeCAD.Vector(1000,0,0))
>>> e = g.toShape()
>>> ec = g.toShape()
>>> e.isEqual(ec)
False
>>> e.isSame(ec)
False
>>> e.isPartner(ec)
False
>>> 
paullee
Veteran
Posts: 5098
Joined: Wed May 04, 2016 3:58 pm

Re: isPartner, isSame() & isEqual()

Post by paullee »

And test again what @bernd had tried, and add isPartner()

[EDIT - to correct typo in original code]
I thought if isSame is True, isPartner() should always be True ?

# isPartner(): Share the same TShape, but may have a different Location and may have a different Orientation
# isSame(): share the same TShape, have the same Location but may have a different Orientation
# isEqual(): share the same TShape, have the same Location and have the same Orientation

Code: Select all

>>> l1 = Part.makeLine(FreeCAD.Vector(0,0,0),FreeCAD.Vector(10,10,10))
>>> l2 = Part.makeLine(FreeCAD.Vector(0,0,0),FreeCAD.Vector(10,10,10))

[EDIT - typo and resulted 'corrected' ]
>>> l1.isSame(l2)
False

>>> l1.isEqual(l2)
False
>>> l1.isPartner(l2)
False
>>> 
wmayer
Founder
Posts: 20245
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: isPartnet, isSame() & isEqual()

Post by wmayer »

paullee wrote: Mon Sep 27, 2021 3:44 pm >>> ec = e.copy()
paullee wrote: Mon Sep 27, 2021 3:58 pm >>> e = g.toShape()
>>> ec = g.toShape()
In both cases you create independent shapes and that's why they don't share a common TShape.

Here is an example to see the three functions in action:

Code: Select all

box = Part.makeBox(1,1,1)
Face4 and Face6 share a common edge
f4 = box.Face4
f6 = box.Face6
e1 = f4.Edge3
e2 = f6.Edge2
e1.isSame(e2) # True because same geometry and placement
e1.isEqual(e2) # False because orientation is different
e1.isPartner(e2) # True because same geometry
paullee
Veteran
Posts: 5098
Joined: Wed May 04, 2016 3:58 pm

Re: isPartner, isSame() & isEqual()

Post by paullee »

wmayer wrote: Mon Sep 27, 2021 4:10 pm In both cases you create independent shapes and that's why they don't share a common TShape.
...

Code: Select all

...
e1.isSame(e2) # True because same geometry and placement
e1.isEqual(e2) # False because orientation is different
e1.isPartner(e2) # True because same geometry
[EDIT - to avoid confusion, probably to myself, strike out below in fact the whole post :) ]

Many thanks taking time to explain :) Just can't make sense what isPartner means. I thought if isSame is True, then isPartner is always True.

So why in Bernd's example, isPartner() returns False ? as isSame() returned True


[EDIT - code deleted]

And it seems to me :

> l1 = PartLine(geometry) (isSame) l2 = PartLine(geometry)
maybe same as
> e = geometry.toShape() (isSmae) ec = geometry.toShape()
?

But all comparisons return False.


[EDIT - code deleted]

It seems in Bernd's example, isSame() return True because underlying Geometry is Same (l1 and l2 are 2 separate TShape?).
But in my example, isSame() is comparing the TShape (rather than underlying Geometry)?
wmayer
Founder
Posts: 20245
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: isPartnet, isSame() & isEqual()

Post by wmayer »

paullee wrote: Mon Sep 27, 2021 5:11 pm Just can't make sense what isPartner means. I thought if isSame is True, then isPartner is always True.
isPartner() is the weakest of all three and only requires that two shapes share the same TShape.
isSame() is like isPartner() but additionally requires the same placement
isEqual() is like isSame() but additionally requires the same orientation
So why in Bernd's example, isPartner() returns False ? as isSame() returned True
Didn't you read ickby's explanation? In the example l1.isSame(l1) is used, i.e. the shape to itself and this of course is always equal.
paullee
Veteran
Posts: 5098
Joined: Wed May 04, 2016 3:58 pm

Re: isPartner, isSame() & isEqual()

Post by paullee »

Ah thanks :D I read that post several time but apparently did not correlate icky's comment and even bernd's reply to the exact line of the code used :lol:


In fact, I had used isSame() for a while to compare the edges sorted afterwards by Part.SortEdges() / Part.getSortedClusters(). It worked.

Trying to see if these comparisons are good for others operation e.g. shape.generalFuse, seems not.


Thanks again anyway !
Post Reply