View Javadoc
1   package org.djunits.unit;
2   
3   import org.djunits.unit.quantity.Quantity;
4   import org.djunits.unit.scale.IdentityScale;
5   import org.djunits.unit.si.SIPrefixes;
6   import org.djunits.unit.unitsystem.UnitSystem;
7   
8   /**
9    * AreaUnit defines a number of common units for areas.
10   * <p>
11   * Copyright (c) 2015-2020 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
12   * BSD-style license. See <a href="https://djunits.org/docs/license.html">DJUNITS License</a>.
13   * <p>
14   * @author <a href="https://www.tudelft.nl/averbraeck">Alexander Verbraeck</a>
15   */
16  public class AreaUnit extends Unit<AreaUnit>
17  {
18      /** */
19      private static final long serialVersionUID = 20140607L;
20  
21      /** The base, with "m2" as the SI signature. */
22      public static final Quantity<AreaUnit> BASE = new Quantity<>("Area", "m2");
23  
24      /** The SI unit for area is m^2. */
25      public static final AreaUnit SI =
26              new AreaUnit().build(new Unit.Builder<AreaUnit>().setQuantity(BASE).setId("m^2").setName("square meter")
27                      .setUnitSystem(UnitSystem.SI_DERIVED).setSiPrefixes(SIPrefixes.UNIT, 2.0).setScale(IdentityScale.SCALE));
28  
29      /** m^2. */
30      public static final AreaUnit SQUARE_METER = SI;
31  
32      /** mm^2. */
33      public static final AreaUnit SQUARE_MILLIMETER = SQUARE_METER.deriveLinear(1.0E-6, "mm^2", "square millimeter");
34  
35      /** cm^2. */
36      public static final AreaUnit SQUARE_CENTIMETER = SQUARE_METER.deriveLinear(1.0E-4, "cm^2", "square centimeter");
37  
38      /** dm^2. */
39      public static final AreaUnit SQUARE_DECIMETER = SQUARE_METER.deriveLinear(1.0E-2, "dm^2", "square decimeter");
40  
41      /** dam^2. */
42      public static final AreaUnit SQUARE_DECAMETER = SQUARE_METER.deriveLinear(1.0E2, "dam^2", "square decameter");
43  
44      /** hm^2. */
45      public static final AreaUnit SQUARE_HECTOMETER = SQUARE_METER.deriveLinear(1.0E4, "hm^2", "square hectometer");
46  
47      /** km^2. */
48      public static final AreaUnit SQUARE_KILOMETER = SQUARE_METER.deriveLinear(1.0E6, "km^2", "square kilometer");
49  
50      /** centiare. */
51      public static final AreaUnit CENTIARE = SQUARE_METER.deriveLinear(1.0, "ca", "centiare", UnitSystem.OTHER);
52  
53      /** are. */
54      public static final AreaUnit ARE = CENTIARE.deriveLinear(100.0, "a", "are");
55  
56      /** hectare. */
57      public static final AreaUnit HECTARE = ARE.deriveLinear(100.0, "ha", "hectare");
58  
59      /** mile^2. */
60      public static final AreaUnit SQUARE_MILE =
61              SQUARE_METER.deriveLinear(sqLength(LengthUnit.MILE), "mi^2", "square mile", UnitSystem.IMPERIAL);
62  
63      /** Nautical mile^2. */
64      public static final AreaUnit SQUARE_NAUTICAL_MILE =
65              SQUARE_METER.deriveLinear(sqLength(LengthUnit.NAUTICAL_MILE), "NM^2", "square Nautical Mile", UnitSystem.OTHER);
66  
67      /** ft^2. */
68      public static final AreaUnit SQUARE_FOOT =
69              SQUARE_METER.deriveLinear(sqLength(LengthUnit.FOOT), "ft^2", "square foot", UnitSystem.IMPERIAL);
70  
71      /** in^2. */
72      public static final AreaUnit SQUARE_INCH =
73              SQUARE_METER.deriveLinear(sqLength(LengthUnit.INCH), "in^2", "square inch", UnitSystem.IMPERIAL);
74  
75      /** yd^2. */
76      public static final AreaUnit SQUARE_YARD =
77              SQUARE_METER.deriveLinear(sqLength(LengthUnit.YARD), "yd^2", "square yard", UnitSystem.IMPERIAL);
78  
79      /** acre (international) defined as 1/640 square mile or 4840 square yards. */
80      public static final AreaUnit ACRE = SQUARE_MILE.deriveLinear(1.0 / 640.0, "ac", "acre", UnitSystem.IMPERIAL);
81  
82      /**
83       * Calculate the conversion factor for a "squared" length.
84       * @param lu LengthUnit; the LengthUnit to use as the base
85       * @return double; the conversion factor
86       */
87      private static double sqLength(final LengthUnit lu)
88      {
89          double factor = lu.getScale().toStandardUnit(1.0);
90          return factor * factor;
91      }
92  
93  }