Skip to content
This repository was archived by the owner on Nov 22, 2023. It is now read-only.

switch to StaticArrays and get 0.6 working [WIP] #80

Merged
merged 22 commits into from
May 4, 2017
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
12 changes: 1 addition & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,8 @@ os:
- linux
- osx
julia:
- 0.4
- 0.5
- 0.6
- nightly
matrix:
allow_failures:
- julia: nightly

notifications:
email: false
sudo: false
script:
- if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
- julia --inline=no -e 'Pkg.clone(pwd()); Pkg.build("GeometryTypes"); Pkg.test("GeometryTypes"; coverage=true)'
after_success:
- julia -e 'cd(Pkg.dir("GeometryTypes")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(process_folder()); Codecov.submit(process_folder())'
8 changes: 4 additions & 4 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
julia 0.4
FixedSizeArrays
julia 0.6-
StaticArrays
ColorTypes
Compat 0.7.15
Iterators
Compat 0.18
FixedPointNumbers
18 changes: 6 additions & 12 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
environment:
matrix:
- JULIAVERSION: "julialang/bin/winnt/x86/0.4/julia-0.4-latest-win32.exe"
- JULIAVERSION: "julialang/bin/winnt/x64/0.4/julia-0.4-latest-win64.exe"
- JULIAVERSION: "julialang/bin/winnt/x86/0.5/julia-0.5-latest-win32.exe"
- JULIAVERSION: "julialang/bin/winnt/x64/0.5/julia-0.5-latest-win64.exe"
- JULIAVERSION: "julianightlies/bin/winnt/x86/julia-latest-win32.exe"
- JULIAVERSION: "julianightlies/bin/winnt/x64/julia-latest-win64.exe"

branches:
only:
- master
- /release-.*/
# - /release-.*/

notifications:
- provider: Email
Expand All @@ -17,11 +15,6 @@ notifications:
on_build_status_changed: false

install:
# If there's a newer build queued for the same PR, cancel this one
- ps: if ($env:APPVEYOR_PULL_REQUEST_NUMBER -and $env:APPVEYOR_BUILD_NUMBER -ne ((Invoke-RestMethod `
https://ci.appveyor.com/api/projects/$env:APPVEYOR_ACCOUNT_NAME/$env:APPVEYOR_PROJECT_SLUG/history?recordsNumber=50).builds | `
Where-Object pullRequestId -eq $env:APPVEYOR_PULL_REQUEST_NUMBER)[0].buildNumber) { `
throw "There are newer queued builds for this pull request, failing early." }
# Download most recent Julia Windows binary
- ps: (new-object net.webclient).DownloadFile(
$("http://s3.amazonaws.com/"+$env:JULIAVERSION),
Expand All @@ -32,7 +25,8 @@ install:
build_script:
# Need to convert from shallow to complete for Pkg.clone to work
- IF EXIST .git\shallow (git fetch --unshallow)
- C:\projects\julia\bin\julia -e "versioninfo(); Pkg.clone(pwd(), \"GeometryTypes\")"
- C:\projects\julia\bin\julia -e "versioninfo();
Pkg.clone(pwd(), \"GeometryTypes\"); Pkg.build(\"GeometryTypes\")"

test_script:
- C:\projects\julia\bin\julia -e "Pkg.test(\"GeometryTypes\")"
- C:\projects\julia\bin\julia --check-bounds=yes -e "Pkg.test(\"GeometryTypes\")"
20 changes: 15 additions & 5 deletions src/GeometryTypes.jl
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
__precompile__()
module GeometryTypes

using FixedSizeArrays
using StaticArrays
using StaticArrays.FixedSizeArrays
using ColorTypes
import Iterators

import FixedSizeArrays: eltype_or, ndims_or
import FixedPointNumbers # U8


using Compat

import Base: ==,
*,
call,
contains,
convert,
diff,
Expand All @@ -31,6 +32,10 @@ import Base: ==,
union,
unique

if VERSION < v"0.6dev"
import Base: slice
end


include("types.jl")
include("typeutils.jl")
Expand Down Expand Up @@ -174,6 +179,7 @@ export AABB,
row,
radius,
setindex,
slice,
spacedim,
starts,
texturecoordinates,
Expand All @@ -189,6 +195,10 @@ export AABB,
width,
widths,
xwidth,
yheight
yheight,
OffsetInteger,
ZeroIndex,
OneIndex,
GLIndex

end # module
91 changes: 84 additions & 7 deletions src/algorithms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,98 @@ normals{VT,FD,FT,FO}(vertices::Vector{Point{3, VT}},

Compute all vertex normals.
"""
function normals{VT,FD,FT,FO}(vertices::Vector{Point{3, VT}},
faces::Vector{Face{FD,FT,FO}},
NT = Normal{3, VT})
function normals{VT, F <: Face}(
vertices::AbstractVector{Point{3, VT}},
faces::AbstractVector{F},
NT = Normal{3, VT}
)
normals_result = zeros(Point{3, VT}, length(vertices)) # initilize with same type as verts but with 0
for face in faces
v = vertices[face]
# we can get away with two edges since faces are planar.
a = v[2] - v[1]
b = v[3] - v[1]
n = cross(a,b)
for i =1:FD
fi = onebased(face, i)
for i =1:length(F)
fi = face[i]
normals_result[fi] = normals_result[fi] + n
end
end
map!(normalize, normals_result)
map(NT, normals_result)
normals_result .= NT.(normalize.(normals_result))
normals_result
end


"""
Slice an AbstractMesh at the specified Z axis value.
Returns a Vector of LineSegments generated from the faces at the specified
heights. Note: This will not slice in-plane faces.
"""
function slice{VT<:AbstractFloat,FT<:Integer}(mesh::AbstractMesh{Point{3,VT}, Face{3, FT}}, height::Number)

height_ct = length(height)
# intialize the LineSegment array
slice = Simplex{2,Point{2,VT}}[]

for face in mesh.faces
v1,v2,v3 = mesh.vertices[face]
zmax = max(v1[3], v2[3], v3[3])
zmin = min(v1[3], v2[3], v3[3])
if height > zmax
continue
elseif zmin <= height
if v1[3] < height && v2[3] >= height && v3[3] >= height
p1 = v1
p2 = v3
p3 = v2
elseif v1[3] > height && v2[3] < height && v3[3] < height
p1 = v1
p2 = v2
p3 = v3
elseif v2[3] < height && v1[3] >= height && v3[3] >= height
p1 = v2
p2 = v1
p3 = v3
elseif v2[3] > height && v1[3] < height && v3[3] < height
p1 = v2
p2 = v3
p3 = v1
elseif v3[3] < height && v2[3] >= height && v1[3] >= height
p1 = v3
p2 = v2
p3 = v1
elseif v3[3] > height && v2[3] < height && v1[3] < height
p1 = v3
p2 = v1
p3 = v2
else
continue
end

start = Point{2,VT}(p1[1] + (p2[1] - p1[1]) * (height - p1[3]) / (p2[3] - p1[3]),
p1[2] + (p2[2] - p1[2]) * (height - p1[3]) / (p2[3] - p1[3]))
finish = Point{2,VT}(p1[1] + (p3[1] - p1[1]) * (height - p1[3]) / (p3[3] - p1[3]),
p1[2] + (p3[2] - p1[2]) * (height - p1[3]) / (p3[3] - p1[3]))

push!(slice, Simplex{2,Point{2, VT}}(start, finish))
end
end

return slice
end


# TODO this should be checkbounds(Bool, ...)
"""
```
checkbounds{VT,FT,FD,FO}(m::AbstractMesh{VT,Face{FD,FT,FO}})
```

Check the `Face` indices to ensure they are in the bounds of the vertex
array of the `AbstractMesh`.
"""
function Base.checkbounds{VT, FD, FT}(m::AbstractMesh{VT, Face{FD, FT}})
isempty(faces(m)) && return true # nothing to worry about I guess
flat_inds = reinterpret(FT, faces(m))
checkbounds(Bool, vertices(m), flat_inds)
end
21 changes: 21 additions & 0 deletions src/baseutils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,24 @@ function argmax(f, iter)
end
best_arg, best_val
end


w_component{N, T}(::Type{Point{N, T}}) = T(1)
w_component{N, T}(::Type{Vec{N, T}}) = T(0)

@generated function transform_convert{T1 <: StaticVector, T2 <: StaticVector}(::Type{T1}, x::T2)
w = w_component(T1)
n1 = length(T1)
n2 = length(T2)
n1 <= n2 && return :(T1(x))
tupl = Expr(:tuple)
ET = eltype(T1)
for i = 1:n2
push!(tupl.args, :($ET(x[$i])))
end
for i = 1:(n1 - n2 - 1)
push!(tupl.args, :($ET(0)))
end
push!(tupl.args, :($w))
:(T1($tupl))
end
12 changes: 7 additions & 5 deletions src/center.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
centered{N,T}(C::Type{HyperCube{N,T}}) = C(Vec{N,T}(-0.5), T(1))
centered{T<:HyperCube}(::Type{T}) = centered(HyperCube{ndims_or(T, 3), eltype_or(T, Float32)})
function centered{T <: HyperCube}(::Type{T})
centered(HyperCube{ndims_or(T, 3), eltype_or(T, Float32)})
end

centered{N,T}(R::Type{HyperRectangle{N,T}}) = R(Vec{N,T}(-0.5), Vec{N,T}(1))
centered{T<:HyperRectangle}(::Type{T}) = centered(HyperRectangle{ndims_or(T, 3), eltype_or(T, Float32)})
centered{N, T}(R::Type{HyperRectangle{N,T}}) = R(Vec{N,T}(-0.5), Vec{N,T}(1))
centered{T <: HyperRectangle}(::Type{T}) = centered(HyperRectangle{ndims_or(T, 3), eltype_or(T, Float32)})

centered{N,T}(S::Type{HyperSphere{N,T}}) = S(Vec{N,T}(0), T(0.5))
centered{T<:HyperSphere}(::Type{T}) = centered(HyperSphere{ndims_or(T, 3), eltype_or(T, Float32)})
centered{N, T}(S::Type{HyperSphere{N, T}}) = S(Vec{N,T}(0), T(0.5))
centered{T <: HyperSphere}(::Type{T}) = centered(HyperSphere{ndims_or(T, 3), eltype_or(T, Float32)})
23 changes: 0 additions & 23 deletions src/checkbounds.jl
Original file line number Diff line number Diff line change
@@ -1,23 +0,0 @@
"""
```
checkbounds{VT,FT,FD,FO}(m::AbstractMesh{VT,Face{FD,FT,FO}})
```

Check the `Face` indices to ensure they are in the bounds of the vertex
array of the `AbstractMesh`.
"""
function Base.checkbounds{VT,FT,FD,FO}(m::AbstractMesh{VT,Face{FD,FT,FO}})
isempty(faces(m)) && return true # nothing to worry about I guess

# index max and min
const i = one(FO) + FO # normalize face offset
s = length(vertices(m)) + FO

for face in faces(m)
# I hope this is unrolled
for elt in face
i <= elt && elt <= s || return false
end
end
return true
end
18 changes: 12 additions & 6 deletions src/convexhulls.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@


Base.eltype(fg::AFG) = eltype(typeof(fg))
Base.length(fg::AFG) = length(vertices(fg))
nvertices(fg::AFG) = length(fg)
Expand All @@ -17,7 +19,9 @@ Base.deleteat!(c::AbstractFlexibleGeometry, i) = (deleteat!(vertices(c), i); c)
Base.copy{FG <: AFG}(fl::FG) = FG(copy(vertices(fl)))
push(fl::AFG, pt) = push!(copy(fl), pt)

vertices(s::Simplex) = s._
vertices{T}(x::AbstractFlexibleGeometry{T}) = x._
vertices(s::Simplex) = Tuple(s)

standard_cube_vertices(::Type{Val{1}}) = [Vec(0), Vec(1)]
_vcat(v1,v2) = Vec(Tuple(v1)..., Tuple(v2)...)
function _combine_vcat(arr1, arr2)
Expand Down Expand Up @@ -49,13 +53,15 @@ end
end

vertices(c::HyperCube) = vertices(convert(HyperRectangle, c))
vertices(s::AbstractConvexHull) = s._
#vertices(s::AbstractConvexHull) = Tuple(s)

vertexmat{M, T}(s::Simplex{M, T}) = Mat{length(T)}(vcat(vertices(s)...))
vertexmat{M}(s::AbstractGeometry{M}) = Mat{M}(vcat(vertices(s)...))

vertexmat(s::Simplex) = Mat(map(Tuple, vertices(s)))
vertexmat(s::AbstractGeometry) = Mat(map(Tuple, vertices(s)))
function vertexmat(s::AbstractFlexibleGeometry)
tuptup = tuple(map(Tuple, vertices(s))...)
Mat(tuptup) :: Mat{spacedim(s), nvertices(s), numtype(s)}
verts = vcat(vertices(s)...)
M, N = spacedim(s), nvertices(s)
Mat{M, N}(verts)
end
vertexmatrix(s::AbstractConvexHull) = Matrix(vertexmat(s))::Matrix{numtype(s)}

Expand Down
Loading