puts "======================================================="
puts "0031850: Modeling Algorithms - boolean cut and common generate unexpected result"
puts "======================================================="
puts ""

restore [locate_data_file bug31850.brep] s
explode s

bfuzzyvalue 1.e-6
bnondestructive 1
brunparallel 1
setfillhistory 0

bclearobjects
bcleartools
baddobjects s_1
baddtools s_2
bfillds

bbop r0 0
bbop r1 1
bbop r2 2
bbop r3 3
bbop r4 4
bbuild rgf

boptions -default

foreach r {r0 r1 r2 r3 r4 rgf} {
  checkshape $r
  if {![regexp "OK" [bopcheck $r]]} {
    puts "Error: the $r is a self-interfering shape"
  }
}

checknbshapes r0 -wire 28 -face 28 -shell 1 -solid 1 -t
checkprops r0 -s 1107.94 -v 472.151

checknbshapes r1 -wire 50 -face 45 -shell 1 -solid 1 -t
checkprops r1 -s 14959.7 -v 37939.8

checknbshapes r2 -wire 33 -face 28 -shell 1 -solid 1 -t
checkprops r2 -s 5244.61 -v 2516.56

checknbshapes r3 -wire 45 -face 45 -shell 1 -solid 1 -t
checkprops r3 -s 10823 -v 34951.1

checkprops r4 -l 203.491
checksection r4 -r 10

checknbshapes rgf -wire 78 -face 73 -shell 3 -solid 3 -t
checkprops rgf -s 17175.6 -v 37939.8

checkview -display r0 -2d -path ${imagedir}/${test_image}.png
