Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
7 / 7 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
| Triangle | |
100.00% |
7 / 7 |
|
100.00% |
4 / 4 |
5 | |
100.00% |
1 / 1 |
| getSurface | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getPerimeter | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getHeight | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getHypot | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Jingga |
| 4 | * |
| 5 | * PHP Version 8.1 |
| 6 | * |
| 7 | * @package phpOMS\Math\Geometry\Shape\D2 |
| 8 | * @copyright Dennis Eichhorn |
| 9 | * @license OMS License 2.0 |
| 10 | * @version 1.0.0 |
| 11 | * @link https://jingga.app |
| 12 | */ |
| 13 | declare(strict_types=1); |
| 14 | |
| 15 | namespace phpOMS\Math\Geometry\Shape\D2; |
| 16 | |
| 17 | /** |
| 18 | * Triangle shape. |
| 19 | * |
| 20 | * @package phpOMS\Math\Geometry\Shape\D2 |
| 21 | * @license OMS License 2.0 |
| 22 | * @link https://jingga.app |
| 23 | * @since 1.0.0 |
| 24 | */ |
| 25 | final class Triangle implements D2ShapeInterface |
| 26 | { |
| 27 | /** |
| 28 | * Area |
| 29 | * |
| 30 | * . |
| 31 | * /|\ |
| 32 | * a h c |
| 33 | * / | \ |
| 34 | * ----b--- |
| 35 | * |
| 36 | * @param float $b Edge |
| 37 | * @param float $h Height |
| 38 | * |
| 39 | * @return float |
| 40 | * |
| 41 | * @since 1.0.0 |
| 42 | */ |
| 43 | public static function getSurface(float $b, float $h) : float |
| 44 | { |
| 45 | return $h * $b / 2; |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Perimeter |
| 50 | * |
| 51 | * @param float $a Edge |
| 52 | * @param float $b Edge |
| 53 | * @param float $c Edge |
| 54 | * |
| 55 | * @return float |
| 56 | * |
| 57 | * @since 1.0.0 |
| 58 | */ |
| 59 | public static function getPerimeter(float $a, float $b, float $c) : float |
| 60 | { |
| 61 | return $a + $b + $c; |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Diagonal |
| 66 | * |
| 67 | * @param float $area Area |
| 68 | * @param float $b Edge |
| 69 | * |
| 70 | * @return float |
| 71 | * |
| 72 | * @since 1.0.0 |
| 73 | */ |
| 74 | public static function getHeight(float $area, float $b) : float |
| 75 | { |
| 76 | return 2 * $area / $b; |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Calculate the hypothenuse |
| 81 | * |
| 82 | * @param mixed ...$vec Vector of values |
| 83 | * |
| 84 | * @return float |
| 85 | * |
| 86 | * @since 1.0.0 |
| 87 | */ |
| 88 | public static function getHypot(mixed ...$vec) : float |
| 89 | { |
| 90 | $hypot = 0.0; |
| 91 | foreach ($vec as $val) { |
| 92 | $hypot += $val * $val; |
| 93 | } |
| 94 | |
| 95 | return \sqrt($hypot); |
| 96 | } |
| 97 | } |