1+ //! Types and contants for handling areas.
2+
13use super :: measurement:: * ;
24use super :: length;
35
6+ /// Number of acres in a square meter
47const SQUARE_METER_ACRE_FACTOR : f64 = 1.0 / 4046.86 ;
58
69/// The `Area` struct can be used to deal with areas in a common way.
@@ -21,205 +24,244 @@ pub struct Area {
2124}
2225
2326impl Area {
24- // Inputs, metric, with both spellings of meter/metre
25-
27+ /// Create new area from floating point value in Square Meters
2628 pub fn from_square_meters ( square_meters : f64 ) -> Self {
2729 Area { square_meters : square_meters }
2830 }
2931
32+ /// Create new area from floating point value in Square Metres
3033 pub fn from_square_metres ( square_metres : f64 ) -> Self {
3134 Self :: from_square_meters ( square_metres)
3235 }
3336
37+ /// Create new area from floating point value in Square Nanometers
3438 pub fn from_square_nanometers ( square_nanometers : f64 ) -> Self {
3539 Self :: from_square_meters (
3640 square_nanometers / ( length:: METER_NANOMETER_FACTOR * length:: METER_NANOMETER_FACTOR ) ,
3741 )
3842 }
3943
44+ /// Create new area from floating point value in Square Nanometres
4045 pub fn from_square_nanometres ( square_nanometres : f64 ) -> Self {
4146 Self :: from_square_nanometers ( square_nanometres)
4247 }
4348
49+ /// Create new area from floating point value in Square Micrometers
4450 pub fn from_square_micrometers ( square_micrometers : f64 ) -> Self {
4551 Self :: from_square_meters (
4652 square_micrometers / ( length:: METER_MICROMETER_FACTOR * length:: METER_MICROMETER_FACTOR ) ,
4753 )
4854 }
4955
56+ /// Create new area from floating point value in Square Micrometres
5057 pub fn from_square_micrometres ( square_micrometres : f64 ) -> Self {
5158 Self :: from_square_micrometers ( square_micrometres)
5259 }
5360
61+ /// Create new area from floating point value in Square Millimeters
5462 pub fn from_square_millimeters ( square_millimeters : f64 ) -> Self {
5563 Self :: from_square_meters (
5664 square_millimeters / ( length:: METER_MILLIMETER_FACTOR * length:: METER_MILLIMETER_FACTOR ) ,
5765 )
5866 }
5967
68+ /// Create new area from floating point value in Square Millimetres
6069 pub fn from_square_millimetres ( square_millimetres : f64 ) -> Self {
6170 Self :: from_square_millimeters ( square_millimetres)
6271 }
6372
73+ /// Create new area from floating point value in Square Centimeters
6474 pub fn from_square_centimeters ( square_centimeters : f64 ) -> Self {
6575 Self :: from_square_meters (
6676 square_centimeters / ( length:: METER_CENTIMETER_FACTOR * length:: METER_CENTIMETER_FACTOR ) ,
6777 )
6878 }
6979
80+ /// Create new area from floating point value in Square Centimetres
7081 pub fn from_square_centimetres ( square_centimetres : f64 ) -> Self {
7182 Self :: from_square_centimeters ( square_centimetres)
7283 }
7384
85+ /// Create new area from floating point value in Square Decimeters
7486 pub fn from_square_decimeters ( square_decimeters : f64 ) -> Self {
7587 Self :: from_square_meters (
7688 square_decimeters / ( length:: METER_DECIMETER_FACTOR * length:: METER_DECIMETER_FACTOR ) ,
7789 )
7890 }
7991
92+ /// Create new area from floating point value in Square Decimetres
8093 pub fn from_square_decimetres ( square_decimetres : f64 ) -> Self {
8194 Self :: from_square_decimeters ( square_decimetres)
8295 }
8396
97+ /// Create new area from floating point value in Square Hectometers
8498 pub fn from_square_hectometers ( square_hectometers : f64 ) -> Self {
8599 Self :: from_square_meters (
86100 square_hectometers / ( length:: METER_HECTOMETER_FACTOR * length:: METER_HECTOMETER_FACTOR ) ,
87101 )
88102 }
89103
104+ /// Create new area from floating point value in Square Hectometres
90105 pub fn from_square_hectometres ( square_hectometres : f64 ) -> Self {
91106 Self :: from_square_hectometers ( square_hectometres)
92107 }
93108
109+ /// Create new area from floating point value in Hectares
94110 pub fn from_hectares ( hectares : f64 ) -> Self {
95111 Self :: from_square_hectometers ( hectares)
96112 }
97113
114+ /// Create new area from floating point value in Square Kilometers
98115 pub fn from_square_kilometers ( square_kilometers : f64 ) -> Self {
99116 Self :: from_square_meters (
100117 square_kilometers / ( length:: METER_KILOMETER_FACTOR * length:: METER_KILOMETER_FACTOR ) ,
101118 )
102119 }
103120
121+ /// Create new area from floating point value in Square Kilometres
104122 pub fn from_square_kilometres ( square_kilometres : f64 ) -> Self {
105123 Self :: from_square_kilometers ( square_kilometres)
106124 }
107125
108- // Inputs, imperial
126+ /// Create new area from floating point value in Square Inches
109127 pub fn from_square_inches ( square_inches : f64 ) -> Self {
110128 Self :: from_square_meters (
111129 square_inches / ( length:: METER_INCH_FACTOR * length:: METER_INCH_FACTOR ) ,
112130 )
113131 }
114132
133+ /// Create new area from floating point value in Square Feet
115134 pub fn from_square_feet ( square_feet : f64 ) -> Self {
116135 Self :: from_square_meters (
117136 square_feet / ( length:: METER_FEET_FACTOR * length:: METER_FEET_FACTOR ) ,
118137 )
119138 }
120139
140+ /// Create new area from floating point value in Square Yards
121141 pub fn from_square_yards ( square_yards : f64 ) -> Self {
122142 Self :: from_square_meters (
123143 square_yards / ( length:: METER_YARD_FACTOR * length:: METER_YARD_FACTOR ) ,
124144 )
125145 }
126146
147+ /// Create new area from floating point value in Acres
127148 pub fn from_acres ( acres : f64 ) -> Self {
128149 Self :: from_square_meters ( acres / SQUARE_METER_ACRE_FACTOR )
129150 }
130151
152+ /// Create new area from floating point value in Square Miles
131153 pub fn from_square_miles ( square_miles : f64 ) -> Self {
132154 Self :: from_square_meters (
133155 square_miles / ( length:: METER_MILE_FACTOR * length:: METER_MILE_FACTOR ) ,
134156 )
135157 }
136158
137- // Outputs, metric
159+ /// Convert this Area to a floating point value in Square Nanometers
138160 pub fn as_square_nanometers ( & self ) -> f64 {
139161 self . square_meters * ( length:: METER_NANOMETER_FACTOR * length:: METER_NANOMETER_FACTOR )
140162 }
141163
164+ /// Convert this Area to a floating point value in Square Nanometres
142165 pub fn as_square_nanometres ( & self ) -> f64 {
143166 self . as_square_nanometers ( )
144167 }
145168
169+ /// Convert this Area to a floating point value in Square Micrometers
146170 pub fn as_square_micrometers ( & self ) -> f64 {
147171 self . square_meters * ( length:: METER_MICROMETER_FACTOR * length:: METER_MICROMETER_FACTOR )
148172 }
149173
174+ /// Convert this Area to a floating point value in Square Micrometres
150175 pub fn as_square_micrometres ( & self ) -> f64 {
151176 self . as_square_micrometers ( )
152177 }
153178
179+ /// Convert this Area to a floating point value in Square Millimeters
154180 pub fn as_square_millimeters ( & self ) -> f64 {
155181 self . square_meters * ( length:: METER_MILLIMETER_FACTOR * length:: METER_MILLIMETER_FACTOR )
156182 }
157183
184+ /// Convert this Area to a floating point value in Square Millimetres
158185 pub fn as_square_millimetres ( & self ) -> f64 {
159186 self . as_square_millimeters ( )
160187 }
161188
189+ /// Convert this Area to a floating point value in Square Centimeters
162190 pub fn as_square_centimeters ( & self ) -> f64 {
163191 self . square_meters * ( length:: METER_CENTIMETER_FACTOR * length:: METER_CENTIMETER_FACTOR )
164192 }
165193
194+ /// Convert this Area to a floating point value in Square Centimetres
166195 pub fn as_square_centimetres ( & self ) -> f64 {
167196 self . as_square_centimeters ( )
168197 }
169198
199+ /// Convert this Area to a floating point value in Square Meters
170200 pub fn as_square_meters ( & self ) -> f64 {
171201 self . square_meters
172202 }
173203
204+ /// Convert this Area to a floating point value in Square Metres
174205 pub fn as_square_metres ( & self ) -> f64 {
175206 self . as_square_meters ( )
176207 }
177208
209+ /// Convert this Area to a floating point value in Square Decimeters
178210 pub fn as_square_decimeters ( & self ) -> f64 {
179211 self . square_meters * ( length:: METER_DECIMETER_FACTOR * length:: METER_DECIMETER_FACTOR )
180212 }
181213
214+ /// Convert this Area to a floating point value in Square Decimetres
182215 pub fn as_square_decimetres ( & self ) -> f64 {
183216 self . as_square_decimeters ( )
184217 }
185218
219+ /// Convert this Area to a floating point value in Square Hectometers
186220 pub fn as_square_hectometers ( & self ) -> f64 {
187221 self . square_meters * ( length:: METER_HECTOMETER_FACTOR * length:: METER_HECTOMETER_FACTOR )
188222 }
189223
224+ /// Convert this Area to a floating point value in Square Hectometres
190225 pub fn as_square_hectometres ( & self ) -> f64 {
191226 self . as_square_hectometers ( )
192227 }
193228
229+ /// Convert this Area to a floating point value in Hectares
194230 pub fn as_hectares ( & self ) -> f64 {
195231 self . as_square_hectometers ( )
196232 }
197233
234+ /// Convert this Area to a floating point value in Square Kilometers
198235 pub fn as_square_kilometers ( & self ) -> f64 {
199236 self . square_meters * ( length:: METER_KILOMETER_FACTOR * length:: METER_KILOMETER_FACTOR )
200237 }
201238
239+ /// Convert this Area to a floating point value in Square Kilometres
202240 pub fn as_square_kilometres ( & self ) -> f64 {
203241 self . as_square_kilometers ( )
204242 }
205243
206- // Outputs, imperial
244+ /// Convert this Area to a floating point value in Square Inches
207245 pub fn as_square_inches ( & self ) -> f64 {
208246 self . square_meters * ( length:: METER_INCH_FACTOR * length:: METER_INCH_FACTOR )
209247 }
210248
249+ /// Convert this Area to a floating point value in Square Feet
211250 pub fn as_square_feet ( & self ) -> f64 {
212251 self . square_meters * ( length:: METER_FEET_FACTOR * length:: METER_FEET_FACTOR )
213252 }
214253
254+ /// Convert this Area to a floating point value in Square Yards
215255 pub fn as_square_yards ( & self ) -> f64 {
216256 self . square_meters * ( length:: METER_YARD_FACTOR * length:: METER_YARD_FACTOR )
217257 }
218258
259+ /// Convert this Area to a floating point value in Acres
219260 pub fn as_acres ( & self ) -> f64 {
220261 self . square_meters * SQUARE_METER_ACRE_FACTOR
221262 }
222263
264+ /// Convert this Area to a floating point value in Square Miles
223265 pub fn as_square_miles ( & self ) -> f64 {
224266 self . square_meters * ( length:: METER_MILE_FACTOR * length:: METER_MILE_FACTOR )
225267 }
0 commit comments