Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
178 additions
and
178 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
|
||
################ | ||
# Bounding boxes | ||
################# | ||
|
||
# A bounding box is an Interval or ProductDomain of intervals that encompasses the domain. | ||
|
||
# If the boundingbox is not a product of intervals, something has gone wrong. | ||
|
||
boundingbox(a::SVector{1}, b::SVector{1}) = a[1]..b[1] | ||
|
||
boundingbox(a::Number, b::Number) = a..b | ||
|
||
boundingbox(a, b) = ProductDomain(map((ai,bi)->ClosedInterval(ai,bi), a, b)...) | ||
|
||
boundingbox(d::AbstractInterval) = d | ||
|
||
boundingbox(::UnitHyperBall{N,T}) where {N,T} = boundingbox(-ones(SVector{N,T}), ones(SVector{N,T})) | ||
|
||
boundingbox(d::ProductDomain) = cartesianproduct(map(boundingbox, elements(d))...) | ||
|
||
boundingbox(d::DerivedDomain) = boundingbox(source(d)) | ||
|
||
boundingbox(d::DifferenceDomain) = boundingbox(d.d1) | ||
|
||
function boundingbox(d::UnionDomain) | ||
left = minimum(hcat(map(infimum,map(boundingbox,elements(d)))...);dims=2) | ||
right = maximum(hcat(map(supremum,map(boundingbox,elements(d)))...);dims=2) | ||
boundingbox(left,right) | ||
end | ||
|
||
function boundingbox(d::IntersectionDomain) | ||
left = maximum(hcat(map(infimum,map(boundingbox,elements(d)))...);dims=2) | ||
right = minimum(hcat(map(supremum,map(boundingbox,elements(d)))...);dims=2) | ||
boundingbox(left,right) | ||
end | ||
|
||
DomainSets.superdomain(d::DomainSets.MappedDomain) = DomainSets.source(d) | ||
|
||
# Now here is a problem: how do we compute a bounding box, without extra knowledge | ||
# of the map? We can only do this for some maps. | ||
boundingbox(d::DomainSets.MappedDomain) = mapped_boundingbox(boundingbox(source(d)), forward_map(d)) | ||
|
||
function mapped_boundingbox(box::Interval, fmap) | ||
l,r = (infimum(box),supremum(box)) | ||
ml = fmap*l | ||
mr = fmap*r | ||
boundingbox(min(ml,mr), max(ml,mr)) | ||
end | ||
|
||
# In general, we can at least map all the corners of the bounding box of the | ||
# underlying domain, and compute a bounding box for those points. This will be | ||
# correct for affine maps. | ||
function mapped_boundingbox(box::ProductDomain, fmap) | ||
crn = corners(infimum(box),supremum(box)) | ||
mapped_corners = [fmap*crn[:,i] for i in 1:size(crn,2)] | ||
left = [minimum([mapped_corners[i][j] for i in 1:length(mapped_corners)]) for j in 1:size(crn,1)] | ||
right = [maximum([mapped_corners[i][j] for i in 1:length(mapped_corners)]) for j in 1:size(crn,1)] | ||
boundingbox(left, right) | ||
end | ||
|
||
# Auxiliary functions to rotate a bounding box when mapping it. | ||
function corners(left::AbstractVector, right::AbstractVector) | ||
@assert length(left)==length(right) | ||
N=length(left) | ||
corners = zeros(N,2^N) | ||
# All possible permutations of the corners | ||
for i=1:2^length(left) | ||
for j=1:N | ||
corners[j,i] = ((i>>(j-1))%2==0) ? left[j] : right[j] | ||
end | ||
end | ||
corners | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# A collection of extensions to the DomainSets package. | ||
|
||
using DomainSets: inverse_map, forward_map | ||
|
||
########################### | ||
# Applying broadcast to in | ||
########################### | ||
|
||
# Intercept a broadcasted call to indomain. We assume that the user wants evaluation | ||
# in a set of points (which we call a grid), rather than in a single point. | ||
# TODO: the user may want to evaluate a single point in a sequence of domains... | ||
broadcast(::typeof(in), grid, d::Domain) = indomain_broadcast(grid, d) | ||
|
||
# # Default methods for evaluation on a grid: the default is to call eval on the domain with | ||
# # points as arguments. Domains that have faster grid evaluation routines may define their own version. | ||
indomain_broadcast(grid, d::Domain) = indomain_broadcast!(BitArray(undef, size(grid)), grid, d) | ||
# TODO: use BitArray here | ||
|
||
function indomain_broadcast!(result, grid::AbstractGrid, domain::Domain) | ||
for (i,x) in enumerate(grid) | ||
result[i] = DomainSets.in(x, domain) | ||
end | ||
result | ||
end | ||
|
||
function indomain_broadcast(grid::AbstractGrid, d::UnionDomain) | ||
z = indomain_broadcast(grid, element(d,1)) | ||
for i in 2:numelements(d) | ||
z = z .| indomain_broadcast(grid, element(d,i)) | ||
end | ||
z | ||
end | ||
|
||
function indomain_broadcast(grid::AbstractGrid, d::IntersectionDomain) | ||
z = indomain_broadcast(grid, element(d,1)) | ||
for i in 2:numelements(d) | ||
z = z .& indomain_broadcast(grid, element(d,i)) | ||
end | ||
z | ||
end | ||
|
||
function indomain_broadcast(grid::AbstractGrid, d::DifferenceDomain) | ||
z1 = indomain_broadcast(grid, d.d1) | ||
z2 = indomain_broadcast(grid, d.d2) | ||
z1 .& (.~z2) | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.