|
41 | 41 | Polygon, |
42 | 42 | Sketch, |
43 | 43 | SketchCircle, |
| 44 | + SketchEdge, |
44 | 45 | SketchEllipse, |
45 | 46 | SketchSegment, |
46 | 47 | Slot, |
| 48 | + SpurGear, |
| 49 | + Triangle, |
47 | 50 | ) |
48 | 51 |
|
49 | 52 | from .conftest import are_graphics_available |
50 | 53 |
|
51 | 54 | DOUBLE_EPS = np.finfo(float).eps |
52 | 55 |
|
53 | 56 |
|
| 57 | +def test_sketch_sketch(): |
| 58 | + """Test the sketch sketch tag functionality""" |
| 59 | + sketch = Sketch() |
| 60 | + sketch.segment(Point2D([-4, 5], unit=UNITS.m), Point2D([4, 5], unit=UNITS.m)) |
| 61 | + sketch.tag = "SketchTag" |
| 62 | + assert sketch.tag == "SketchTag" |
| 63 | + |
| 64 | + |
| 65 | +def test_sketch_segment(): |
| 66 | + """Test the sketch segment unit conversion for end point, not equal, |
| 67 | + and plane change functionality""" |
| 68 | + start_point = Point2D([0, 0], unit=UNITS.meter) |
| 69 | + end_point = Point2D([5, 5], unit=UNITS.kilometer) |
| 70 | + segment1 = SketchSegment(start_point, end_point) |
| 71 | + assert segment1.end == Point2D([5000, 5000]) |
| 72 | + segment2 = SketchSegment(start_point, end_point) |
| 73 | + assert segment1.__ne__(segment2) is False |
| 74 | + segment2 = SketchSegment(end_point, start_point) |
| 75 | + assert segment1.__ne__(segment2) is True |
| 76 | + new_plane = Plane( |
| 77 | + origin=Point3D([0, 0, 5]), direction_x=Vector3D([1, 0, 0]), direction_y=Vector3D([0, 0, 1]) |
| 78 | + ) |
| 79 | + segment1.plane_change(new_plane) |
| 80 | + assert segment1.direction == UnitVector3D([0.70710678, 0.0, 0.70710678]) |
| 81 | + |
| 82 | + |
| 83 | +@pytest.mark.skipif( |
| 84 | + not are_graphics_available(), reason="Skipping due to graphics requirements missing" |
| 85 | +) |
| 86 | +def test_sketch_gears(): |
| 87 | + """Test the sketch gears addendum, dedendum, and visualization polydate functionality""" |
| 88 | + origin = Point2D([0, 1], unit=UNITS.meter) |
| 89 | + module = 40 |
| 90 | + pressure_angle = Quantity(20, UNITS.deg) |
| 91 | + n_teeth = 22 |
| 92 | + gearspur = SpurGear(origin, module, pressure_angle, n_teeth) |
| 93 | + assert gearspur.addendum == 40.0 |
| 94 | + assert gearspur.dedendum == 50.0 |
| 95 | + gearspurpoly = gearspur.visualization_polydata |
| 96 | + assert gearspurpoly.center == pytest.approx( |
| 97 | + ([0.0, 1.0000000298023224, 0.0]), |
| 98 | + rel=1e-7, |
| 99 | + abs=1e-8, |
| 100 | + ) |
| 101 | + assert gearspurpoly.bounds == pytest.approx( |
| 102 | + [-0.4852221608161926, 0.4852221608161926, 0.5148882269859314, 1.4851118326187134, 0.0, 0.0], |
| 103 | + rel=1e-7, |
| 104 | + abs=1e-8, |
| 105 | + ) |
| 106 | + assert gearspurpoly.n_cells == 704 |
| 107 | + assert gearspurpoly.n_points == 70405 |
| 108 | + assert gearspurpoly.n_open_edges == 0.0 |
| 109 | + |
| 110 | + |
| 111 | +def test_sketch_circle_plane_change(): |
| 112 | + """Test the sketch circle change plane functionality""" |
| 113 | + center = Point2D([5, 10], UNITS.m) |
| 114 | + radius = 3 * UNITS.m |
| 115 | + circle = SketchCircle(center, radius) |
| 116 | + new_plane = Plane( |
| 117 | + origin=Point3D([0, 0, 5]), direction_x=Vector3D([1, 0, 0]), direction_y=Vector3D([0, 0, 1]) |
| 118 | + ) |
| 119 | + circle.plane_change(new_plane) |
| 120 | + assert circle.dir_x == Vector3D([1, 0, 0]) |
| 121 | + assert circle.dir_y == Vector3D([0, 0, 1]) |
| 122 | + assert circle.dir_z == Vector3D([0, -1, 0]) |
| 123 | + |
| 124 | + |
| 125 | +def test_sketch_face(): |
| 126 | + """Test the sketch face perimeter and change plane functionality""" |
| 127 | + sketch = Sketch() |
| 128 | + per = Triangle(Point2D([10, 10]), Point2D([2, 1]), Point2D([10, -10])).perimeter |
| 129 | + assert abs((per - 45.64306508752774 * UNITS.m).m) <= 5e-14 |
| 130 | + sketch.triangle(Point2D([10, 10]), Point2D([2, 1]), Point2D([10, -10]), tag="Triangle") |
| 131 | + |
| 132 | + new_plane = Plane( |
| 133 | + origin=Point3D([0, 0, 5]), direction_x=Vector3D([1, 0, 0]), direction_y=Vector3D([0, 0, 1]) |
| 134 | + ) |
| 135 | + sketch.faces[0].plane_change(new_plane) |
| 136 | + |
| 137 | + |
| 138 | +def test_sketch_edge(): |
| 139 | + """Test the sketch edge functionality""" |
| 140 | + sketch = SketchEdge() |
| 141 | + with pytest.raises( |
| 142 | + NotImplementedError, match="Each edge must provide the start point definition." |
| 143 | + ): |
| 144 | + sketch.start() |
| 145 | + with pytest.raises( |
| 146 | + NotImplementedError, match="Each edge must provide the end point definition." |
| 147 | + ): |
| 148 | + sketch.end() |
| 149 | + with pytest.raises(NotImplementedError, match="Each edge must provide the length definition."): |
| 150 | + sketch.length() |
| 151 | + with pytest.raises( |
| 152 | + NotImplementedError, match="Each edge must provide the polydata definition." |
| 153 | + ): |
| 154 | + sketch.visualization_polydata() |
| 155 | + plane = Plane( |
| 156 | + origin=Point3D([0, 0, 0]), direction_x=Vector3D([1, 2, -1]), direction_y=Vector3D([1, 0, 1]) |
| 157 | + ) |
| 158 | + sketch.plane_change(plane) |
| 159 | + |
| 160 | + |
54 | 161 | def test_errors_sketch_segment(): |
55 | 162 | """Check errors when handling a ``SketchSegment``.""" |
56 | 163 | with pytest.raises(BeartypeCallHintParamViolation): |
|
0 commit comments