diff --git a/src/components.jl b/src/components.jl index 71e9f0b9..7548de86 100644 --- a/src/components.jl +++ b/src/components.jl @@ -1,11 +1,34 @@ +export + P2, + P3, + BezierCurve, + curve_points, + directed_curve + +typealias P2 FixedSizeArrays.Vec{2,Float64} +typealias P3 FixedSizeArrays.Vec{3,Float64} + + immutable Shape vertices::AVec end +Shape(x, y) = Shape(collect(zip(x, y))) + get_xs(shape::Shape) = Float64[v[1] for v in shape.vertices] get_ys(shape::Shape) = Float64[v[2] for v in shape.vertices] +function scale(shape::Shape, x, y=x) + sx, sy = shape_coords(shape) + Shape(sx .* x, sy .* y) +end + +function translate(shape::Shape, x, y=x) + sx, sy = shape_coords(shape) + Shape(sx .+ x, sy .+ y) +end + function shape_coords(shape::Shape) unzip(shape.vertices) end @@ -288,16 +311,6 @@ end # @require FixedSizeArrays begin - export - P2, - P3, - BezierCurve, - curve_points, - directed_curve - - typealias P2 FixedSizeArrays.Vec{2,Float64} - typealias P3 FixedSizeArrays.Vec{3,Float64} - type BezierCurve{T <: FixedSizeArrays.Vec} control_points::Vector{T} end diff --git a/src/recipes.jl b/src/recipes.jl index df860b05..3e88113e 100644 --- a/src/recipes.jl +++ b/src/recipes.jl @@ -28,50 +28,50 @@ function _apply_recipe(d::KW, args...; issubplot=false, kw...) args end -# # ------------------------------------------------- +# ------------------------------------------------- -# function rotate(x::Real, y::Real, θ::Real; center = (0,0)) -# cx = x - center[1] -# cy = y - center[2] -# xrot = cx * cos(θ) - cy * sin(θ) -# yrot = cy * cos(θ) + cx * sin(θ) -# xrot + center[1], yrot + center[2] -# end +function rotate(x::Real, y::Real, θ::Real; center = (0,0)) + cx = x - center[1] + cy = y - center[2] + xrot = cx * cos(θ) - cy * sin(θ) + yrot = cy * cos(θ) + cx * sin(θ) + xrot + center[1], yrot + center[2] +end -# # ------------------------------------------------- +# ------------------------------------------------- -# type EllipseRecipe <: PlotRecipe -# w::Float64 -# h::Float64 -# x::Float64 -# y::Float64 -# θ::Float64 -# end -# EllipseRecipe(w,h,x,y) = EllipseRecipe(w,h,x,y,0) +type EllipseRecipe <: PlotRecipe + w::Float64 + h::Float64 + x::Float64 + y::Float64 + θ::Float64 +end +EllipseRecipe(w,h,x,y) = EllipseRecipe(w,h,x,y,0) -# # return x,y coords of a rotated ellipse, centered at the origin -# function rotatedEllipse(w, h, x, y, θ, rotθ) -# # # coord before rotation -# xpre = w * cos(θ) -# ypre = h * sin(θ) +# return x,y coords of a rotated ellipse, centered at the origin +function rotatedEllipse(w, h, x, y, θ, rotθ) + # # coord before rotation + xpre = w * cos(θ) + ypre = h * sin(θ) -# # rotate and translate -# r = rotate(xpre, ypre, rotθ) -# x + r[1], y + r[2] -# end + # rotate and translate + r = rotate(xpre, ypre, rotθ) + x + r[1], y + r[2] +end -# function getRecipeXY(ep::EllipseRecipe) -# x, y = unzip([rotatedEllipse(ep.w, ep.h, ep.x, ep.y, u, ep.θ) for u in linspace(0,2π,100)]) -# top = rotate(0, ep.h, ep.θ) -# right = rotate(ep.w, 0, ep.θ) -# linex = Float64[top[1], 0, right[1]] + ep.x -# liney = Float64[top[2], 0, right[2]] + ep.y -# Any[x, linex], Any[y, liney] -# end +function getRecipeXY(ep::EllipseRecipe) + x, y = unzip([rotatedEllipse(ep.w, ep.h, ep.x, ep.y, u, ep.θ) for u in linspace(0,2π,100)]) + top = rotate(0, ep.h, ep.θ) + right = rotate(ep.w, 0, ep.θ) + linex = Float64[top[1], 0, right[1]] + ep.x + liney = Float64[top[2], 0, right[2]] + ep.y + Any[x, linex], Any[y, liney] +end -# function getRecipeArgs(ep::EllipseRecipe) -# [(:line, (3, [:dot :solid], [:red :blue], :path))] -# end +function getRecipeArgs(ep::EllipseRecipe) + [(:line, (3, [:dot :solid], [:red :blue], :path))] +end # # ------------------------------------------------- diff --git a/src/utils.jl b/src/utils.jl index 69a259b5..d60ef237 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -265,9 +265,16 @@ end ``` """ function with(f::Function, args...; kw...) + newdefs = KW(kw) + + if :canvas in args + newdefs[:xticks] = nothing + newdefs[:yticks] = nothing + newdefs[:grid] = false + newdefs[:legend] = false + end # dict to store old and new keyword args for anything that changes - newdefs = KW(kw) olddefs = KW() for k in keys(newdefs) olddefs[k] = default(k)