def add (lower,data = nil, inverted = false)
begin
lower.each do |lowCell|
if (!lowCell.is_a?(Cell) || !member?(lowCell))
raise "object #{lowCell} is not a cell"
end
end
if (lower != [])
ld = lower[0].dim
exit if ld >= @dim
lower.each do |lowCell|
if (lowCell.dim != ld)
raise "boundary cells have different dimension"
end
end
end
cellDim = (lower.empty? ? 0 : lower[0].dim+1 )
cell = @cellCreate.call(self, cellDim, data)
@lower[cell] = lower
@upper[cell] = Array.new
@cells[cellDim][cell] = true
@inverted[cell] = inverted
lower.each do |lowCell|
@lower[lowCell].each do |lowestCell|
matches = @upper[lowestCell] & lower
if (matches.length > 2)
raise "diamond property violation"
end
if (matches.length == 2)
@switchH[[lowestCell,matches[1],cell]] = matches[0]
@switchH[[lowestCell,matches[0],cell]] = matches[1]
end
end
@upper[lowCell].push(cell)
end
if (cellDim == 1)
if lower.length > 2
raise "diamond property violation"
end
if (lower.length == 2)
@switchH[[nil,lower[0],cell]] = lower[1]
@switchH[[nil,lower[1],cell]] = lower[0]
else
@switchH[[nil,lower[0],cell]] = lower[0]
end
end
if (cell.dim == @dim)
lower.each do |lowCell|
upper = @upper[lowCell]
if upper.length > 2
raise "diamond property violation"
end
if (upper.length == 2)
@switchH[[lowCell,upper[0],nil]] = upper[1]
@switchH[[lowCell,upper[1],nil]] = upper[0]
end
end
end
return cell
rescue
raise $!
end
end