-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix bugs in geometry module + write tests
- Loading branch information
1 parent
ed436b3
commit 58627ad
Showing
2 changed files
with
49 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,48 @@ | ||
import numpy as np | ||
import pint | ||
import math | ||
|
||
from dataclassy import dataclass | ||
from pint import Quantity | ||
|
||
|
||
@dataclass(kwargs=True) | ||
class Solid: | ||
surface_area: pint.Quantity = None | ||
volume: pint.Quantity = None | ||
surface_area: Quantity = None | ||
volume: Quantity = None | ||
|
||
|
||
class Prism(Solid): | ||
length: pint.Quantity | ||
length: Quantity | ||
|
||
cross_section_perimeter: pint.Quantity | ||
cross_section_area: pint.Quantity | ||
cross_section_perimeter: Quantity | ||
cross_section_area: Quantity | ||
|
||
lateral_area: pint.Quantity = None | ||
lateral_area: Quantity = None | ||
|
||
def __init__(self) -> None: | ||
def __post_init__(self) -> None: | ||
self.lateral_area = self.cross_section_perimeter * self.length | ||
self.surface_area = self.lateral_area + 2 * self.cross_section_area | ||
self.volume = self.cross_section_area * self.length | ||
|
||
|
||
class Cylinder(Prism): | ||
diameter: pint.Quantity | ||
diameter: Quantity | ||
|
||
cross_section_perimeter: pint.Quantity = None | ||
cross_section_area: pint.Quantity = None | ||
cross_section_perimeter: Quantity = None | ||
cross_section_area: Quantity = None | ||
|
||
def __init__(self) -> None: | ||
def __post_init__(self) -> None: | ||
self.radius = self.diameter / 2 | ||
self.cross_section_perimeter = np.pi * self.diameter | ||
self.cross_section_area = np.pi * self.radius ** 2 | ||
self.cross_section_perimeter = math.pi * self.diameter | ||
self.cross_section_area = math.pi * self.radius ** 2 | ||
|
||
|
||
class RectangularPrism(Prism): | ||
width: pint.Quantity | ||
thickness: pint.Quantity | ||
width: Quantity | ||
thickness: Quantity | ||
|
||
cross_section_perimeter: pint.Quantity = None | ||
cross_section_area: pint.Quantity = None | ||
cross_section_perimeter: Quantity = None | ||
cross_section_area: Quantity = None | ||
|
||
def __init__(self) -> None: | ||
def __post_init__(self) -> None: | ||
self.cross_section_perimeter = 2 * (self.width + self.thickness) | ||
self.cross_section_area = self.width * self.thickness |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters