from math import sqrt def almostEqual(x: float, y: float) -> bool: return abs(x - y) < 10**-9 def distance(a: tuple[float, float], b: tuple[float, float]) -> float: """Calculate the distance between two points using the Euclidean distance formula.""" return sqrt((b[0] - a[0]) ** 2 + (b[1] - a[1]) ** 2) def triangleArea(a: float, b: float, c: float) -> float: """Calculate the area of a triangle using Heron's formula.""" semiperimeter = 0.5 * (a + b + c) return sqrt( semiperimeter * (semiperimeter - a) * (semiperimeter - b) * (semiperimeter - c) ) def triangleAreaByCoordinates( x1: float, y1: float, x2: float, y2: float, x3: float, y3: float ) -> float: """Calculate the area of a triangle given its coordinates.""" A = distance((x1, y1), (x2, y2)) B = distance((x2, y2), (x3, y3)) C = distance((x3, y3), (x1, y1)) return triangleArea(A, B, C) print("Testing triangleAreaByCoordinates()...", end="") assert almostEqual(triangleAreaByCoordinates(10, 11, 14, 11, 12, 13), 4) assert isinstance(triangleAreaByCoordinates(10, 11, 14, 11, 12, 13), float) assert almostEqual(triangleAreaByCoordinates(2, 4.0, 2, 7, 6.0, 7), 6) assert almostEqual(triangleAreaByCoordinates(0, 0, 12.0, 0, 12, 5), 30) assert almostEqual(triangleAreaByCoordinates(0, 0, 0, 1, 1, 1), 0.5) print("Passed!")