Skip to content

Commit 0e16f25

Browse files
committed
add some convenience functions for rects
1 parent 4221f84 commit 0e16f25

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/rectangles.jl

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,13 +268,23 @@ function Base.:(*)(m::Mat{4,4,T}, h::Rect{3,T}) where T
268268
Rect{3,T}(_vmin, _vmax - _vmin)
269269
end
270270

271-
function Base.:(-)(h::Rect{N, T}, move::Vec{N}) where {N,T}
271+
Base.:(-)(h::Rect{N, T}, move::Number) where {N,T} = h - Vec{N, N}(move)
272+
Base.:(+)(h::Rect{N, T}, move::Number) where {N,T} = h + Vec{N, N}(move)
273+
274+
275+
function Base.:(-)(h::Rect{N, T}, move::StaticVector{N}) where {N,T}
272276
Rect{N, T}(minimum(h) .- move, widths(h))
273277
end
274-
function Base.:(+)(h::Rect{N, T}, move::Vec{N}) where {N,T}
278+
279+
function Base.:(+)(h::Rect{N, T}, move::StaticVector{N}) where {N,T}
275280
Rect{N, T}(minimum(h) .+ move, widths(h))
276281
end
277282

283+
284+
function Base.:(*)(rect::Rect, scaling::Union{Number, StaticVector})
285+
return Rect(minimum(rect) .* scaling, widths(rect) .* scaling)
286+
end
287+
278288
# Enables rectangular indexing into a matrix
279289
function Base.to_indices(A::AbstractMatrix{T}, I::Tuple{Rect2D{IT}}) where {T, IT<:Integer}
280290
rect = I[1]

0 commit comments

Comments
 (0)