Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
7 / 7 |
|
100.00% |
7 / 7 |
CRAP | |
100.00% |
1 / 1 |
| Trapezoid | |
100.00% |
7 / 7 |
|
100.00% |
7 / 7 |
7 | |
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 | |||
| getA | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getB | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getC | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getD | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 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 | * Trapezoid 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 Trapezoid implements D2ShapeInterface |
| 26 | { |
| 27 | /** |
| 28 | * Area |
| 29 | * |
| 30 | * --- a ---- |
| 31 | * / | \ |
| 32 | * c h d |
| 33 | * / | \ |
| 34 | * -------- b --------- |
| 35 | * |
| 36 | * @param float $a Edge |
| 37 | * @param float $b Edge |
| 38 | * @param float $h Height |
| 39 | * |
| 40 | * @return float |
| 41 | * |
| 42 | * @since 1.0.0 |
| 43 | */ |
| 44 | public static function getSurface(float $a, float $b, float $h) : float |
| 45 | { |
| 46 | return ($a + $b) / 2 * $h; |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Perimeter |
| 51 | * |
| 52 | * --- a ---- |
| 53 | * / | \ |
| 54 | * c h d |
| 55 | * / | \ |
| 56 | * -------- b --------- |
| 57 | * |
| 58 | * @param float $a Edge |
| 59 | * @param float $b Edge |
| 60 | * @param float $c Edge |
| 61 | * @param float $d Edge |
| 62 | * |
| 63 | * @return float |
| 64 | * |
| 65 | * @since 1.0.0 |
| 66 | */ |
| 67 | public static function getPerimeter(float $a, float $b, float $c, float $d) : float |
| 68 | { |
| 69 | return $a + $b + $c + $d; |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Height |
| 74 | * |
| 75 | * --- a ---- |
| 76 | * / | \ |
| 77 | * c h d |
| 78 | * / | \ |
| 79 | * -------- b --------- |
| 80 | * |
| 81 | * @param float $area Area |
| 82 | * @param float $a Edge |
| 83 | * @param float $b Edge |
| 84 | * |
| 85 | * @return float |
| 86 | * |
| 87 | * @since 1.0.0 |
| 88 | */ |
| 89 | public static function getHeight(float $area, float $a, float $b) : float |
| 90 | { |
| 91 | return 2 * $area / ($a + $b); |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * A |
| 96 | * |
| 97 | * --- a ---- |
| 98 | * / | \ |
| 99 | * c h d |
| 100 | * / | \ |
| 101 | * -------- b --------- |
| 102 | * |
| 103 | * @param float $area Area |
| 104 | * @param float $h Height |
| 105 | * @param float $b Edge |
| 106 | * |
| 107 | * @return float |
| 108 | * |
| 109 | * @since 1.0.0 |
| 110 | */ |
| 111 | public static function getA(float $area, float $h, float $b) : float |
| 112 | { |
| 113 | return 2 * $area / $h - $b; |
| 114 | } |
| 115 | |
| 116 | /** |
| 117 | * B |
| 118 | * |
| 119 | * --- a ---- |
| 120 | * / | \ |
| 121 | * c h d |
| 122 | * / | \ |
| 123 | * -------- b --------- |
| 124 | * |
| 125 | * @param float $area Area |
| 126 | * @param float $h Height |
| 127 | * @param float $a Edge |
| 128 | * |
| 129 | * @return float |
| 130 | * |
| 131 | * @since 1.0.0 |
| 132 | */ |
| 133 | public static function getB(float $area, float $h, float $a) : float |
| 134 | { |
| 135 | return 2 * $area / $h - $a; |
| 136 | } |
| 137 | |
| 138 | /** |
| 139 | * C |
| 140 | * |
| 141 | * --- a ---- |
| 142 | * / | \ |
| 143 | * c h d |
| 144 | * / | \ |
| 145 | * -------- b --------- |
| 146 | * |
| 147 | * @param float $perimeter Perimeter |
| 148 | * @param float $a Edge |
| 149 | * @param float $b Edge |
| 150 | * @param float $d Edge |
| 151 | * |
| 152 | * @return float |
| 153 | * |
| 154 | * @since 1.0.0 |
| 155 | */ |
| 156 | public static function getC(float $perimeter, float $a, float $b, float $d) : float |
| 157 | { |
| 158 | return $perimeter - $a - $b - $d; |
| 159 | } |
| 160 | |
| 161 | /** |
| 162 | * D |
| 163 | * |
| 164 | * --- a ---- |
| 165 | * / | \ |
| 166 | * c h d |
| 167 | * / | \ |
| 168 | * -------- b --------- |
| 169 | * |
| 170 | * @param float $perimeter Perimeter |
| 171 | * @param float $a Edge |
| 172 | * @param float $b Edge |
| 173 | * @param float $c Edge |
| 174 | * |
| 175 | * @return float |
| 176 | * |
| 177 | * @since 1.0.0 |
| 178 | */ |
| 179 | public static function getD(float $perimeter, float $a, float $b, float $c) : float |
| 180 | { |
| 181 | return $perimeter - $a - $b - $c; |
| 182 | } |
| 183 | } |