MCPcopy
hub / github.com/CadQuery/cadquery / test_approximate2D

Function test_approximate2D

tests/test_nurbs.py:347–389  ·  view source on GitHub ↗
(lam, penalty)

Source from the content-addressed store, hash-verified

345
346@mark.parametrize(("penalty", "lam"), [(3, 1e-6), (4, 1e-6), (5, 1e-6), (2, 0)])
347def test_approximate2D(lam, penalty):
348
349 t = torus(5, 1).face()
350
351 # double periodic surface
352 us = np.linspace(0, 1, endpoint=False)
353 vs = np.linspace(0, 1, endpoint=False)
354
355 pts = np.array(
356 [t.positionAt(u * 2 * np.pi, v * 2 * np.pi).toTuple() for v in vs for u in us]
357 )
358
359 surf = approximate2D(
360 pts,
361 us[None, :].repeat(len(vs), 0).ravel(),
362 vs[:, None].repeat(len(us), 1).ravel(),
363 3,
364 3,
365 15,
366 15,
367 uperiodic=True,
368 vperiodic=True,
369 penalty=penalty,
370 lam=lam,
371 )
372
373 f = surf.face()
374
375 # general sanity checks
376 assert f.isValid()
377 assert f.Area() == approx(t.Area(), rel=1e-3)
378
379 # check the stability of the parameters
380 us0 = us[None, :].repeat(len(vs), 0).ravel()
381 vs0 = vs[:, None].repeat(len(us), 1).ravel()
382
383 us2, vs2 = f.params(array2vec(pts))
384
385 delta_u = np.array(us2 - us0)
386 delta_v = np.array(vs2 - vs0)
387
388 assert np.allclose(np.where(delta_u >= 1, delta_u, 0) % 1, 0)
389 assert np.allclose(np.where(delta_v >= 1, delta_v, 0) % 1, 0)
390
391
392EDGES = (

Callers

nothing calls this directly

Calls 9

approximate2DFunction · 0.90
array2vecFunction · 0.90
torusFunction · 0.85
isValidMethod · 0.80
faceMethod · 0.45
toTupleMethod · 0.45
positionAtMethod · 0.45
AreaMethod · 0.45
paramsMethod · 0.45

Tested by

no test coverage detected