diff --git a/REQUIRE b/REQUIRE index 8e79a50..475b6ed 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1,2 +1,3 @@ PyPlot Elliptic +Compat \ No newline at end of file diff --git a/src/Geometry2D.jl b/src/Geometry2D.jl index 203d4d4..20473e9 100644 --- a/src/Geometry2D.jl +++ b/src/Geometry2D.jl @@ -1,5 +1,6 @@ module Geometry2D +using Compat using PyPlot import PyPlot: plot, fill, polar @@ -19,11 +20,11 @@ abstract G2dSimpleObject <: G2dObject # objects for which area,perimeter,isin, m abstract G2dCompoundObject <: G2dObject # automated promotion rules for arrays of numbers -promote_rule{T<:Integer,S<:FloatingPoint}(::Type{Array{T,1}}, ::Type{Array{S,1}} ) = Array{S,1} +promote_rule{T<:Integer,S<:AbstractFloat}(::Type{Array{T,1}}, ::Type{Array{S,1}} ) = Array{S,1} promote_rule{T<:Integer}(::Type{Array{Rational{T},1}}, ::Type{Array{T,1}}) = Array{Rational{T},1} promote_rule{T<:Integer,S<:Integer}(::Type{Array{Rational{T},1}}, ::Type{Array{S,1}}) = Array{Rational{promote_type(T,S)},1} promote_rule{T<:Integer,S<:Integer}(::Type{Array{Rational{T},1}}, ::Type{Array{Rational{S},1}}) = Array{Rational{promote_type(T,S)},1} -promote_rule{T<:Integer,S<:FloatingPoint}(::Type{Array{Rational{T},1}}, ::Type{Array{S,1}}) = Array{promote_type(T,S), 1} +promote_rule{T<:Integer,S<:AbstractFloat}(::Type{Array{Rational{T},1}}, ::Type{Array{S,1}}) = Array{promote_type(T,S), 1} # should probably put something in here for complex numbers too tolerance = eps() # global variable for tolerance of many operations in floating point diff --git a/src/circle.jl b/src/circle.jl index 3667fd4..a085153 100644 --- a/src/circle.jl +++ b/src/circle.jl @@ -132,7 +132,7 @@ closed(::Circle) = true # approximate as a regular polygon function approxpoly(c::Circle, n::Integer) dtheta = 2.0*pi/n - theta = dtheta*[0:n] + theta = dtheta*collect(0:n) x = c.center.x + c.radius * cos(theta) y = c.center.y + c.radius * sin(theta) return PointArray(x,y) diff --git a/src/intersection.jl b/src/intersection.jl index 306a873..2337c13 100644 --- a/src/intersection.jl +++ b/src/intersection.jl @@ -184,7 +184,7 @@ end intersection( r::Ray, s::Segment; tolerance=1.0e-12 ) = intersection( s, r; tolerance=tolerance ) # intersection of lines with segments or Rays -RayOrSegment = Union(Ray, Segment) +RayOrSegment = @compat Union{Ray, Segment} function intersection( s::RayOrSegment, l::Line; tolerance=1.0e-12 ) #OUTPUTS: # intersect = 0 means no intersection diff --git a/src/line.jl b/src/line.jl index 4a87a97..293fb9d 100644 --- a/src/line.jl +++ b/src/line.jl @@ -74,7 +74,7 @@ Segment{T<:Number}(startpoint::Point{T}, endpoint::Point{T}) = Segment{T}(promot Segment{T<:Number, S<:Number}(startpoint::Point{T}, endpoint::Point{S}) = Segment(promote(startpoint, endpoint)...) # could have done this with an abstract type above the three, but wanted to try out Unions -LINETYPE = Union(Line, Ray, Segment) +LINETYPE = @compat Union{Line, Ray, Segment} # lots of alternate representations we could build constructors for # ray constructed using two points (with one as start), or point and a slope (and + or -) @@ -94,23 +94,23 @@ copy(r::Ray) = Ray(r.startpoint, r.direction) copy(s::Segment) = Segment(s.startpoint, s.endpoint) -# promote_rule{T<:Integer,S<:FloatingPoint}(::Type{Line{T}}, ::Type{Line{S}} ) = Line{S} +# promote_rule{T<:Integer,S<:AbstractFloat}(::Type{Line{T}}, ::Type{Line{S}} ) = Line{S} # promote_rule{T<:Integer}(::Type{Line{Rational{T}}}, ::Type{Line{T}}) = Line{Rational{T}} # promote_rule{T<:Integer,S<:Integer}(::Type{Line{Rational{T}}}, ::Type{Line{S}}) = Line{Rational{promote_type(T,S)}} # promote_rule{T<:Integer,S<:Integer}(::Type{Line{Rational{T}}}, ::Type{Line{Rational{S}}}) = Line{Rational{promote_type(T,S)}} -# promote_rule{T<:Integer,S<:FloatingPoint}(::Type{Line{Rational{T}}}, ::Type{Line{S}}) = Line{promote_type(T,S)} +# promote_rule{T<:Integer,S<:AbstractFloat}(::Type{Line{Rational{T}}}, ::Type{Line{S}}) = Line{promote_type(T,S)} -# promote_rule{T<:Integer,S<:FloatingPoint}(::Type{Ray{T}}, ::Type{Ray{S}} ) = Ray{S} +# promote_rule{T<:Integer,S<:AbstractFloat}(::Type{Ray{T}}, ::Type{Ray{S}} ) = Ray{S} # promote_rule{T<:Integer}(::Type{Ray{Rational{T}}}, ::Type{Ray{T}}) = Ray{Rational{T}} # promote_rule{T<:Integer,S<:Integer}(::Type{Ray{Rational{T}}}, ::Type{Ray{S}}) = Ray{Rational{promote_type(T,S)}} # promote_rule{T<:Integer,S<:Integer}(::Type{Ray{Rational{T}}}, ::Type{Ray{Rational{S}}}) = Ray{Rational{promote_type(T,S)}} -# promote_rule{T<:Integer,S<:FloatingPoint}(::Type{Ray{Rational{T}}}, ::Type{Ray{S}}) = Ray{promote_type(T,S)} +# promote_rule{T<:Integer,S<:AbstractFloat}(::Type{Ray{Rational{T}}}, ::Type{Ray{S}}) = Ray{promote_type(T,S)} -# promote_rule{T<:Integer,S<:FloatingPoint}(::Type{Segment{T}}, ::Type{Segment{S}} ) = Segment{S} +# promote_rule{T<:Integer,S<:AbstractFloat}(::Type{Segment{T}}, ::Type{Segment{S}} ) = Segment{S} # promote_rule{T<:Integer}(::Type{Segment{Rational{T}}}, ::Type{Segment{T}}) = Segment{Rational{T}} # promote_rule{T<:Integer,S<:Integer}(::Type{Segment{Rational{T}}}, ::Type{Segment{S}}) = Segment{Rational{promote_type(T,S)}} # promote_rule{T<:Integer,S<:Integer}(::Type{Segment{Rational{T}}}, ::Type{Segment{Rational{S}}}) = Segment{Rational{promote_type(T,S)}} -# promote_rule{T<:Integer,S<:FloatingPoint}(::Type{Segment{Rational{T}}}, ::Type{Segment{S}}) = Segment{promote_type(T,S)} +# promote_rule{T<:Integer,S<:AbstractFloat}(::Type{Segment{Rational{T}}}, ::Type{Segment{S}}) = Segment{promote_type(T,S)} # conversion of one type to another: note though that these loose information convert{T<:Number}(::Type{Ray}, s::Segment{T}) = Ray(s.startpoint, s.endpoint-s.startpoint) @@ -277,16 +277,16 @@ function displayPath(line::Line; bounds=default_bounds) # choose the two points that are in the bounding rectangle P = [] if i1==1 && isin(p1, bounds)[1] - P = [P, p1] + P = vcat(P, p1) end if i2==1 && isin(p2, bounds)[1] - P = [P, p2] + P = vcat(P, p2) end if i3==1 && isin(p3, bounds)[1] - P = [P, p3] + P = vcat(P, p3) end if i4==1 && isin(p4, bounds)[1] - P = [P, p4] + P = vcat(P, p4) end return unique(P) # doesn't eliminate all possible redundant points because of roundoff errors end diff --git a/src/point.jl b/src/point.jl index 9d2cfa2..1dbdce4 100644 --- a/src/point.jl +++ b/src/point.jl @@ -24,16 +24,16 @@ origin{T<:Number}(::Point{T}) = Point(convert(T,0), convert(T,0)) typealias Vect Point # automated promotion rules for Points -promote_rule{T<:Integer,S<:FloatingPoint}(::Type{Point{T}}, ::Type{Point{S}} ) = Point{S} +promote_rule{T<:Integer,S<:AbstractFloat}(::Type{Point{T}}, ::Type{Point{S}} ) = Point{S} promote_rule{T<:Integer}(::Type{Point{Rational{T}}}, ::Type{Point{T}}) = Point{Rational{T}} promote_rule{T<:Integer,S<:Integer}(::Type{Point{Rational{T}}},::Type{Point{S}}) = Point{Rational{promote_type(T,S)}} promote_rule{T<:Integer,S<:Integer}(::Type{Point{Rational{T}}},::Type{Point{Rational{S}}}) = Point{Rational{promote_type(T,S)}} -promote_rule{T<:Integer,S<:FloatingPoint}(::Type{Point{Rational{T}}}, ::Type{Point{S}}) = Point{promote_type(T,S)} -promote_rule{T<:FloatingPoint,S<:FloatingPoint}(::Type{Point{T}}, ::Type{Point{S}}) = Point{promote_type(T,S)} +promote_rule{T<:Integer,S<:AbstractFloat}(::Type{Point{Rational{T}}}, ::Type{Point{S}}) = Point{promote_type(T,S)} +promote_rule{T<:AbstractFloat,S<:AbstractFloat}(::Type{Point{T}}, ::Type{Point{S}}) = Point{promote_type(T,S)} # should probably put something in here for complex numbers too # don't seem to need these? -# convert{T<:FloatingPoint}(::Type{Point{T}}, p::Point) = Point(convert(T,p.x), convert(T,p.y)) +# convert{T<:AbstractFloat}(::Type{Point{T}}, p::Point) = Point(convert(T,p.x), convert(T,p.y)) # convert{T<:Integer}(::Type{Point{Rational{T}}}, p::Point) = Point(convert(Rational{T},p.x), convert(Rational{T},p.y)) # convert{T<:Integer}(::Type{Point{T}}, p::Point) = Point(convert(T,p.x), convert(T,p.y)) @@ -58,13 +58,13 @@ inner(p1::Point, p2::Point) = p1.x * p2.x + p1.y * p2.y isequal(p1::Point, p2::Point) = ( p1.x==p2.x && p1.y==p2.y ) isless(p1::Point, p2::Point) = ( p1.x (p1::Point, p2::Point) = p2(p1::Point, p2::Point) = p2 (p1::Point, p2::Point) = p2(p1::Point, p2::Point) = p2=(p1::Point, p2::Point) = p1<=p2 .<=(p1::Point, p2::Point) = p2<=p1 cmp(p1::Point, p2::Point) = p1