diff --git a/tests/pytest/test_csg2d.py b/tests/pytest/test_csg2d.py index 204e8ce1..596be0eb 100644 --- a/tests/pytest/test_csg2d.py +++ b/tests/pytest/test_csg2d.py @@ -3,6 +3,19 @@ import pytest import math from pytest import approx + +def check_area(geo, area): + if isinstance(geo, Solid2d): + g = CSG2d() + g.Add(geo) + geo = g + + m = geo.GenerateMesh() + ngs = pytest.importorskip("ngsolve") + mesh = ngs.Mesh(m) + mesh.Curve(5) + assert ngs.Integrate(1.0, mesh) == approx(area) + def test_two_circles(): c1 = Circle(center=(0,0), radius=1) c2 = c1.Rotate(45) @@ -82,6 +95,17 @@ def test_circle_plus_rect1(): mesh.Curve(5) assert ngs.Integrate(1.0, mesh) == approx(math.pi) +def test_circle_and_rect(): + c = Circle(center=(0,0),radius=1) + r = Rectangle((0,0),(1,1)) + + pi = math.pi + check_area(c-r, 3/4*pi) + check_area(c*r, 1/4*pi) + check_area(c+r, 3/4*pi+1) + check_area(r*c, 1/4*pi) + check_area(r+c, 3/4*pi+1) + if __name__ == "__main__": test_two_circles()