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

[wip] drop 0.4 + fixes for 0.6 #79

Closed
wants to merge 2 commits into from
Closed
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
5 changes: 3 additions & 2 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
julia 0.4
julia 0.5
FixedSizeArrays
ColorTypes
Compat 0.7.15
Compat 0.18
Iterators
FixedPointNumbers
7 changes: 6 additions & 1 deletion src/GeometryTypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ module GeometryTypes
using FixedSizeArrays
using ColorTypes
import Iterators
import FixedPointNumbers # U8

import FixedSizeArrays: eltype_or, ndims_or
using Compat

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

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


include("types.jl")
include("typeutils.jl")
Expand Down Expand Up @@ -168,6 +172,7 @@ export AABB,
row,
radius,
setindex,
slice,
spacedim,
starts,
texturecoordinates,
Expand Down
8 changes: 4 additions & 4 deletions src/faces.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@ convert{T1<:Face}(::Type{T1}, f::T1) = f
convert{T1<:Face, T2<:Face}(::Type{T1}, f::T2) = T1(f)

# Silly duplication, but call(::FixedVector, ::Any) = convert is overloaded in FixedSizeArrays
@compat (::Type{F}){F<:Face}(f::F) = f
(::Type{F}){F<:Face}(f::F) = f

@compat function (::Type{Face{N, T, O}}){T, T2, O, N}(f::Face{N, T2, O})
function (::Type{Face{N, T, O}}){T, T2, O, N}(f::Face{N, T2, O})
Face{N, T, O}(convert(NTuple{N, T}, getfield(f, 1)))
end
immutable IndexConvertFunc{T1, T2}
f::T2
end
@compat function (ifunc::IndexConvertFunc{Face{N,T1,O1}, Face{N,T2,O2}}){N,T1,T2,O1,O2}(i)
function (ifunc::IndexConvertFunc{Face{N,T1,O1}, Face{N,T2,O2}}){N,T1,T2,O1,O2}(i)
Int(ifunc.f[i])+Int(O1)-Int(O2)
end
@compat function (T::Type{Face{N, T1, O1}}){N, T1, O1, F<:Face}(f::F)
function (T::Type{Face{N, T1, O1}}){N, T1, O1, F<:Face}(f::F)
map(IndexConvertFunc{T,F}(f), T)
end

Expand Down
12 changes: 6 additions & 6 deletions src/hyperrectangles.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ function _split{H<:HyperRectangle}(b::H, axis, value)
end

# empty constructor such that update will always include the first point
@compat function (HR::Type{HyperRectangle{N,T}}){T,N}()
function (HR::Type{HyperRectangle{N,T}}){T,N}()
HR(Vec{N,T}(typemax(T)), Vec{N,T}(typemin(T)))
end

# conversion from other HyperRectangles
@compat function (HR::Type{HyperRectangle{N,T1}}){N,T1,T2}(a::HyperRectangle{N,T2})
function (HR::Type{HyperRectangle{N,T1}}){N,T1,T2}(a::HyperRectangle{N,T2})
HR(Vec{N, T1}(minimum(a)), Vec{N, T1}(widths(a)))
end

Expand All @@ -35,7 +35,7 @@ function HyperRectangle{N,T1,T2}(v1::Vec{N,T1}, v2::Vec{N,T2})
end


@compat function (HR::Type{HyperRectangle{N,T}}){N,T}(a::GeometryPrimitive)
function (HR::Type{HyperRectangle{N,T}}){N,T}(a::GeometryPrimitive)
HR(Vec{N, T}(minimum(a)), Vec{N, T}(widths(a)))
end
"""
Expand Down Expand Up @@ -63,7 +63,7 @@ function HyperRectangle{T}(r::SimpleRectangle{T})
HyperRectangle{2,T}(r)
end

@compat function (::Type{HyperRectangle{N,T}}){N,T}(r::SimpleRectangle)
function (::Type{HyperRectangle{N,T}}){N,T}(r::SimpleRectangle)
if N > 2
return HyperRectangle(Vec{N, T}(T(r.x), T(r.y), Vec{N-2,T}(zero(T))...),
Vec{N, T}(T(r.w), T(r.h), Vec{N-2,T}(zero(T))...))
Expand Down Expand Up @@ -162,7 +162,7 @@ end
"""
Construct a HyperRectangle enclosing all points.
"""
@compat function (t::Type{HyperRectangle{N1, T1}}){N1, T1, PT<:Point}(
function (t::Type{HyperRectangle{N1, T1}}){N1, T1, PT<:Point}(
geometry::AbstractArray{PT}
)
N2, T2 = length(PT), eltype(PT)
Expand Down Expand Up @@ -195,7 +195,7 @@ maximum{T}(a::SimpleRectangle{T}) = Point{2, T}(a.x + widths(a)[1], a.y +widths(
minimum{T}(a::SimpleRectangle{T}) = Point{2, T}(a.x, a.y)
origin{T}(a::SimpleRectangle{T}) = Point{2, T}(a.x, a.y)

@compat (::Type{SimpleRectangle}){T}(val::Vec{2, T}) = SimpleRectangle{T}(0, 0, val...)
(::Type{SimpleRectangle}){T}(val::Vec{2, T}) = SimpleRectangle{T}(0, 0, val...)
function SimpleRectangle{T}(position::Vec{2,T}, width::Vec{2,T})
SimpleRectangle{T}(position..., width...)
end
Expand Down
4 changes: 2 additions & 2 deletions src/hypersphere.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@compat (::Type{Sphere})(x...) = HyperSphere(x...)
(::Type{Sphere})(x...) = HyperSphere(x...)

@compat (::Type{Circle})(x...) = HyperSphere(x...)
(::Type{Circle})(x...) = HyperSphere(x...)

widths{N, T}(c::HyperSphere{N, T}) = Vec{N, T}(radius(c)*2)
radius(c::HyperSphere) = c.r
Expand Down
20 changes: 10 additions & 10 deletions src/meshes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ end

# Needed to not get into an stack overflow
convert{M <: AbstractMesh}(::Type{M}, mesh::AbstractGeometry) = M(mesh)
@compat (::Type{HM1}){HM1 <: AbstractMesh}(mesh::HM1) = mesh
(::Type{HM1}){HM1 <: AbstractMesh}(mesh::HM1) = mesh

"""
Uses decompose to get all the converted attributes from the meshtype and
Expand All @@ -57,7 +57,7 @@ Getindex can be defined for any arbitrary geometric type or exotic mesh type.
This way, we can make sure, that you can convert most of the meshes from one type to the other
with minimal code.
"""
@compat function (::Type{HM1}){HM1 <: AbstractMesh}(primitive::Union{AbstractMesh, GeometryPrimitive})
function (::Type{HM1}){HM1 <: AbstractMesh}(primitive::Union{AbstractMesh, GeometryPrimitive})
result = Dict{Symbol, Any}()
for (field, target_type) in zip(fieldnames(HM1), HM1.parameters)
if target_type != Void
Expand All @@ -77,7 +77,7 @@ end
isvoid{T}(::Type{T}) = false
isvoid(::Type{Void}) = true
isvoid{T}(::Type{Vector{T}}) = isvoid(T)
@compat function (::Type{HM1}){HM1 <: HomogenousMesh}(primitive::HomogenousMesh)
function (::Type{HM1}){HM1 <: HomogenousMesh}(primitive::HomogenousMesh)
fnames = fieldnames(HM1)
args = ntuple(nfields(HM1)) do i
field, target_type = fnames[i], fieldtype(HM1, i)
Expand All @@ -98,7 +98,7 @@ end
#Should be:
#function call{M <: HMesh, VT <: Point, FT <: Face}(::Type{M}, vertices::Vector{VT}, faces::Vector{FT})
# Haven't gotten around to implement the types correctly with abstract types in FixedSizeArrays
@compat function (::Type{M}){M <: HMesh, VT, FT <: Face}(
function (::Type{M}){M <: HMesh, VT, FT <: Face}(
vertices::Vector{Point{3, VT}}, faces::Vector{FT}
)
msh = PlainMesh{VT, FT}(vertices=vertices, faces=faces)
Expand All @@ -122,12 +122,12 @@ end
"""
Creates a mesh from keyword arguments, which have to match the field types of the given concrete mesh
"""
@compat (::Type{M}){M <: HMesh}(; kw_args...) = M(Dict{Symbol, Any}(kw_args))
(::Type{M}){M <: HMesh}(; kw_args...) = M(Dict{Symbol, Any}(kw_args))

"""
Creates a new mesh from a dict of `fieldname => value` and converts the types to the given meshtype
"""
@compat function (::Type{M}){M <: HMesh}(attribs::Dict{Symbol, Any})
function (::Type{M}){M <: HMesh}(attribs::Dict{Symbol, Any})
newfields = map(zip(fieldnames(HomogenousMesh), M.parameters)) do field_target_type
field, target_type = field_target_type
default = fieldtype(HomogenousMesh, field) <: Vector ? Void[] : nothing
Expand All @@ -139,7 +139,7 @@ end
"""
Creates a new mesh from an old one, with changed attributes given by the keyword arguments
"""
@compat function (::Type{M}){M <: HMesh}(mesh::AbstractMesh, attributes::Dict{Symbol, Any})
function (::Type{M}){M <: HMesh}(mesh::AbstractMesh, attributes::Dict{Symbol, Any})
newfields = map(fieldnames(HomogenousMesh)) do field
get(attributes, field, getfield(mesh, field))
end
Expand All @@ -148,7 +148,7 @@ end
"""
Creates a new mesh from an old one, with a new constant attribute (like a color)
"""
@compat function (::Type{HM}){HM <: HMesh, ConstAttrib}(mesh::AbstractMesh, constattrib::ConstAttrib)
function (::Type{HM}){HM <: HMesh, ConstAttrib}(mesh::AbstractMesh, constattrib::ConstAttrib)
result = Dict{Symbol, Any}()
for (field, target_type) in zip(fieldnames(HM), HM.parameters)
if target_type <: ConstAttrib
Expand All @@ -168,7 +168,7 @@ end
"""
Creates a new mesh from a tuple of a geometry type and a constant attribute
"""
@compat function (::Type{HM}){HM <: HMesh, ConstAttrib, P<:AbstractGeometry}(x::Tuple{P, ConstAttrib})
function (::Type{HM}){HM <: HMesh, ConstAttrib, P<:AbstractGeometry}(x::Tuple{P, ConstAttrib})
any, const_attribute = x
add_attribute(HM(any), const_attribute)
end
Expand Down Expand Up @@ -235,7 +235,7 @@ end
immutable MeshMulFunctor{T}
matrix::Mat{4,4,T}
end
@compat (m::MeshMulFunctor{T}){T}(vert) = Vec{3, T}(m.matrix*Vec{4, T}(vert..., 1))
(m::MeshMulFunctor{T}){T}(vert) = Vec{3, T}(m.matrix*Vec{4, T}(vert..., 1))
function *{T}(m::Mat{4,4,T}, mesh::AbstractMesh)
msh = deepcopy(mesh)
map!(MeshMulFunctor(m), msh.vertices)
Expand Down
2 changes: 1 addition & 1 deletion src/polygons.jl
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ function topoint{T}(::Type{Point{2, T}}, p::Point{3, T})
Point{2, T}(p[1], p[2])
end

@compat function (::Type{M}){M <: AbstractMesh, P <: Point}(
function (::Type{M}){M <: AbstractMesh, P <: Point}(
points::AbstractArray{P}
)
faces = polygon2faces(points, facetype(M))
Expand Down
8 changes: 4 additions & 4 deletions src/primitives.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

@compat function (meshtype::Type{T}){T <: AbstractMesh}(c::Pyramid)
function (meshtype::Type{T}){T <: AbstractMesh}(c::Pyramid)
T(decompose(vertextype(T), c), decompose(facetype(T), c))
end

Expand All @@ -10,7 +10,7 @@ Just walk through all attributes of the mesh and try to decompose it.
If there are attributes missing, just hope it will get managed by the mesh constructor.
(E.g. normal calculation, which needs to have vertices and faces present)
"""
@compat function (meshtype::Type{T}){T <: AbstractMesh}(c::GeometryPrimitive, args...)
function (meshtype::Type{T}){T <: AbstractMesh}(c::GeometryPrimitive, args...)
attribs = attributes(T)
newattribs = Dict{Symbol, Any}()
for (fieldname, typ) in attribs
Expand All @@ -22,9 +22,9 @@ If there are attributes missing, just hope it will get managed by the mesh const
end


@compat function (meshtype::Type{T}){T <: HMesh,HT}(
function (meshtype::Type{T}){T <: HMesh,HT}(
c::Union{HyperCube{3,T}, HyperRectangle{3,HT}}

) xdir = Vec{3, HT}(widths(c)[1],0f0,0f0)
ydir = Vec{3, HT}(0f0,widths(c)[2],0f0)
zdir = Vec{3, HT}(0f0,0f0,widths(c)[3])
Expand Down
8 changes: 4 additions & 4 deletions src/simplices.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
# We need this constructor to route around the FixedSizeArray `call` and
# so Simplex(Pt, Pt...) etc works. Hopefully these ambiguities will be fixed in
# forthcoming Julia versions.
@compat (::Type{S}){S <: Simplex}(s::S) = s
@compat function (::Type{T}){T<:Simplex,F<:FixedVector}(f::F...)
(::Type{S}){S <: Simplex}(s::S) = s
function (::Type{T}){T<:Simplex,F<:FixedVector}(f::F...)
Simplex{length(f),F}(f)
end
@compat (::Type{S}){S <: Simplex}(fs::FlexibleSimplex) = convert(S, fs)
(::Type{S}){S <: Simplex}(fs::FlexibleSimplex) = convert(S, fs)

# FSA doesn't handle symbols for length 1 well.
@compat function (::Type{T}){T<:Simplex}(f::Symbol)
function (::Type{T}){T<:Simplex}(f::Symbol)
Simplex{1,Symbol}((f,))
end

Expand Down
2 changes: 1 addition & 1 deletion src/slice.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ 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 Base.slice{VT<:AbstractFloat,FT<:Integer,O}(mesh::AbstractMesh{Point{3,VT},Face{3,FT,O}}, height::Number)
function slice{VT<:AbstractFloat,FT<:Integer,O}(mesh::AbstractMesh{Point{3,VT},Face{3,FT,O}}, height::Number)

height_ct = length(height)
# intialize the LineSegment array
Expand Down
Loading