From b1d37daf047d405bf7d6825b78a628d52ca53f86 Mon Sep 17 00:00:00 2001 From: Steve Kelly Date: Sun, 12 Apr 2015 17:54:38 -0400 Subject: [PATCH] allow openscad style translation syntax --- src/Descartes.jl | 4 ++++ src/primitives.jl | 5 +++++ src/transforms.jl | 13 +++++++++++++ 3 files changed, 22 insertions(+) create mode 100644 src/transforms.jl diff --git a/src/Descartes.jl b/src/Descartes.jl index 1b96524..a3d5dc1 100644 --- a/src/Descartes.jl +++ b/src/Descartes.jl @@ -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 diff --git a/src/primitives.jl b/src/primitives.jl index f0904d5..e441347 100644 --- a/src/primitives.jl +++ b/src/primitives.jl @@ -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 diff --git a/src/transforms.jl b/src/transforms.jl new file mode 100644 index 0000000..6a7d32a --- /dev/null +++ b/src/transforms.jl @@ -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