Skip to content

Commit

Permalink
allow openscad style translation syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
sjkelly committed Apr 12, 2015
1 parent cafef8a commit b1d37da
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Descartes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ module Descartes
#using Meshes

include("primitives.jl")
include("transforms.jl")
include("csg.jl")
include("frep.jl")

# primitives
export Cuboid, Cylinder, Sphere

# transforms
export Translation, translate

# CSG
export CSGUnion, CSGDiff, CSGIntersect

Expand Down
5 changes: 5 additions & 0 deletions src/primitives.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ type Cuboid{N, T} <: AbstractPrimitive{N, T}
location::NTuple{N, T}
end

function translate{T}(c::Cuboid{3,T}, loc::NTuple{3,T})
new_loc = (c.location[1]+loc[1], c.location[2]+loc[2], c.location[3]+loc[3])
Cuboid{3,T}(c.dimensions, new_loc)
end

type Cylinder{N, T} <: AbstractPrimitive{N, T}
radius::T
height::T
Expand Down
13 changes: 13 additions & 0 deletions src/transforms.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
abstract AbstractTransform{N, T}

type Translation{N,T} <: AbstractTransform{N,T}
location::NTuple{N, T}
end

function translate(x,y,z)
Translation((x,y,z))
end

function (*){N,T}(translation::Translation{N,T}, obj::AbstractPrimitive{N,T})
translate(obj, translation.location)
end

0 comments on commit b1d37da

Please sign in to comment.