Boolean null and universal sets

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
AdrianBowyer
Posts: 15
Joined: Tue Nov 01, 2016 5:36 pm

Boolean null and universal sets

Post by AdrianBowyer »

A feature request.

When writing Python to build shapes it'd be very useful to have the Universal and Null sets available in the Part API. (I suspect these are already used internally.) Then one could write:

Code: Select all

a = Part.Null()
for i in range(0, n):
 a = a.fuse(MyShapeThatDependsOnN(n))
or

Code: Select all

a = Part.Universal()
for i in range(0, n):
 a = a.common(MyShapeThatDependsOnN(n))
Both would also be useful in conditional code:

Code: Select all

a = SomeShape()
if n > 0:
 b = MyShapeThatDependsOnN(n)
else:
 b = Part.Null()
a = a.fuse(b)
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: Boolean null and universal sets

Post by Kunda1 »

bumping this for more disussion
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
wmayer
Founder
Posts: 20302
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Boolean null and universal sets

Post by wmayer »

Part.Shape() delivers the null shape. A universal shape doesn't exist, only a half-space solid is supported by the kernel.
The best what you can do to have a universal shape is creating a sphere with a very high radius:

Code: Select all

Part.makeSphere(1e10)
AdrianBowyer
Posts: 15
Joined: Tue Nov 01, 2016 5:36 pm

Re: Boolean null and universal sets

Post by AdrianBowyer »

wmayer wrote: Thu Oct 01, 2020 6:35 pm Part.Shape() delivers the null shape. A universal shape doesn't exist, only a half-space solid is supported by the kernel.
The best what you can do to have a universal shape is creating a sphere with a very high radius:

Code: Select all

Part.makeSphere(1e10)
Sadly that doesn't work. The first piece of code in my original post then gives the error:

<class 'Part.OCCError'>: Base shape is null
AdrianBowyer
Posts: 15
Joined: Tue Nov 01, 2016 5:36 pm

Re: Boolean null and universal sets

Post by AdrianBowyer »

AdrianBowyer wrote: Thu Aug 05, 2021 9:51 am
Sadly that doesn't work. The first piece of code in my original post then gives the error:

<class 'Part.OCCError'>: Base shape is null
I use this to make the null set, which is horrible, but which works:

Code: Select all

def NullSet():
 a = Part.makeBox(1, 1, 1)
 a.translate(Base.Vector(10, 10, 10))
 return a.common(Part.makeBox(1, 1, 1))
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: Boolean null and universal sets

Post by Kunda1 »

AdrianBowyer wrote: Thu Aug 05, 2021 9:57 am
AdrianBowyer wrote: Thu Aug 05, 2021 9:51 am
Sadly that doesn't work. The first piece of code in my original post then gives the error:

<class 'Part.OCCError'>: Base shape is null
I use this to make the null set, which is horrible, but which works:

Code: Select all

def NullSet():
 a = Part.makeBox(1, 1, 1)
 a.translate(Base.Vector(10, 10, 10))
 return a.common(Part.makeBox(1, 1, 1))
Hello @AdrianBowyer, It's excellent to see you on this forum! Just a quick question, what version of FreeCAD are you using? (please copy/paste About) Thanks!
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
AdrianBowyer
Posts: 15
Joined: Tue Nov 01, 2016 5:36 pm

Re: Boolean null and universal sets

Post by AdrianBowyer »

Kunda1 wrote: Thu Aug 05, 2021 9:59 am Hello @AdrianBowyer, It's excellent to see you on this forum! Just a quick question, what version of FreeCAD are you using? (please copy/paste About) Thanks!
OS: Ubuntu 20.04.2 LTS (ubuntu:GNOME/ubuntu)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.24291 (Git) AppImage
Build type: Release
Branch: (HEAD detached at 0.19.2)
Hash: 7b5e18a0759de778b74d3a5c17eba9cb815035ac
Python version: 3.8.8
Qt version: 5.12.9
Coin version: 4.0.0
OCC version: 7.4.0
Locale: C/Default (C)
wmayer
Founder
Posts: 20302
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Boolean null and universal sets

Post by wmayer »

git commit 666f67f8d9

Allows you to write:

Code: Select all

a = Part.Shape() # Null shape
b = Part.makeBox(1,1,1)

c = b.cut(a)
c.isNull()

c = a.cut(b)
c.isNull()

c = a.fuse(b)
c.isNull()

c = b.fuse(a)
c.isNull()

c = a.common(b)
c.isNull()

c = b.common(a)
c.isNull()
AdrianBowyer
Posts: 15
Joined: Tue Nov 01, 2016 5:36 pm

Re: Boolean null and universal sets

Post by AdrianBowyer »

Hi!

That doesn't work, I'm afraid. It gives a

<class 'Part.OCCError'>: Base shape is null

error, by which it means the shape is undefined. The CSG null set is a perfectly well defined shape - empty space.
wmayer
Founder
Posts: 20302
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Boolean null and universal sets

Post by wmayer »

Have you built the latest version that includes these changes?
Post Reply