Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initial sketch of 2d #33

Merged
merged 2 commits into from
May 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/Descartes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,13 @@ include("opencl.jl")
# GeometryTypes
export Point

# primitives
# 3d primitives
export Cuboid, Cylinder, Sphere, Piping

# 2d primitives

export Square, Circle

# transforms
export Transform, Translation, translate, rotate

Expand Down
8 changes: 8 additions & 0 deletions src/constructors.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
function Square(dims;center=false)
@assert length(dims) == 2
lb = SVector(0.,0.)
center && (lb = -SVector{2,Float64}(dims)/2)
Square(SVector{2,Float64}(dims), lb, SMatrix{3,3}(1.0*I), SMatrix{3,3}(1.0*I))
end


function Cuboid(dims;center=false)
@assert length(dims) == 3
lb = SVector(0.,0.,0.)
Expand Down
5 changes: 5 additions & 0 deletions src/frep.jl
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,8 @@ function FRep(p::Piping{T}, x, y, z) where {T}
end
val - p.radius
end

function FRep(p::LinearExtrude, _x, _y, _z)
r = FRep(s.primitive, x, y, z)
max(max(-z,z-p.height), r)
end
5 changes: 5 additions & 0 deletions src/hyperrectangles.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
function HyperRectangle(square::Square{T}) where {T}
orig = HyperRectangle{2,T}(square.lowercorner, square.dimensions)
transform(square.transform, orig)
end

function HyperRectangle(cube::Cuboid{T}) where {T}
orig = HyperRectangle{3,T}(cube.lowercorner, cube.dimensions)
transform(cube.transform, orig)
Expand Down
13 changes: 12 additions & 1 deletion src/operations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ function transform(it::SMatrix, x::AbstractVector) where {T}
transform(it, x...)
end

function transform(t::SMatrix, h::HyperRectangle)
function transform(t::SMatrix, h::HyperRectangle{3,T}) where {T}
p_1 = t*SVector(h.origin... , 1)
p_2 = t*SVector(h.widths... , 1)
p_3 = t*SVector(h.origin[1]+h.widths[1],h.origin[2],h.origin[3], 1)
Expand All @@ -101,6 +101,17 @@ function transform(t::SMatrix, h::HyperRectangle)
HyperRectangle(x_o, y_o, z_o, x_w-x_o, y_w-y_o, z_w-z_o)
end

function transform(t::SMatrix, h::HyperRectangle{2,T}) where {T}
p_1 = t*SVector(h.origin... , 1)
p_2 = t*SVector(h.widths... , 1)
p_3 = t*SVector(h.origin[1]+h.widths[1],h.origin[2], 1)
p_4 = t*SVector(h.origin[1],h.origin[2]+h.widths[2], 1)
x_o = min(p_1[1],p_2[1],p_3[1],p_4[1])
y_o = min(p_1[2],p_2[2],p_3[2],p_4[2])
x_w = max(p_1[1],p_2[1],p_3[1],p_4[1])
y_w = max(p_1[2],p_2[2],p_3[2],p_4[2])
HyperRectangle(x_o, y_o, x_w-x_o, y_w-y_o)
end

#function clarkcatmull!(n::Integer, pipe::Pipe{Float64})
# length(pipe.points) < 3 && return
Expand Down
22 changes: 21 additions & 1 deletion src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,22 @@ abstract type AbstractCSGTree{N,T} <: AbstractPrimitive{N, T} end
abstract type AbstractOperation{N,T} <: AbstractPrimitive{N,T} end
abstract type AbstractTransform{N,T} end

# Geometric Primitives
# 2D Geometric Primitives

struct Square{T} <: AbstractPrimitive{2, T}
dimensions::SVector{2,T}
lowercorner::SVector{2,T}
transform::SMatrix{3,3,T,9}
inv_transform::SMatrix{3,3,T,9}
end

struct Circle{T} <: AbstractPrimitive{2, T}
radius::T
transform::SMatrix{3,3,T,9}
inv_transform::SMatrix{3,3,T,9}
end

# 3D Geometric Primitives

struct Cuboid{T} <: AbstractPrimitive{3, T}
dimensions::SVector{3,T}
Expand Down Expand Up @@ -70,3 +85,8 @@ struct Shell{T} <: AbstractPrimitive{3,T}
primitive::T
distance
end

struct LinearExtrude{T} <: AbstractPrimitive{3,T}
primitive::T
distance
end
6 changes: 6 additions & 0 deletions test/2d.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@testset "2D Geometry" begin

c = Square([1,2])
HyperRectangle(c)

end
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import GeometryTypes
include("tranforms.jl")
include("opencl.jl")
include("primitives.jl")
include("2d.jl")
include("hyperrectangles.jl")
include("distancefield.jl")
include("meshes.jl")
Expand Down