Skip to content

Commit

Permalink
after testing fixed bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
louisponet committed Nov 6, 2017
1 parent 6fda096 commit 138efe1
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 35 deletions.
34 changes: 34 additions & 0 deletions src/defaults.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,40 @@
"File with all the user defaults inside it"
const default_file = joinpath(@__DIR__,"../user_defaults/user_defaults.jl")

function init_defaults(filename::String)
raw_input =""
names_to_export = Symbol[]
open(filename,"r") do f
while !eof(f)
line = readline(f)
if line == "" || line[1] == '#'
continue
end
lhs = parse(line).args[1]
if typeof(lhs) == Symbol
push!(names_to_export,lhs)
end
raw_input *= line*"; "
end
end
for name in names_to_export
eval(:(export $name))
end
eval(parse(raw_input))
end

function load_defaults(filename::String=default_file)
raw_input =""
names_to_export = Symbol[]
open(filename,"r") do f
while !eof(f)
raw_input *= readline(f)*"; "
end
end
raw_input *= "nothing ;"
eval(parse(raw_input))
end

"Macro which allows you to define any default variable that will get loaded every time you use this package."
macro set_default(expr)
expr2file(default_file,expr)
Expand Down
33 changes: 0 additions & 33 deletions src/file_processing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -781,36 +781,3 @@ function expr2file(filename::String, expression::Expr)
end
end

function init_defaults(filename::String)
raw_input =""
names_to_export = Symbol[]
open(filename,"r") do f
while !eof(f)
line = readline(f)
if line == "" || line[1] == '#'
continue
end
lhs = parse(line).args[1]
if typeof(lhs) == Symbol
push!(names_to_export,lhs)
end
raw_input *= line*"; "
end
end
for name in names_to_export
eval(:(export $name))
end
eval(parse(raw_input))
end

function load_defaults(filename::String=default_file)
raw_input =""
names_to_export = Symbol[]
open(filename,"r") do f
while !eof(f)
raw_input *= readline(f)*"; "
end
end
raw_input *= "nothing ;"
eval(parse(raw_input))
end
19 changes: 17 additions & 2 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,29 @@ end
Point3D(::Type{T},x) where T<:AbstractFloat = Point3D(T(x),T(x),T(x))
Point3D(x::Array{<:AbstractFloat,1}) = Point3D(x[1],x[2],x[3])

import Base:+,-,*
import Base: +, -, *, /, convert, promote_rule, show, zero, norm
+(x::Point3D,y::Point3D) = Point3D(x.x+y.x,x.y+y.y,x.z+y.z)
+(x::Point3D,y::Number) = Point3D(x.x+y,x.y+y,x.z+y)
-(x::Point3D,y::Point3D) = Point3D(x.x-y.x,x.y-y.y,x.z-y.z)
-(x::Point3D,y::Number) = Point3D(x.x-y,x.y-y,x.z-y)
*(x::Point3D,y::Point3D) = Point3D(x.x*y.x,x.y*y.y,x.z*y.z)
*(x::Point3D,y::Number) = Point3D(x.x*y,x.y*y,x.z*y)

/(a::Point3D,b::Point3D) = Point3D(a.x/b.x,a.y/b.y,a.z/b.z)
/(a::Point3D,b::Number) = Point3D(a.x/b,a.y/b,a.z/b)
@inline norm(a::Point3D) = sqrt(a.x^2+a.y^2+a.z^2)
zero(::Type{Point3D{T}}) where T = Point3D(zero(T),zero(T),zero(T))
zero(::Type{Point3D}) = Point3D(zero(Float64),zero(Float64),zero(Float64))

convert(::Type{Point3D},x::Point3D) = x
convert(::Type{Array},x::Point3D) = [x.x,x.y,x.z]
convert(::Type{Point3D},x::T) where T<:AbstractFloat = Point3D{T}(x,x,x)
convert(::Type{Point3D{T}},x::Real) where T<:AbstractFloat = Point3D{T}(x,x,x)
convert(::Type{Point3D{T}},x::Point3D) where T<:AbstractFloat = Point3D{T}(x.x,x.y,x.z)
convert(::Type{Point3D{T}},x::Array{T,1}) where T<:AbstractFloat = Point3D{T}(x[1],x[2],x[3])
promote_rule(::Type{Point3D{S}},::Type{Point3D{T}}) where {S<:AbstractFloat,T<:AbstractFloat} = Point3D{promote_type(S,T)}
promote_rule(::Type{Point3D{S}},::Type{T}) where {S<:AbstractFloat,T<:Real} = Point3D{promote_type(S,T)}

show(io::IO,x::Point3D)=print(io,"x = $(x.x), y = $(x.y), z = $(x.z)")

abstract type Band end

Expand Down

0 comments on commit 138efe1

Please sign in to comment.