1 | <?php namespace Arcanedev\Units\Measures; |
||
13 | class Distance extends UnitMeasure implements DistanceContract |
||
14 | { |
||
15 | /* ------------------------------------------------------------------------------------------------ |
||
16 | | Traits |
||
17 | | ------------------------------------------------------------------------------------------------ |
||
18 | */ |
||
19 | use Calculatable; |
||
20 | |||
21 | /* ------------------------------------------------------------------------------------------------ |
||
22 | | Constructor |
||
23 | | ------------------------------------------------------------------------------------------------ |
||
24 | */ |
||
25 | /** |
||
26 | * Distance constructor. |
||
27 | * |
||
28 | * @param float|int $value |
||
29 | * @param string $unit |
||
30 | * @param array $options |
||
31 | */ |
||
32 | public function __construct($value = 0, $unit = self::M, array $options = []) |
||
36 | 176 | ||
37 | 176 | /* ------------------------------------------------------------------------------------------------ |
|
38 | 176 | | Getters & Setters |
|
39 | 176 | | ------------------------------------------------------------------------------------------------ |
|
40 | 176 | */ |
|
41 | 176 | /** |
|
42 | 132 | * Get the default names. |
|
43 | 176 | * |
|
44 | * @return array |
||
45 | */ |
||
46 | public function defaultNames() |
||
58 | 6 | ||
59 | 6 | /* ------------------------------------------------------------------------------------------------ |
|
60 | 6 | | Main Functions |
|
61 | 6 | | ------------------------------------------------------------------------------------------------ |
|
62 | 6 | */ |
|
63 | 6 | /** |
|
64 | 6 | * Make a distance instance. |
|
65 | * |
||
66 | * @param float|int $value |
||
67 | * @param string $unit |
||
68 | * @param array $options |
||
69 | * |
||
70 | * @return static |
||
71 | */ |
||
72 | public static function make($value = 0, $unit = self::M, array $options = []) |
||
76 | 8 | ||
77 | /** |
||
78 | 8 | * Convert the distance to the given unit. |
|
79 | * |
||
80 | * @param string $to |
||
81 | * |
||
82 | * @return \Arcanedev\Units\Contracts\Measures\Distance |
||
83 | */ |
||
84 | public function to($to) |
||
92 | |||
93 | /** |
||
94 | 72 | * Convert the distance. |
|
95 | * |
||
96 | 72 | * @param string $from |
|
97 | * @param string $to |
||
98 | * @param float|int $value |
||
99 | * |
||
100 | * @return float|int |
||
101 | */ |
||
102 | public static function convert($from, $to, $value) |
||
106 | 72 | ||
107 | /* ------------------------------------------------------------------------------------------------ |
||
108 | 72 | | Calculation Functions |
|
109 | | ------------------------------------------------------------------------------------------------ |
||
110 | 24 | */ |
|
111 | /** |
||
112 | 24 | * Add the distance. |
|
113 | * |
||
114 | * @param float|int $value |
||
115 | * @param string $unit |
||
116 | * |
||
117 | * @return \Arcanedev\Units\Contracts\Measures\Distance |
||
118 | */ |
||
119 | public function addDistance($value, $unit = self::M) |
||
125 | |||
126 | 24 | /** |
|
127 | * Sub the distance. |
||
128 | * |
||
129 | * @param float|int $value |
||
130 | * @param string $unit |
||
131 | * |
||
132 | * @return \Arcanedev\Units\Contracts\Measures\Distance |
||
133 | */ |
||
134 | public function subDistance($value, $unit = self::M) |
||
140 | |||
141 | 16 | /* ------------------------------------------------------------------------------------------------ |
|
142 | | Other Functions |
||
143 | 16 | | ------------------------------------------------------------------------------------------------ |
|
144 | 16 | */ |
|
145 | 12 | /** |
|
146 | * Get the distance convert ratio. |
||
147 | * |
||
148 | * @param string $to |
||
149 | * @param string $from |
||
150 | * |
||
151 | * @return float|int |
||
152 | */ |
||
153 | protected static function getRatio($to, $from) |
||
164 | |||
165 | /** |
||
166 | * Get all the distance ratios. |
||
167 | * |
||
168 | * @return array |
||
169 | */ |
||
170 | protected static function getRatios() |
||
187 | } |
||
188 |