1 # Copyright (C) 2020-2023 CEA/DEN, EDF R&D
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License, or (at your option) any later version.
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # Lesser General Public License for more details.
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 # See https://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 ### Test offset using approximation
21 ### bos #20476 EDF 22546 - sigsegv with offset
23 from salome.shaper import model
25 #=========================================================================
26 # Creation of a document and sketch
27 #=========================================================================
30 partSet = model.moduleDocument()
33 Sketch_1 = model.addSketch(partSet, model.defaultPlane("XOY"))
36 #=========================================================================
37 # Creation of a testing B-spline
38 #=========================================================================
40 ### Create SketchPoint
41 SketchPoint_1 = Sketch_1.addPoint(0, 0)
42 SketchPoint_1.setAuxiliary(True)
44 ### Create SketchPoint
45 SketchPoint_2 = Sketch_1.addPoint(0.03453184, 0.15311942)
46 SketchPoint_2.setAuxiliary(True)
48 ### Create SketchPoint
49 SketchPoint_3 = Sketch_1.addPoint(0.11839488, 0.28145762)
50 SketchPoint_3.setAuxiliary(True)
52 ### Create SketchPoint
53 SketchPoint_4 = Sketch_1.addPoint(0.20229646, 0.3653592)
54 SketchPoint_4.setAuxiliary(True)
56 ### Create SketchPoint
57 SketchPoint_5 = Sketch_1.addPoint(0.325663, 0.44425058)
58 SketchPoint_5.setAuxiliary(True)
60 ### Create SketchPoint
61 SketchPoint_6 = Sketch_1.addPoint(0.44409642, 0.5083426)
62 SketchPoint_6.setAuxiliary(True)
64 ### Create SketchPoint
65 SketchPoint_7 = Sketch_1.addPoint(0.5625298400000001, 0.5526636)
66 SketchPoint_7.setAuxiliary(True)
68 ### Create SketchPoint
69 SketchPoint_8 = Sketch_1.addPoint(0.70069574, 0.5969460600000001)
70 SketchPoint_8.setAuxiliary(True)
72 ### Create SketchPoint
73 SketchPoint_9 = Sketch_1.addPoint(0.8684989, 0.63132374)
74 SketchPoint_9.setAuxiliary(True)
76 ### Create SketchPoint
77 SketchPoint_10 = Sketch_1.addPoint(1.02146416, 0.6509020600000001)
78 SketchPoint_10.setAuxiliary(True)
80 ### Create SketchPoint
81 SketchPoint_11 = Sketch_1.addPoint(1.22873228, 0.65063228)
82 SketchPoint_11.setAuxiliary(True)
84 ### Create SketchPoint
85 SketchPoint_12 = Sketch_1.addPoint(1.41129626, 0.6454293800000001)
86 SketchPoint_12.setAuxiliary(True)
88 ### Create SketchPoint
89 SketchPoint_13 = Sketch_1.addPoint(1.58403254, 0.6205325399999999)
90 SketchPoint_13.setAuxiliary(True)
92 ### Create SketchPoint
93 SketchPoint_14 = Sketch_1.addPoint(1.7369978, 0.60550194)
94 SketchPoint_14.setAuxiliary(True)
96 ### Create SketchPoint
97 SketchPoint_15 = Sketch_1.addPoint(1.9244949, 0.5632621)
98 SketchPoint_15.setAuxiliary(True)
100 ### Create SketchPoint
101 SketchPoint_16 = Sketch_1.addPoint(2.10709742, 0.5160891400000001)
102 SketchPoint_16.setAuxiliary(True)
104 ### Create SketchPoint
105 SketchPoint_17 = Sketch_1.addPoint(2.27486204, 0.4763544)
106 SketchPoint_17.setAuxiliary(True)
108 ### Create SketchPoint
109 SketchPoint_18 = Sketch_1.addPoint(2.4179996, 0.43661966)
110 SketchPoint_18.setAuxiliary(True)
112 ### Create SketchPoint
113 SketchPoint_19 = Sketch_1.addPoint(2.55123238, 0.39692346)
114 SketchPoint_19.setAuxiliary(True)
116 ### Create SketchPoint
117 SketchPoint_20 = Sketch_1.addPoint(2.70913076, 0.3522556)
118 SketchPoint_20.setAuxiliary(True)
120 ### Create SketchPoint
121 SketchPoint_21 = Sketch_1.addPoint(2.89173328, 0.29768296)
122 SketchPoint_21.setAuxiliary(True)
124 ### Create SketchPoint
125 SketchPoint_22 = Sketch_1.addPoint(3.04469854, 0.2530151)
126 SketchPoint_22.setAuxiliary(True)
128 ### Create SketchPoint
129 SketchPoint_23 = Sketch_1.addPoint(3.19273068, 0.20341412)
130 SketchPoint_23.setAuxiliary(True)
132 ### Create SketchPoint
133 SketchPoint_24 = Sketch_1.addPoint(3.35556218, 0.1537746)
134 SketchPoint_24.setAuxiliary(True)
136 ### Create SketchPoint
137 SketchPoint_25 = Sketch_1.addPoint(3.50363286, 0.10914528)
138 SketchPoint_25.setAuxiliary(True)
140 ### Create SketchPoint
141 SketchPoint_26 = Sketch_1.addPoint(3.63686564, 0.06944908000000001)
142 SketchPoint_26.setAuxiliary(True)
144 ### Create SketchPoint
145 SketchPoint_27 = Sketch_1.addPoint(3.7404997, 0.03965766)
146 SketchPoint_27.setAuxiliary(True)
148 ### Create SketchPoint
149 SketchPoint_28 = Sketch_1.addPoint(3.838584, 0.004933120000000001)
150 SketchPoint_28.setAuxiliary(True)
152 ### Create SketchPoint
153 SketchPoint_29 = Sketch_1.addPoint(3.854, -0.009866240000000002)
154 SketchPoint_29.setAuxiliary(True)
156 ### Create SketchPoint
157 SketchPoint_30 = Sketch_1.addPoint(3.77009842, -0.004817500000000001)
158 SketchPoint_30.setAuxiliary(True)
160 ### Create SketchPoint
161 SketchPoint_31 = Sketch_1.addPoint(3.56040228, 0.01025164)
162 SketchPoint_31.setAuxiliary(True)
164 ### Create SketchPoint
165 SketchPoint_32 = Sketch_1.addPoint(3.43946376, 0.00300612)
166 SketchPoint_32.setAuxiliary(True)
168 ### Create SketchPoint
169 SketchPoint_33 = Sketch_1.addPoint(3.31609722, -0.02154386)
170 SketchPoint_33.setAuxiliary(True)
172 ### Create SketchPoint
173 SketchPoint_34 = Sketch_1.addPoint(3.18779756, -0.05349352)
174 SketchPoint_34.setAuxiliary(True)
176 ### Create SketchPoint
177 SketchPoint_35 = Sketch_1.addPoint(3.04963166, -0.09777598)
178 SketchPoint_35.setAuxiliary(True)
180 ### Create SketchPoint
181 SketchPoint_36 = Sketch_1.addPoint(2.89173328, -0.15192468)
182 SketchPoint_36.setAuxiliary(True)
184 ### Create SketchPoint
185 SketchPoint_37 = Sketch_1.addPoint(2.70913076, -0.22580586)
186 SketchPoint_37.setAuxiliary(True)
188 ### Create SketchPoint
189 SketchPoint_38 = Sketch_1.addPoint(2.54629926, -0.2947539200000001)
190 SketchPoint_38.setAuxiliary(True)
192 ### Create SketchPoint
193 SketchPoint_39 = Sketch_1.addPoint(2.39822858, -0.3588074)
194 SketchPoint_39.setAuxiliary(True)
196 ### Create SketchPoint
197 SketchPoint_40 = Sketch_1.addPoint(2.26992892, -0.41299464)
198 SketchPoint_40.setAuxiliary(True)
200 ### Create SketchPoint
201 SketchPoint_41 = Sketch_1.addPoint(2.12189678, -0.47704812)
202 SketchPoint_41.setAuxiliary(True)
204 ### Create SketchPoint
205 SketchPoint_42 = Sketch_1.addPoint(1.8998293, -0.5558238799999999)
206 SketchPoint_42.setAuxiliary(True)
208 ### Create SketchPoint
209 SketchPoint_43 = Sketch_1.addPoint(1.70246596, -0.6247334)
210 SketchPoint_43.setAuxiliary(True)
212 ### Create SketchPoint
213 SketchPoint_44 = Sketch_1.addPoint(1.52479656, -0.6640442000000001)
214 SketchPoint_44.setAuxiliary(True)
216 ### Create SketchPoint
217 SketchPoint_45 = Sketch_1.addPoint(1.33236634, -0.68847856)
218 SketchPoint_45.setAuxiliary(True)
220 ### Create SketchPoint
221 SketchPoint_46 = Sketch_1.addPoint(1.15223038, -0.7006186600000001)
222 SketchPoint_46.setAuxiliary(True)
224 ### Create SketchPoint
225 SketchPoint_47 = Sketch_1.addPoint(0.9819992000000001, -0.69792086)
226 SketchPoint_47.setAuxiliary(True)
228 ### Create SketchPoint
229 SketchPoint_48 = Sketch_1.addPoint(0.83392852, -0.6730240200000001)
230 SketchPoint_48.setAuxiliary(True)
232 ### Create SketchPoint
233 SketchPoint_49 = Sketch_1.addPoint(0.68589638, -0.63826094)
234 SketchPoint_49.setAuxiliary(True)
236 ### Create SketchPoint
237 SketchPoint_50 = Sketch_1.addPoint(0.5403308, -0.59359308)
238 SketchPoint_50.setAuxiliary(True)
240 ### Create SketchPoint
241 SketchPoint_51 = Sketch_1.addPoint(0.4144977, -0.52425962)
242 SketchPoint_51.setAuxiliary(True)
244 ### Create SketchPoint
245 SketchPoint_52 = Sketch_1.addPoint(0.30593052, -0.4549647)
246 SketchPoint_52.setAuxiliary(True)
248 ### Create SketchPoint
249 SketchPoint_53 = Sketch_1.addPoint(0.19243022, -0.37079334)
250 SketchPoint_53.setAuxiliary(True)
252 ### Create SketchPoint
253 SketchPoint_54 = Sketch_1.addPoint(0.09866240000000001, -0.26199492)
254 SketchPoint_54.setAuxiliary(True)
256 ### Create SketchPoint
257 SketchPoint_55 = Sketch_1.addPoint(0.04439808000000001, -0.17296752)
258 SketchPoint_55.setAuxiliary(True)
260 ### Create SketchPoint
261 SketchPoint_56 = Sketch_1.addPoint(0.009866240000000002, -0.08397866)
262 SketchPoint_56.setAuxiliary(True)
264 ### Create SketchBSpline
265 SketchBSpline_1_poles = [(0, 0),
266 (9.014752251795682e-05, 0.05451214529317949),
267 (0.02532271171862411, 0.15579971775632),
268 (0.1083431350565314, 0.2748971692083296),
269 (0.2055162110916063, 0.3762476714704591),
270 (0.3226869043516477, 0.4417758873955893),
271 (0.4396106030030269, 0.5114950821406695),
272 (0.5686113665746824, 0.5543315380381274),
273 (0.7080109281378321, 0.6032643908580265),
274 (0.8627418437966349, 0.6310529967664337),
275 (1.038760710497959, 0.658153841986185),
276 (1.22044861142381, 0.6481760900098785),
277 (1.409221724680022, 0.652722089409154),
278 (1.576578009046891, 0.6165884029638471),
279 (1.750622207371201, 0.6101568179490738),
280 (1.923498511038718, 0.5633997285939256),
281 (2.101468637706691, 0.5160168977121142),
282 (2.26756869845679, 0.4799182653430439),
283 (2.415109663038519, 0.4380247760586003),
284 (2.559003214216268, 0.3937264274604114),
285 (2.717970834232034, 0.3510185960290838),
286 (2.881379255194576, 0.2994130045705585),
287 (3.044331614256414, 0.2554589350745441),
288 (3.196663224032949, 0.2002205281261157),
289 (3.35069087314937, 0.1557508658621287),
290 (3.498630901739528, 0.1100749985226144),
291 (3.626758629069007, 0.07354615416618171),
292 (3.739427723854896, 0.03597634464461345),
293 (3.813716543275791, 0.02837078095396758),
294 (3.876876038873482, -0.02879298081488075),
295 (3.682323148493558, 0.01775150116288641),
296 (3.59938700895519, 0.01042701260276316),
297 (3.435447203044759, 0.007149079513330239),
298 (3.314513764134776, -0.02220772128681934),
299 (3.182869424552179, -0.05232760411385898),
300 (3.042896269666394, -0.100514554949581),
301 (2.881422363667536, -0.1529357624091178),
302 (2.715356347244389, -0.2233467064371046),
303 (2.550824101050389, -0.2921770145749832),
304 (2.405271709687486, -0.3565989754466863),
305 (2.262755596020973, -0.4148284616349733),
306 (2.100460548570712, -0.490254433165252),
307 (1.907228846355101, -0.5500679945331017),
308 (1.712805296160232, -0.627643180207678),
309 (1.521165382362285, -0.66728412705947),
310 (1.336949022926033, -0.6896647036620358),
311 (1.155869424658838, -0.7022133877004375),
312 (0.9881820016357848, -0.7038771014232653),
313 (0.8328845467272493, -0.6739914151454918),
314 (0.6860350214810707, -0.638614040735098),
315 (0.5400698242489836, -0.6015646418675653),
316 (0.4182804086275665, -0.5270754227323547),
317 (0.302266907807943, -0.4533758717656259),
318 (0.1873191972961234, -0.3753781603200299),
319 (0.1039872761267704, -0.2741082432964857),
320 (0.04328037620103962, -0.1770551690563165),
321 (0.006988972040230026, -0.08835445483623842),
322 (-0.0008115069204040052, -0.02871741534942534),
325 SketchBSpline_1 = Sketch_1.addSpline(degree = 3, poles = SketchBSpline_1_poles, weights = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], knots = [0, 0.01841877717868692, 0.03640857044229438, 0.0503319019589481, 0.06751503486217877, 0.08331688612829682, 0.09815550484724707, 0.1151806897007172, 0.1352802264972665, 0.1533760897133781, 0.1776976203324573, 0.1991289647725509, 0.2196078542088847, 0.2376437370925934, 0.2601966555045284, 0.2823272796231457, 0.3025579520551492, 0.3199893311119836, 0.3363024715699076, 0.3555578894595023, 0.3779215054846461, 0.3966205779803185, 0.4149403217914447, 0.43491563393835, 0.453062794308183, 0.4693759347661071, 0.4820291845192418, 0.4942387027706504, 0.496746319874324, 0.5066094106685624, 0.5312792857910991, 0.5454960476108249, 0.5602561299909423, 0.5757710096568369, 0.592796194510307, 0.6123837212555427, 0.6354982845523691, 0.6562477832463178, 0.6751789135618669, 0.6915216952124962, 0.7104486749233012, 0.7380977836510125, 0.762628078574017, 0.7839805979515587, 0.8067422887543781, 0.8279279725980087, 0.8479059568735401, 0.8655249471990413, 0.8833680589533851, 0.9012352967057089, 0.9180940098763235, 0.9332074432767975, 0.9497886416105058, 0.9666426179720728, 0.9788770179440802, 0.9900778977399243, 1], multiplicities = [4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4])
326 Sketch_1.setCoincident(SketchPoint_1.coordinates(), SketchBSpline_1.startPoint())
327 Sketch_1.setCoincident(SketchPoint_1.coordinates(), SketchBSpline_1.endPoint())
328 Sketch_1.setCoincident(SketchPoint_2.coordinates(), SketchBSpline_1.result())
329 Sketch_1.setCoincident(SketchPoint_3.coordinates(), SketchBSpline_1.result())
330 Sketch_1.setCoincident(SketchPoint_4.coordinates(), SketchBSpline_1.result())
331 Sketch_1.setCoincident(SketchPoint_5.coordinates(), SketchBSpline_1.result())
332 Sketch_1.setCoincident(SketchPoint_6.coordinates(), SketchBSpline_1.result())
333 Sketch_1.setCoincident(SketchPoint_7.coordinates(), SketchBSpline_1.result())
334 Sketch_1.setCoincident(SketchPoint_8.coordinates(), SketchBSpline_1.result())
335 Sketch_1.setCoincident(SketchPoint_9.coordinates(), SketchBSpline_1.result())
336 Sketch_1.setCoincident(SketchPoint_10.coordinates(), SketchBSpline_1.result())
337 Sketch_1.setCoincident(SketchPoint_11.coordinates(), SketchBSpline_1.result())
338 Sketch_1.setCoincident(SketchPoint_12.coordinates(), SketchBSpline_1.result())
339 Sketch_1.setCoincident(SketchPoint_13.coordinates(), SketchBSpline_1.result())
340 Sketch_1.setCoincident(SketchPoint_14.coordinates(), SketchBSpline_1.result())
341 Sketch_1.setCoincident(SketchPoint_15.coordinates(), SketchBSpline_1.result())
342 Sketch_1.setCoincident(SketchPoint_16.coordinates(), SketchBSpline_1.result())
343 Sketch_1.setCoincident(SketchPoint_17.coordinates(), SketchBSpline_1.result())
344 Sketch_1.setCoincident(SketchPoint_18.coordinates(), SketchBSpline_1.result())
345 Sketch_1.setCoincident(SketchPoint_19.coordinates(), SketchBSpline_1.result())
346 Sketch_1.setCoincident(SketchPoint_20.coordinates(), SketchBSpline_1.result())
347 Sketch_1.setCoincident(SketchPoint_21.coordinates(), SketchBSpline_1.result())
348 Sketch_1.setCoincident(SketchPoint_22.coordinates(), SketchBSpline_1.result())
349 Sketch_1.setCoincident(SketchPoint_23.coordinates(), SketchBSpline_1.result())
350 Sketch_1.setCoincident(SketchPoint_24.coordinates(), SketchBSpline_1.result())
351 Sketch_1.setCoincident(SketchPoint_25.coordinates(), SketchBSpline_1.result())
352 Sketch_1.setCoincident(SketchPoint_26.coordinates(), SketchBSpline_1.result())
353 Sketch_1.setCoincident(SketchPoint_27.coordinates(), SketchBSpline_1.result())
354 Sketch_1.setCoincident(SketchPoint_28.coordinates(), SketchBSpline_1.result())
355 Sketch_1.setCoincident(SketchPoint_29.coordinates(), SketchBSpline_1.result())
356 Sketch_1.setCoincident(SketchPoint_30.coordinates(), SketchBSpline_1.result())
357 Sketch_1.setCoincident(SketchPoint_31.coordinates(), SketchBSpline_1.result())
358 Sketch_1.setCoincident(SketchPoint_32.coordinates(), SketchBSpline_1.result())
359 Sketch_1.setCoincident(SketchPoint_33.coordinates(), SketchBSpline_1.result())
360 Sketch_1.setCoincident(SketchPoint_34.coordinates(), SketchBSpline_1.result())
361 Sketch_1.setCoincident(SketchPoint_35.coordinates(), SketchBSpline_1.result())
362 Sketch_1.setCoincident(SketchPoint_36.coordinates(), SketchBSpline_1.result())
363 Sketch_1.setCoincident(SketchPoint_37.coordinates(), SketchBSpline_1.result())
364 Sketch_1.setCoincident(SketchPoint_38.coordinates(), SketchBSpline_1.result())
365 Sketch_1.setCoincident(SketchPoint_39.coordinates(), SketchBSpline_1.result())
366 Sketch_1.setCoincident(SketchPoint_40.coordinates(), SketchBSpline_1.result())
367 Sketch_1.setCoincident(SketchPoint_41.coordinates(), SketchBSpline_1.result())
368 Sketch_1.setCoincident(SketchPoint_42.coordinates(), SketchBSpline_1.result())
369 Sketch_1.setCoincident(SketchPoint_43.coordinates(), SketchBSpline_1.result())
370 Sketch_1.setCoincident(SketchPoint_44.coordinates(), SketchBSpline_1.result())
371 Sketch_1.setCoincident(SketchPoint_45.coordinates(), SketchBSpline_1.result())
372 Sketch_1.setCoincident(SketchPoint_46.coordinates(), SketchBSpline_1.result())
373 Sketch_1.setCoincident(SketchPoint_47.coordinates(), SketchBSpline_1.result())
374 Sketch_1.setCoincident(SketchPoint_48.coordinates(), SketchBSpline_1.result())
375 Sketch_1.setCoincident(SketchPoint_49.coordinates(), SketchBSpline_1.result())
376 Sketch_1.setCoincident(SketchPoint_50.coordinates(), SketchBSpline_1.result())
377 Sketch_1.setCoincident(SketchPoint_51.coordinates(), SketchBSpline_1.result())
378 Sketch_1.setCoincident(SketchPoint_52.coordinates(), SketchBSpline_1.result())
379 Sketch_1.setCoincident(SketchPoint_53.coordinates(), SketchBSpline_1.result())
380 Sketch_1.setCoincident(SketchPoint_54.coordinates(), SketchBSpline_1.result())
381 Sketch_1.setCoincident(SketchPoint_55.coordinates(), SketchBSpline_1.result())
382 Sketch_1.setCoincident(SketchPoint_56.coordinates(), SketchBSpline_1.result())
386 #=========================================================================
387 # Make offset for testing B-spline
388 #=========================================================================
390 # This B-spline still failes on larger values and even smaller in reversed mode.
391 # But we still consider this as an impruvement because without approximation
392 # we have only "Offset algorithm failed" with the same conditions.
394 # Common offset params
395 SketchOffset_1_objects = [ SketchBSpline_1 ]
396 jointType = "KeepDistance"
397 isApproximated = True
399 # Test outside offset
403 SketchOffset_1 = Sketch_1.addOffset(SketchOffset_1_objects, offsetValue, isReversed, jointType, isApproximated)
406 # Hardcoded value was obtained by running the same script from SALOME Python Console.
407 assert(len(SketchOffset_1.offset()) == 124)
409 # Test reversed offset
413 SketchOffset_2 = Sketch_1.addOffset(SketchOffset_1_objects, offsetValue, isReversed, jointType, isApproximated)
416 assert(len(SketchOffset_2.offset()) == 101)