Skip to content

Commit

Permalink
Merge pull request #41 from sjkelly/sjk/setops
Browse files Browse the repository at this point in the history
use base setop names, closes #39
  • Loading branch information
sjkelly authored Jul 3, 2019
2 parents 03320f2 + b8dacc7 commit 55d633a
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 15 deletions.
18 changes: 9 additions & 9 deletions examples/csg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ translate([24,0,0]) {

using Descartes

a = translate([-24,0,0])CSGUnion(
Cuboid([15,15,15], center=true),
Sphere(10))
a = translate([-24,0,0])union(
Cuboid([15,15,15], center=true),
Sphere(10))

b = CSGIntersect(
Cuboid([15,15,15], center=true),
Sphere(10))
b = intersect(
Cuboid([15,15,15], center=true),
Sphere(10))

c = translate([24,0,0])CSGDiff(
Cuboid([15,15,15], center=true),
Sphere(10))
c = translate([24,0,0])diff(
Cuboid([15,15,15], center=true),
Sphere(10))

m = HomogenousMesh(a,b,c)

Expand Down
2 changes: 1 addition & 1 deletion examples/example001.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function example001()
rotate(pi/2, rot)Cylinder(r, h, center=true)
end

CSGDiff(
diff(
Sphere(r_from_dia(size)),
rotcy([0, 0, 0], cy_r, cy_h),
rotcy([1, 0, 0], cy_r, cy_h),
Expand Down
2 changes: 1 addition & 1 deletion examples/fea.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ for i = 1:hole_ct
h = translate([hole_interval*i, -1, beam_size[3]/2])*
rotate(-pi/2, [1,0,0])*
Cylinder(hole_d/2, beam_size[2]+2, center=false)
global c = CSGDiff(c, h)
global c = diff(c, h)
end

save("fea.ply",HomogenousMesh(c))
2 changes: 1 addition & 1 deletion examples/radiused_union.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ c2 = Cuboid([4,4.0,4])
cyl1 = rotate(pi/6, [1,0,0])translate([2,2,0])Cylinder(1.0,10.0)

u = Shell(0.5)RadiusedCSGUnion(1,c2, cyl1)
u2 = CSGDiff(u, Cuboid([2,2,2]))
u2 = diff(u, Cuboid([2,2,2]))

m = HomogenousMesh(u2)

Expand Down
3 changes: 1 addition & 2 deletions src/Descartes.jl
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
module Descartes

import Base: *
import Base: *, union, diff, intersect
import GeometryTypes: HyperRectangle,
HomogenousMesh,
SignedDistanceField

using GeometryTypes,
FileIO,
StaticArrays,
# JLD,
Meshing,
MeshIO,
LinearAlgebra
Expand Down
29 changes: 28 additions & 1 deletion src/constructors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ function Piping(r, pts)
Piping(Float64(r), ptsc, SMatrix{4,4}(1.0*I), SMatrix{4,4}(1.0*I))
end

# CSG
#
#
# CSG Operations
#
#

# Union
function CSGUnion(l::AbstractPrimitive{N1,T1}, r::AbstractPrimitive{N2,T2}) where {N1, N2, T1, T2}
Expand All @@ -57,6 +61,11 @@ CSGUnion(x::AbstractPrimitive) = x
CSGUnion(::Nothing, x::AbstractPrimitive) = x
CSGUnion(x::AbstractPrimitive, ::Nothing) = x

union(l::AbstractPrimitive, r::AbstractPrimitive...) = CSGUnion(l,r...)

union(x::AbstractPrimitive) = x
union(::Nothing, x::AbstractPrimitive) = x
union(x::AbstractPrimitive, ::Nothing) = x

# Radiused Union
function RadiusedCSGUnion(radius::Real, l::AbstractPrimitive{N1,T1}, r::AbstractPrimitive{N2,T2}) where {N1, N2, T1, T2}
Expand All @@ -79,16 +88,34 @@ CSGDiff(x::AbstractPrimitive) = x
CSGDiff(::Nothing, x::AbstractPrimitive) = x
CSGDiff(x::AbstractPrimitive, ::Nothing) = x

diff(l::AbstractPrimitive, r::AbstractPrimitive...) = CSGDiff(l,r...)

diff(x::AbstractPrimitive) = x
diff(::Nothing, x::AbstractPrimitive) = x
diff(x::AbstractPrimitive, ::Nothing) = x

# Intersect

function CSGIntersect(l::AbstractPrimitive{N1,T1}, r::AbstractPrimitive{N2,T2}) where {N1, N2, T1, T2}
N1 == N2 || error("cannot create CSG between objects in R$N1 and R$N2")
return CSGIntersect{N1,T1, typeof(l), typeof(r)}(l,r)
end

function CSGIntersect(l::AbstractPrimitive{N1,T1}, r::AbstractPrimitive{N2,T2}...) where {N1, N2, T1, T2}
N1 == N2 || error("cannot create CSG between objects in R$N1 and R$N2")
return CSGIntersect(l,CSGIntersect(r[1], r[2:end]...))
end

CSGIntersect(x::AbstractPrimitive) = x
CSGIntersect(::Nothing, x::AbstractPrimitive) = x
CSGIntersect(x::AbstractPrimitive, ::Nothing) = x

intersect(l::AbstractPrimitive, r::AbstractPrimitive...) = CSGIntersect(l,r...)

intersect(x::AbstractPrimitive) = x
intersect(::Nothing, x::AbstractPrimitive) = x
intersect(x::AbstractPrimitive, ::Nothing) = x

# Shell

function Shell(r)
Expand Down

0 comments on commit 55d633a

Please sign in to comment.