Skip to content

Commit

Permalink
Merge pull request #8 from yuyichao/0.6
Browse files Browse the repository at this point in the history
Fix depwarns on 0.6
  • Loading branch information
yuyichao authored Feb 16, 2017
2 parents 0b74596 + 95c57e3 commit 9df7346
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 19 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ os:
- linux
- osx
julia:
- release
- 0.4
- 0.5
- nightly
notifications:
email: false
Expand Down
3 changes: 2 additions & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
julia 0.4-
julia 0.4
Colors
Compat 0.17.0
21 changes: 13 additions & 8 deletions src/Graphics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@ VERSION >= v"0.4.0-dev+6521" && __precompile__()

module Graphics

import Base: +, -, *, /, &, fill, norm, scale
import Base: +, -, *, /, &, fill, norm
using Colors
using Compat

if isdefined(Base, :scale)
import Base: scale
end

export
# Part 1. 2D Geometry
Expand Down Expand Up @@ -58,7 +63,7 @@ immutable Vec2
y::Float64
end

typealias Point Vec2
const Point = Vec2

(+)(a::Vec2, b::Vec2) = Vec2(a.x + b.x, a.y + b.y)
(-)(a::Vec2, b::Vec2) = Vec2(a.x - b.x, a.y - b.y)
Expand Down Expand Up @@ -86,8 +91,8 @@ end

BoundingBox() = BoundingBox(NaN, NaN, NaN, NaN)

function BoundingBox(points::Point...)
xmin, xmax, ymin, ymax = NaN, NaN, NaN, NaN
function BoundingBox(p0::Point, points::Point...)
xmin, xmax, ymin, ymax = p0.x, p0.x, p0.y, p0.y
for p in points
xmin = min(xmin, p.x)
xmax = max(xmax, p.x)
Expand All @@ -97,8 +102,8 @@ function BoundingBox(points::Point...)
return BoundingBox(xmin, xmax, ymin, ymax)
end

function BoundingBox(bboxes::BoundingBox...)
xmin, xmax, ymin, ymax = NaN, NaN, NaN, NaN
function BoundingBox(bb0::BoundingBox, bboxes::BoundingBox...)
xmin, xmax, ymin, ymax = bb0.xmin, bb0.xmax, bb0.ymin, bb0.ymax
for bb in bboxes
xmin = min(xmin, bb.xmin)
xmax = max(xmax, bb.xmax)
Expand Down Expand Up @@ -188,7 +193,7 @@ macro mustimplement(sig)
end

# a graphics output device; can create GraphicsContexts
abstract GraphicsDevice
@compat abstract type GraphicsDevice end

@mustimplement width(gd::GraphicsDevice)
@mustimplement height(gd::GraphicsDevice)
Expand All @@ -199,7 +204,7 @@ ymin(g::GraphicsDevice) = 0
ymax(g::GraphicsDevice) = height(g)

# an object that can actually be drawn to
abstract GraphicsContext
@compat abstract type GraphicsContext end

@mustimplement width(gc::GraphicsContext)
@mustimplement height(gc::GraphicsContext)
Expand Down
18 changes: 9 additions & 9 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ using Base.Test


## rotation: rotate()
@test_approx_eq rotate(Vec2(1, 2), π, Vec2(1, 1)).x 1
@test_approx_eq rotate(Vec2(1, 2), π, Vec2(1, 1)).y 0
@test_approx_eq rotate(Vec2(1, 2), 2π).x 1
@test_approx_eq rotate(Vec2(1, 2), 2π).y 2
@test rotate(Vec2(1, 2), π, Vec2(1, 1)).x 1
@test rotate(Vec2(1, 2), π, Vec2(1, 1)).y 0
@test rotate(Vec2(1, 2), 2π).x 1
@test rotate(Vec2(1, 2), 2π).y 2

## Euclidean norm/magnitude: norm()
@test norm(Vec2(1, 2)) == sqrt(5)
Expand All @@ -36,7 +36,7 @@ BBT = BoundingBox(BBT_point_1, BBT_point_2, BBT_point_3)
@test height(BBT) == 4
@test width(BBT) == 3
@test diagonal(BBT) == 5
@test_approx_eq aspect_ratio(BBT) 1.333333333333
@test aspect_ratio(BBT) 1.333333333333
@test xmin(BBT) == 1
@test xmax(BBT) == 4
@test center(BBT) == Vec2(2.5, 3)
Expand Down Expand Up @@ -64,10 +64,10 @@ BBT_2 = BoundingBox(6, 7, 8, 9)

#### rotate()
BBT_3 = rotate(BBT_1, π, Point(0, 1))
@test_approx_eq BBT_3.xmin -3
@test_approx_eq BBT_3.ymin -3
@test_approx_eq BBT_3.xmax -2
@test_approx_eq BBT_3.ymax -2
@test BBT_3.xmin -3
@test BBT_3.ymin -3
@test BBT_3.xmax -2
@test BBT_3.ymax -2

#### with_aspect_ratio()
@test with_aspect_ratio(BBT_1, 2) == BoundingBox(2.25, 2.75, 4, 5)
Expand Down

0 comments on commit 9df7346

Please sign in to comment.