11################################################################################
22"""
3- electricpy.geometry.triangle - Collection of methods which operate on Cartesian
4- triangles.
3+ electricpy.geometry.triangle - Collection of methods for Cartesian triangles.
54
65>>> import electricpy.geometry.triangle as triangle
76
1211
1312from __future__ import annotations
1413
15- from typing import Iterable , Optional , Sequence , Tuple , Union
14+ from typing import Tuple , Union
1615import math
1716
1817from electricpy .geometry import Point , Line
@@ -42,9 +41,7 @@ def _is_close(a: float, b: float, *, rel_tol: float = 1e-9, abs_tol: float = 1e-
4241
4342
4443def _triangle_twice_area (p0 : Point , p1 : Point , p2 : Point ) -> float :
45- """
46- Return twice the signed area (cross product magnitude).
47- """
44+ """Return twice the signed area (cross product magnitude)."""
4845 return (p1 .x - p0 .x ) * (p2 .y - p0 .y ) - (p1 .y - p0 .y ) * (p2 .x - p0 .x )
4946
5047
@@ -115,9 +112,7 @@ def perimeter(self) -> float:
115112 return self .a + self .b + self .c
116113
117114 def perimeters (self ) -> float :
118- """
119- Backward-compatible alias for perimeter().
120- """
115+ """Backward-compatible alias for perimeter()."""
121116 return self .perimeter ()
122117
123118 def area (self ) -> float :
@@ -151,9 +146,9 @@ def centroid(self) -> Point:
151146
152147 def in_center (self ) -> Point :
153148 """
154- Return the incenter of the triangle.
149+ Return the in_center of the triangle.
155150
156- The incenter is the weighted average of vertices by the lengths of
151+ The in_center is the weighted average of vertices by the lengths of
157152 the opposite sides. With our naming:
158153 a = |p0-p1| opposite vertex p2
159154 b = |p1-p2| opposite vertex p0
@@ -172,7 +167,7 @@ def in_center(self) -> Point:
172167
173168 def in_radius (self ) -> float :
174169 """
175- Return the inradius of the triangle.
170+ Return the in_radius of the triangle.
176171
177172 r = A / s where s is semiperimeter.
178173 """
@@ -184,12 +179,12 @@ def in_radius(self) -> float:
184179
185180 def ortho_center (self ) -> Point :
186181 """
187- Return the orthocenter of the triangle.
182+ Return the ortho_center of the triangle.
188183
189184 Construct two altitudes:
190185 - altitude from p0 to line through p1-p2
191186 - altitude from p1 to line through p0-p2
192- Their intersection is the orthocenter .
187+ Their intersection is the ortho_center .
193188
194189 Requires Line objects returned by geometry.line_equation to support:
195190 - foot_perpendicular(Point) -> Point
@@ -207,7 +202,7 @@ def ortho_center(self) -> Point:
207202
208203 def circum_center (self ) -> Point :
209204 """
210- Return the circumcenter of the triangle.
205+ Return the circum_center of the triangle.
211206
212207 Intersection of perpendicular bisectors of two sides.
213208 """
@@ -217,21 +212,23 @@ def circum_center(self) -> Point:
217212
218213 def circum_radius (self ) -> float :
219214 """
220- Return the circumradius of the triangle.
215+ Return the circum_radius of the triangle.
221216
222217 R = abc / (4A)
223218 """
224219 A = self .area ()
225220 if _is_close (A , 0.0 , abs_tol = self ._tol ):
226- raise ValueError ("Degenerate triangle: area is zero, circumradius undefined" )
221+ raise ValueError ("Degenerate triangle: area is zero, circum_radius undefined" )
227222 return (self .a * self .b * self .c ) / (4.0 * A )
228223
229224 # -------------------------------------------------------------------------
230225 # Validation
231226 # -------------------------------------------------------------------------
232227 def __is_valid (self ) -> bool :
233228 """
234- Validate triangle:
229+ Validate triangle.
230+
231+ Checks:
235232 - triangle inequality with tolerance
236233 - non-collinear (non-degenerate) using cross-product area test
237234 """
0 commit comments