1# Mode - Complete
2set calcul "c"
3# Join type - Intersection
4set type "i"
5
6proc compare_prop_values {prop m_res m_ref} {
7  if { ($m_ref != 0 && abs (($m_ref - $m_res) / double($m_ref)) > 1.e-2) || ($m_res == 0 && $m_ref != 0) } {
8    puts "Error: The $prop of result shape is $m_res, expected $m_ref"
9    return 0
10  } else {
11    puts "OK: The $prop of result shape is as expected"
12    return 1
13  }
14}
15
16proc compare_nbs {entity nb_res nb_ref} {
17  if {$nb_res != $nb_ref} {
18    puts "Error: number of $entity entities in the result shape is $nb_res, expected $nb_ref"
19    return 0
20  } else {
21    puts "OK: number of $entity entities in the result shape is as expected"
22    return 1
23  }
24}
25
26proc perform_offset_multi {theResult theShape theValue theFaceIds theFaceValues} {
27  upvar $theShape TheShape
28
29  global ${theResult}
30  global ${theResult}_unif
31
32  tcopy TheShape sx
33  offsetparameter 1.e-7 c i r
34  offsetload sx ${theValue}
35
36  set nbFaces [llength $theFaceIds]
37  if {$nbFaces > 0} {
38    explode sx f
39  }
40
41  for {set i 0} {$i < $nbFaces} {incr i} {
42    set face_id [lindex $theFaceIds $i]
43    set face_offset [lindex $theFaceValues $i]
44    offsetonface sx_${face_id} ${face_offset}
45  }
46
47  offsetperform ${theResult}
48
49  if {![catch { checkshape ${theResult} } ] } {
50    unifysamedom ${theResult}_unif ${theResult}
51    return 1
52  }
53  return 0
54}
55
56proc perform_offset_multi_with_ref {theResult theShape theValue theFaceIds theFaceValues theRefValues theUnified} {
57
58  upvar $theShape TheShape
59
60  global ${theResult}
61  global ${theResult}_unif
62
63  set operation_done [perform_offset_multi ${theResult} TheShape ${theValue} ${theFaceIds} ${theFaceValues}]
64
65  if {${operation_done} == 0} {
66    puts "Error: operation with offset value ${theValue} has failed"
67    return 0
68  }
69
70  set check_res {}
71
72  if { $theUnified == 1} {
73    set nbshapes_value [nbshapes ${theResult}_unif]
74  } else {
75    set nbshapes_value [nbshapes ${theResult}]
76  }
77
78  if { [llength $theRefValues] == 4} {
79    set area_value [lindex [sprops ${theResult}] 2]
80    set volume_value [lindex [vprops ${theResult}] 2]
81    set nbwires_value [lindex $nbshapes_value 13]
82    set nbfaces_value [lindex $nbshapes_value 16]
83
84    lappend checks_res [compare_prop_values "area" ${area_value} [lindex ${theRefValues} 0]]
85    lappend checks_res [compare_prop_values "volume" ${volume_value} [lindex ${theRefValues} 1]]
86
87    lappend checks_res [compare_nbs "wire" $nbwires_value [lindex ${theRefValues} 2]]
88    lappend checks_res [compare_nbs "face" $nbfaces_value [lindex ${theRefValues} 3]]
89  }
90
91  set nbshells_value [lindex $nbshapes_value 19]
92  set nbsolids_value [lindex $nbshapes_value 22]
93  lappend checks_res [compare_nbs "shell" $nbshells_value 1]
94  lappend checks_res [compare_nbs "solid" $nbsolids_value 1]
95
96  set OK 1
97  foreach x $checks_res {
98    if {$x == 0} {
99      set OK 0
100      break
101    }
102  }
103
104  set status "OK"
105  if {$OK == 0} {
106    puts "Error: operation with offset value ${theValue} produced incorrect result"
107    set status "KO"
108  }
109
110  puts "Offset value ${theValue} - $status: area - ${area_value}; volume - ${volume_value}; wires - ${nbwires_value}; faces - ${nbfaces_value} (${area_value} ${volume_value} ${nbwires_value} ${nbfaces_value})"
111
112  checkmaxtol ${theResult} -ref 1.e-6
113}
114