Skip to content

remove generated Rect method #165

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 5 additions & 11 deletions src/primitives/rectangles.jl
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,11 @@ Rect constructor for individually specified intervals.
e.g. Rect(0,0,1,2) has origin == Vec(0,0) and
width == Vec(1,2)
"""
@generated function Rect(vals::Number...)
# Generated so we get goodish codegen on each signature
n = length(vals)
@assert iseven(n)
mid = div(n, 2)
v1 = Expr(:call, :Vec)
v2 = Expr(:call, :Vec)
# TODO this can be inbounds
append!(v1.args, [:(vals[$i]) for i in 1:mid])
append!(v2.args, [:(vals[$i]) for i in (mid + 1):length(vals)])
return Expr(:call, :Rect, v1, v2)
function Rect(vals::Vararg{Number, N}) where {N}
M, r = fldmod(N, 2)
(r == 0) || throw(ArgumentError("number of arguments must be even"))
origin, widths = ntuple(i -> vals[i], M), ntuple(i -> vals[i+M], M)
return Rect(Vec(origin), Vec(widths))
end

Rect3(a::Vararg{Number,6}) = Rect3(Vec{3}(a[1], a[2], a[3]), Vec{3}(a[4], a[5], a[6]))
Expand Down
5 changes: 5 additions & 0 deletions test/geometrytypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -312,4 +312,9 @@ end
rect2 = Rect(0.0, 0.0, 2.0, 3.0)
@test finishes(rect1, rect2)

rect1 = @inferred Rect(1, 2, 3, 4, 5, 6, 7, 8)
rect2 = Rect(Vec(1, 2, 3, 4), Vec(5, 6, 7, 8))
@test rect1 == rect2

@test_throws ArgumentError Rect(1, 2, 3)
end
Loading