Skip to content

Commit

Permalink
Working n-dimensional setdiff
Browse files Browse the repository at this point in the history
  • Loading branch information
dpsanders committed May 29, 2016
1 parent bd9ae2f commit e0649ab
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 7 deletions.
9 changes: 2 additions & 7 deletions src/multidim/setdiff.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,14 @@ function setdiff{N,T}(A::IntervalBox{N,T}, B::IntervalBox{N,T})
first = [ i[1] for i in X ]
labels = [i[2] for i in first]

any(labels .== -1) && return A # no overlap
any(labels .== -1) && return [A] # no overlap

@assert all(labels .== 1)
# @assert all(labels .== 1)

excluded = [i[1] for i in first]

result_list = IntervalBox{N,T}[]

@show first
@show labels
@show excluded


for dimension in N:-1:1
for which in X[dimension][2:end]
excluded[dimension] = which[1]
Expand Down
48 changes: 48 additions & 0 deletions test/multidim_tests/multidim.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,54 @@ facts("@intervalbox tests") do

@intervalbox g(x, y) = x - y
@fact isa(g(X), IntervalBox) --> true
end

facts("setdiff for IntervalBox") do
X = IntervalBox(2..4, 3..5)
Y = IntervalBox(3..5, 4..6)
@fact setdiff(X, Y) --> [ IntervalBox(3..4, 3..4),
IntervalBox(2..3, 3..5) ]


X = IntervalBox(2..5, 3..6)
Y = IntervalBox(-10..10, 4..5)
@fact setdiff(X, Y) --> [ IntervalBox(2..5, 3..4),
IntervalBox(2..5, 5..6) ]


X = IntervalBox(2..5, 3..6)
Y = IntervalBox(4..6, 4..5)
@fact setdiff(X, Y) --> [ IntervalBox(4..5, 3..4),
IntervalBox(4..5, 5..6),
IntervalBox(2..4, 3..6) ]


X = IntervalBox(2..5, 3..6)
Y = IntervalBox(3..4, 4..5)
@fact setdiff(X, Y) --> [ IntervalBox(3..4, 3..4),
IntervalBox(3..4, 5..6),
IntervalBox(2..3, 3..6),
IntervalBox(4..5, 3..6) ]


X = IntervalBox(2..5, 3..6)
Y = IntervalBox(2..4, 10..20)
@fact setdiff(X, Y) --> typeof(X)[X]


X = IntervalBox(2..5, 3..6)
Y = IntervalBox(-10..10, -10..10)
@fact setdiff(X, Y) --> typeof(X)[]


X = IntervalBox(1..4, 3..6, 7..10)
Y = IntervalBox(2..3, 4..5, 8..9)
@fact setdiff(X, Y) --> [ IntervalBox(2..3, 4..5, 7..8),
IntervalBox(2..3, 4..5, 9..10),
IntervalBox(2..3, 3..4, 7..10),
IntervalBox(2..3, 5..6, 7..10),
IntervalBox(1..2, 3..6, 7..10),
IntervalBox(3..4, 3..6, 7..10) ]


end

0 comments on commit e0649ab

Please sign in to comment.