# test for #22778: compare number of triangles in triangulation
# produced on surface converted to nurbs, against number of triangles on
# original analytic (spherical) surface

puts "TODO #22778 All: too many triangles"

# original face on spherical surface
restore [locate_data_file bug22778_square.brep] s
checkshape s
incmesh s 0.001
set trinfo_s [trinfo s]
regexp {([0-9]+) triangles} $trinfo_s str nbtri_s
regexp {deflection ([0-9.+e-]+)} $trinfo_s str defl_s

# face converted to NURBS
nurbsconvert r s
checkshape r
incmesh r 0.001
set trinfo_r [trinfo r]
regexp {([0-9]+) triangles} $trinfo_r str nbtri_r
regexp {deflection ([0-9.+e-]+)} $trinfo_r str defl_r

# check deflections
if { $defl_s > 0.001 } {
    puts "Error: too big deflection on original face ($defl_s > 0.001)"
}
if { $defl_r > 0.001 } {
    puts "Error: too big deflection on NURBS face ($defl_r > 0.001)"
}

# compare number of triangles, allow twice more
if { $nbtri_r > [expr 2. * $nbtri_s] } {
    puts "Error: too many triangles ($nbtri_r, while ~ $nbtri_s would be sufficient)"
}

# extra check: deflection on rough mesh on NURBS
tclean r
incmesh r 0.1
checktrinfo r -max_defl 0.1
