box b 10 10 10

foreach bf [explode b f] {
  # replace face with the nurbs one
  nurbsconvert nf $bf
  eval mkvolume s nf [explode b f]

  savehistory mv_hist
  modified m mv_hist nf

  mksurface surf m
  if {![regexp "BSplineSurface" [dump surf]]} {
    puts "Error: Boolean Operation took the second face"
  }

  # make the shape periodic in all directions
  makeperiodic res s -x 10 -y 10 -z 10

  savehistory h
  modified mf h m

  mksurface s_mf mf

  # get twins for the face
  periodictwins tf mf

  checknbshapes tf -face 1 -m "Periodic twins" -t

  mksurface s_tf tf

  if {![regexp {\*\n([^ \n]*)} [dump s_mf] full mf_type]} {
    puts "Error: Unable to get the type"
  }
  if {![regexp {\*\n([^ \n]*)} [dump s_tf] full tf_type]} {
    puts "Error: Unable to get the type"
  }

  if {$mf_type != $tf_type} {
    puts "Error: Twins have different geometries"
  }

  # get twins for edges of the face
  foreach e [explode mf e] {
    periodictwins twins $e
    checknbshapes twins -edge 2 -m "Periodic twins" -t
    mkcurve c_$e $e
    if {![regexp {Basis curve :\n([^ \n]*)} [dump c_$e] full e_type]} {
      puts "Error: Unable to get the type"
    }

    foreach t [explode twins e] {
      mkcurve c_$t $t
      if {![regexp {Basis curve :\n([^ \n]*)} [dump c_$t] full t_type]} {
        puts "Error: Unable to get the type"
      }
      if {$e_type != $t_type} {
        puts "Error: Twins have different geometries"
      }
    }
  }
}

