Skip to content

Commit

Permalink
Removed a convert method for Cells that was causing cells to be copie…
Browse files Browse the repository at this point in the history
…d when referenced. Added a test for this condition.
  • Loading branch information
ajkeller34 committed Sep 28, 2016
1 parent 11471c1 commit da55aaf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
20 changes: 11 additions & 9 deletions src/Cells.jl
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ type CellArray{S,T} <: CellRef{S,T}
mag::Float64
rot::Float64
end
convert{S,T}(::Type{CellArray{S,T}}, x::CellArray) =
CellArray(T(x.cell), convert(Point{S}, x.origin),
convert(Point{S}, x.deltacol),
convert(Point{S}, x.deltarow),
x.col, x.row, x.xrefl, x.mag, x.rot)
convert{S}(::Type{CellArray{S}}, x::CellArray) =
CellArray(x.cell, convert(Point{S}, x.origin),
convert(Point{S}, x.deltacol),
convert(Point{S}, x.deltarow),
x.col, x.row, x.xrefl, x.mag, x.rot)

"""
```
Expand Down Expand Up @@ -154,10 +154,12 @@ type Cell{T<:Coordinate}
c
end
end
convert{T}(::Type{Cell{T}}, x::Cell) =
Cell{T}(x.name, convert(Vector{Polygon{T}}, x.elements),
convert(Vector{CellRef}, x.refs),
x.create)
# Do NOT define a convert method like this or otherwise cells will
# be copied when referenced by CellRefs!
# convert{T}(::Type{Cell{T}}, x::Cell) =
# Cell{T}(x.name, convert(Vector{Polygon{T}}, x.elements),
# convert(Vector{CellRef}, x.refs),
# x.create)

"""
```
Expand Down
7 changes: 5 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ end
@test_throws Unitful.DimensionError render!(c3, Rectangle(5m,10m))
render!(c3, r)
c2ref = CellReference(c2, Point(-10.0,0.0); mag=1.0, rot=180°)
@test c2ref.cell === c2
c3ref = CellReference(c3, Point(10.0,0.0); mag=2.0, rot=90°)
push!(c.refs, c2ref)
push!(c2.refs, c3ref)
Expand All @@ -308,8 +309,10 @@ end
c = Cell("main")
c2 = Cell("rect")
render!(c2, Rectangle(5,5))
push!(c.refs, CellArray(c2, Point(0,0); dc=Point(10,0), dr=Point(0,10),
ncols=10, nrows=10))
arr = CellArray(c2, Point(0,0); dc=Point(10,0), dr=Point(0,10),
ncols=10, nrows=10)
@test arr.cell === c2
push!(c.refs, arr)

# Test bounds with cell arrays
@test bounds(c) == Rectangle(95,95)
Expand Down

0 comments on commit da55aaf

Please sign in to comment.