-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
942 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright (c) Dmytro Kyshchenko. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
namespace xFunc.Maths.Expressions.Units.AreaUnits; | ||
|
||
/// <summary> | ||
/// Represents a length number. | ||
/// </summary> | ||
public class Area : Unit<AreaValue> | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="Area"/> class. | ||
/// </summary> | ||
/// <param name="value">A length value.</param> | ||
public Area(AreaValue value) | ||
: base(value) | ||
{ | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override TResult AnalyzeInternal<TResult>(IAnalyzer<TResult> analyzer) | ||
=> analyzer.Analyze(this); | ||
|
||
/// <inheritdoc /> | ||
protected override TResult AnalyzeInternal<TResult, TContext>( | ||
IAnalyzer<TResult, TContext> analyzer, | ||
TContext context) | ||
=> analyzer.Analyze(this, context); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
// Copyright (c) Dmytro Kyshchenko. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System.Diagnostics.CodeAnalysis; | ||
|
||
namespace xFunc.Maths.Expressions.Units.AreaUnits; | ||
|
||
/// <summary> | ||
/// Represents a area unit. | ||
/// </summary> | ||
public class AreaUnit : IEquatable<AreaUnit> | ||
{ | ||
/// <summary> | ||
/// The meter (m²) unit. | ||
/// </summary> | ||
public static readonly AreaUnit Meter = new AreaUnit(1.0, "m^2"); | ||
|
||
/// <summary> | ||
/// The millimeter (mm²) unit. | ||
/// </summary> | ||
public static readonly AreaUnit Millimeter = new AreaUnit(0.000001, "mm^2"); | ||
|
||
/// <summary> | ||
/// The centimeter (cm²) unit. | ||
/// </summary> | ||
public static readonly AreaUnit Centimeter = new AreaUnit(0.0001, "cm^2"); | ||
|
||
/// <summary> | ||
/// The kilometer (km²) unit. | ||
/// </summary> | ||
public static readonly AreaUnit Kilometer = new AreaUnit(1000000, "km^2"); | ||
|
||
/// <summary> | ||
/// The inch (in²) unit. | ||
/// </summary> | ||
public static readonly AreaUnit Inch = new AreaUnit(0.00064516, "in^2"); | ||
|
||
/// <summary> | ||
/// The foot (ft²) unit. | ||
/// </summary> | ||
public static readonly AreaUnit Foot = new AreaUnit(0.09290304, "ft^2"); | ||
|
||
/// <summary> | ||
/// The yard (yd²) unit. | ||
/// </summary> | ||
public static readonly AreaUnit Yard = new AreaUnit(0.83612736, "yd^2"); | ||
|
||
/// <summary> | ||
/// The mile (mi²) unit. | ||
/// </summary> | ||
public static readonly AreaUnit Mile = new AreaUnit(2589988.110336, "mi^2"); | ||
|
||
/// <summary> | ||
/// The hectare (ha) unit. | ||
/// </summary> | ||
public static readonly AreaUnit Hectare = new AreaUnit(10000.0, "ha"); | ||
|
||
/// <summary> | ||
/// The acre (ac) unit. | ||
/// </summary> | ||
public static readonly AreaUnit Acre = new AreaUnit(4046.8564224, "ac"); | ||
|
||
private AreaUnit(double factor, string unitName) | ||
{ | ||
Factor = factor; | ||
UnitName = unitName; | ||
} | ||
|
||
/// <summary> | ||
/// Determines whether two specified instances of <see cref="AreaValue"/> are equal. | ||
/// </summary> | ||
/// <param name="left">The first object to compare.</param> | ||
/// <param name="right">The second object to compare.</param> | ||
/// <returns><c>true</c> if <paramref name="left"/> is equal to <paramref name="right"/>; otherwise, <c>false</c>.</returns> | ||
public static bool operator ==(AreaUnit left, AreaUnit right) | ||
=> left.Equals(right); | ||
|
||
/// <summary> | ||
/// Determines whether two specified instances of <see cref="AreaValue"/> are equal. | ||
/// </summary> | ||
/// <param name="left">The first object to compare.</param> | ||
/// <param name="right">The second object to compare.</param> | ||
/// <returns><c>true</c> if <paramref name="left"/> is equal to <paramref name="right"/>; otherwise, <c>false</c>.</returns> | ||
public static bool operator !=(AreaUnit left, AreaUnit right) | ||
=> !left.Equals(right); | ||
|
||
/// <inheritdoc /> | ||
public bool Equals(AreaUnit other) | ||
=> Factor.Equals(other.Factor) && UnitName == other.UnitName; | ||
|
||
/// <inheritdoc /> | ||
public override bool Equals(object? obj) | ||
=> obj is AreaUnit other && Equals(other); | ||
|
||
/// <inheritdoc /> | ||
[ExcludeFromCodeCoverage] | ||
public override int GetHashCode() | ||
=> HashCode.Combine(Factor, UnitName); | ||
|
||
/// <inheritdoc /> | ||
public override string ToString() | ||
=> UnitName; | ||
|
||
/// <summary> | ||
/// Gets a factor of conversion from this unit to base unit. | ||
/// </summary> | ||
public double Factor { get; } | ||
|
||
/// <summary> | ||
/// Gets a short name of the unit. | ||
/// </summary> | ||
public string UnitName { get; } | ||
|
||
private static readonly Lazy<IDictionary<string, AreaUnit>> AllUnits | ||
= new Lazy<IDictionary<string, AreaUnit>>(GetUnits); | ||
|
||
private static IDictionary<string, AreaUnit> GetUnits() | ||
=> new Dictionary<string, AreaUnit>(StringComparer.InvariantCultureIgnoreCase) | ||
{ | ||
{ Meter.UnitName, Meter }, | ||
{ Millimeter.UnitName, Millimeter }, | ||
{ Centimeter.UnitName, Centimeter }, | ||
{ Kilometer.UnitName, Kilometer }, | ||
{ Inch.UnitName, Inch }, | ||
{ Foot.UnitName, Foot }, | ||
{ Yard.UnitName, Yard }, | ||
{ Mile.UnitName, Mile }, | ||
{ Acre.UnitName, Acre }, | ||
{ Hectare.UnitName, Hectare }, | ||
}; | ||
|
||
/// <summary> | ||
/// Gets all available unit names. | ||
/// </summary> | ||
public static IEnumerable<string> Names => AllUnits.Value.Keys; | ||
|
||
/// <summary> | ||
/// Gets all available units. | ||
/// </summary> | ||
[ExcludeFromCodeCoverage] | ||
public static IEnumerable<AreaUnit> Units => AllUnits.Value.Values; | ||
|
||
/// <summary> | ||
/// Gets a unit by name. | ||
/// </summary> | ||
/// <param name="name">The name of unit.</param> | ||
/// <param name="unit">When this method returns, the value associated with the specified name, if the unit is found; otherwise, the default value for the type of the value parameter. This parameter is passed uninitialized.</param> | ||
/// <returns><c>true</c> if area units contain an unit with the specified <paramref name="name"/>; otherwise, <c>false</c>.</returns> | ||
/// <exception cref="ArgumentNullException"><paramref name="name"/> is <c>null</c>.</exception> | ||
public static bool FromName(string name, out AreaUnit unit) | ||
{ | ||
if (string.IsNullOrWhiteSpace(name)) | ||
throw new ArgumentNullException(nameof(name)); | ||
|
||
return AllUnits.Value.TryGetValue(name, out unit); | ||
} | ||
} |
Oops, something went wrong.