File indexing completed on 2026-04-17 07:47:24
0001 import pytest
0002
0003 import acts
0004
0005
0006 def test_surface_bounds_base_api():
0007 bounds = acts.RectangleBounds(10.0, 5.0)
0008
0009 assert bounds.type == acts.SurfaceBoundsType.Rectangle
0010 assert bounds.isCartesian() is True
0011 assert bounds.values() == [-10.0, -5.0, 10.0, 5.0]
0012 assert bounds.inside(acts.Vector2(0.0, 0.0)) is True
0013 assert bounds.inside(acts.Vector2(100.0, 100.0)) is False
0014 assert bounds.distance(acts.Vector2(0.0, 0.0)) == pytest.approx(5.0)
0015 center = bounds.center()
0016 assert center[0] == pytest.approx(0.0)
0017 assert center[1] == pytest.approx(0.0)
0018 assert "RectangleBounds" in str(bounds)
0019
0020
0021 def test_boundary_tolerance_binding_and_inside_overload():
0022 none_tol = acts.BoundaryTolerance.none()
0023 inf_tol = acts.BoundaryTolerance.infinite()
0024 abs_tol = acts.BoundaryTolerance.absoluteEuclidean(0.5)
0025
0026 assert none_tol.isNone() is True
0027 assert none_tol.isInfinite() is False
0028
0029 assert inf_tol.isInfinite() is True
0030 assert inf_tol.isNone() is False
0031
0032 assert abs_tol.hasAbsoluteEuclidean() is True
0033 assert abs_tol.hasChi2Bound() is False
0034 assert abs_tol.hasChi2Cartesian() is False
0035
0036 bounds = acts.RectangleBounds(10.0, 5.0)
0037 assert bounds.inside(acts.Vector2(0.0, 0.0), none_tol) is True
0038 assert bounds.inside(acts.Vector2(100.0, 100.0), inf_tol) is True
0039
0040
0041 def test_bound_value_enums_exposed():
0042 assert acts.CylinderBoundsValue.R is not None
0043 assert acts.AnnulusBoundsValue.MinR is not None
0044 assert acts.RadialBoundsValue.MinR is not None
0045 assert acts.LineBoundsValue.R is not None
0046 assert acts.RectangleBoundsValue.MinX is not None
0047 assert acts.TrapezoidBoundsValue.HalfLengthXnegY is not None
0048
0049
0050 @pytest.mark.parametrize(
0051 "bounds, expected_size",
0052 [
0053 (acts.CylinderBounds(10.0, 20.0), 6),
0054 (acts.AnnulusBounds(10.0, 20.0, -0.2, 0.2), 7),
0055 (acts.RadialBounds(10.0, 20.0), 4),
0056 (acts.LineBounds(1.0, 100.0), 2),
0057 (acts.RectangleBounds(10.0, 20.0), 4),
0058 (acts.TrapezoidBounds(8.0, 12.0, 20.0, 0.1), 4),
0059 ],
0060 )
0061 def test_surface_bounds_indexing(bounds, expected_size):
0062 assert len(bounds) == expected_size
0063 for i in range(expected_size):
0064 assert bounds[i] == pytest.approx(bounds.values()[i])
0065
0066 with pytest.raises(IndexError):
0067 _ = bounds[expected_size]
0068
0069 with pytest.raises(IndexError):
0070 _ = bounds[-1]
0071
0072
0073 def test_surface_bounds_get_method():
0074 cylinder = acts.CylinderBounds(10.0, 20.0)
0075 assert cylinder.get(acts.CylinderBoundsValue.R) == pytest.approx(10.0)
0076 assert cylinder.get(acts.CylinderBoundsValue.HalfLengthZ) == pytest.approx(20.0)
0077 assert cylinder.get(acts.CylinderBoundsValue.HalfPhiSector) == pytest.approx(
0078 cylinder.values()[2]
0079 )
0080 assert cylinder.get(acts.CylinderBoundsValue.AveragePhi) == pytest.approx(
0081 cylinder.values()[3]
0082 )
0083 assert cylinder.get(acts.CylinderBoundsValue.BevelMinZ) == pytest.approx(
0084 cylinder.values()[4]
0085 )
0086 assert cylinder.get(acts.CylinderBoundsValue.BevelMaxZ) == pytest.approx(
0087 cylinder.values()[5]
0088 )
0089
0090 annulus = acts.AnnulusBounds(10.0, 20.0, -0.2, 0.2)
0091 assert annulus.get(acts.AnnulusBoundsValue.MinR) == pytest.approx(10.0)
0092 assert annulus.get(acts.AnnulusBoundsValue.MaxR) == pytest.approx(20.0)
0093 assert annulus.get(acts.AnnulusBoundsValue.MinPhiRel) == pytest.approx(-0.2)
0094 assert annulus.get(acts.AnnulusBoundsValue.MaxPhiRel) == pytest.approx(0.2)
0095 assert annulus.get(acts.AnnulusBoundsValue.OriginX) == pytest.approx(
0096 annulus.values()[4]
0097 )
0098 assert annulus.get(acts.AnnulusBoundsValue.OriginY) == pytest.approx(
0099 annulus.values()[5]
0100 )
0101
0102 radial = acts.RadialBounds(11.0, 21.0)
0103 assert radial.get(acts.RadialBoundsValue.MinR) == pytest.approx(11.0)
0104 assert radial.get(acts.RadialBoundsValue.MaxR) == pytest.approx(21.0)
0105 assert radial.get(acts.RadialBoundsValue.HalfPhiSector) == pytest.approx(
0106 radial.values()[2]
0107 )
0108 assert radial.get(acts.RadialBoundsValue.AveragePhi) == pytest.approx(
0109 radial.values()[3]
0110 )
0111
0112 line = acts.LineBounds(1.0, 100.0)
0113 assert line.get(acts.LineBoundsValue.R) == pytest.approx(1.0)
0114 assert line.get(acts.LineBoundsValue.HalfLengthZ) == pytest.approx(100.0)
0115
0116 rectangle = acts.RectangleBounds(10.0, 20.0)
0117 assert rectangle.get(acts.RectangleBoundsValue.MinX) == pytest.approx(-10.0)
0118 assert rectangle.get(acts.RectangleBoundsValue.MinY) == pytest.approx(-20.0)
0119 assert rectangle.get(acts.RectangleBoundsValue.MaxX) == pytest.approx(10.0)
0120 assert rectangle.get(acts.RectangleBoundsValue.MaxY) == pytest.approx(20.0)
0121
0122 trapezoid = acts.TrapezoidBounds(8.0, 12.0, 20.0, 0.1)
0123 assert trapezoid.get(acts.TrapezoidBoundsValue.HalfLengthXnegY) == pytest.approx(
0124 8.0
0125 )
0126 assert trapezoid.get(acts.TrapezoidBoundsValue.HalfLengthXposY) == pytest.approx(
0127 12.0
0128 )
0129 assert trapezoid.get(acts.TrapezoidBoundsValue.HalfLengthY) == pytest.approx(20.0)
0130 assert trapezoid.get(acts.TrapezoidBoundsValue.RotationAngle) == pytest.approx(0.1)
0131
0132
0133 def test_surface_factory_and_surface_api():
0134 gctx = acts.GeometryContext.dangerouslyDefaultConstruct()
0135 transform = acts.Transform3.Identity()
0136
0137 plane_bounds = acts.RectangleBounds(10.0, 5.0)
0138 plane = acts.Surface.createPlane(transform, plane_bounds)
0139 assert isinstance(plane, acts.PlaneSurface)
0140 assert plane.type == acts.SurfaceType.Plane
0141 assert plane.bounds == plane_bounds
0142 assert plane.thickness == pytest.approx(0.0)
0143 assert isinstance(plane.isSensitive, bool)
0144 assert isinstance(plane.isAlignable, bool)
0145
0146 local = acts.Vector2(1.0, 1.0)
0147 direction = acts.Vector3(0.0, 0.0, 1.0)
0148 global_position = plane.localToGlobal(gctx, local, direction)
0149 assert plane.insideBounds(local, acts.BoundaryTolerance.none()) is True
0150 assert (
0151 plane.isOnSurface(
0152 gctx, global_position, direction, acts.BoundaryTolerance.none(), 0.0
0153 )
0154 is True
0155 )
0156 assert "PlaneSurface" in plane.name
0157 assert "PlaneSurface" in plane.toString(gctx)
0158
0159 cylinder = acts.Surface.createCylinder(transform, acts.CylinderBounds(20.0, 50.0))
0160 assert isinstance(cylinder, acts.CylinderSurface)
0161 assert cylinder.type == acts.SurfaceType.Cylinder
0162
0163 perigee = acts.Surface.createPerigee(acts.Vector3(0.0, 0.0, 0.0))
0164 assert isinstance(perigee, acts.PerigeeSurface)
0165 assert perigee.type == acts.SurfaceType.Perigee