diff --git a/UnitsNet.Tests/CustomCode/ForceTests.cs b/UnitsNet.Tests/CustomCode/ForceTests.cs index fb348634a8..bbed182da0 100644 --- a/UnitsNet.Tests/CustomCode/ForceTests.cs +++ b/UnitsNet.Tests/CustomCode/ForceTests.cs @@ -1,16 +1,16 @@ // Copyright (c) 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). // https://github.com/angularsen/UnitsNet -// +// // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: -// +// // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. -// +// // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -51,26 +51,19 @@ public void ForceDividedByAreaEqualsPressure() } [Fact] - public void PressureByAreaEqualsForceUsingArea() + public void PressureByAreaEqualsForce() { Force force = Force.FromPressureByArea(Pressure.FromNewtonsPerSquareMeter(5), Area.FromSquareMeters(7)); Assert.Equal(force, Force.FromNewtons(35)); } - [Fact] - public void PressureByAreaEqualsForceUsingLength2D() - { - var force = Force.FromPressureByArea(Pressure.FromNewtonsPerSquareMeter(6), Length2d.FromMeters(5, 2)); - Assert.Equal(force, Force.FromNewtons(60)); - } - [Fact] public void ForceDividedByMassEqualsAcceleration() { Acceleration acceleration = Force.FromNewtons(27)/Mass.FromKilograms(9); Assert.Equal(acceleration, Acceleration.FromMetersPerSecondSquared(3)); } - + [Fact] public void ForceDividedByAccelerationEqualsMass() { @@ -85,12 +78,6 @@ public void ForceDividedByLengthEqualsForcePerLength() Assert.Equal(forcePerLength, ForcePerLength.FromNewtonsPerMeter(4)); } - [Fact] - public void MassByAccelerationEqualsForceUsingDouble() - { - var force = Force.FromMassByAcceleration(Mass.FromKilograms(9), 3); - Assert.Equal(force, Force.FromNewtons(27)); - } [Fact] public void MassByAccelerationEqualsForce() { diff --git a/UnitsNet.Tests/CustomCode/Length2dTests.cs b/UnitsNet.Tests/CustomCode/Length2dTests.cs deleted file mode 100644 index 39cda56ef1..0000000000 --- a/UnitsNet.Tests/CustomCode/Length2dTests.cs +++ /dev/null @@ -1,146 +0,0 @@ -// Copyright (c) 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). -// https://github.com/angularsen/UnitsNet -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -using Xunit; - -namespace UnitsNet.Tests.CustomCode -{ -// ReSharper disable once InconsistentNaming - public class Length2dTests - { - private const double Delta = 1E-5; - - private static void AssertAreEqual(Vector2 expected, Vector2 actual, double delta) - { - AssertEx.EqualTolerance(expected.X, actual.X, delta); - AssertEx.EqualTolerance(expected.Y, actual.Y, delta); - } - - [Fact] - public void ArithmeticOperators() - { - Length2d v = Length2d.FromMeters(1, 2); - AssertEx.EqualTolerance(-1, -v.Meters.X, Delta); - AssertEx.EqualTolerance(-2, -v.Meters.Y, Delta); - AssertEx.EqualTolerance(2, (Length2d.FromMeters(3, 3) - v).Meters.X, Delta); - AssertEx.EqualTolerance(1, (Length2d.FromMeters(3, 3) - v).Meters.Y, Delta); - AssertEx.EqualTolerance(2, (v + v).Meters.X, Delta); - AssertEx.EqualTolerance(4, (v + v).Meters.Y, Delta); - AssertEx.EqualTolerance(10, (v*10).Meters.X, Delta); - AssertEx.EqualTolerance(20, (v*10).Meters.Y, Delta); - AssertEx.EqualTolerance(10, (10*v).Meters.X, Delta); - AssertEx.EqualTolerance(20, (10*v).Meters.Y, Delta); - AssertEx.EqualTolerance(2, (Length2d.FromMeters(2, 2)*v).Meters.X, Delta); - AssertEx.EqualTolerance(4, (Length2d.FromMeters(2, 2)*v).Meters.Y, Delta); - AssertEx.EqualTolerance(2, (Length2d.FromMeters(10, 20)/5).Meters.X, Delta); - AssertEx.EqualTolerance(4, (Length2d.FromMeters(10, 20)/5).Meters.Y, Delta); - AssertEx.EqualTolerance(2, (Length2d.FromMeters(10, 20)/Length2d.FromMeters(5, 5)).X, Delta); - AssertEx.EqualTolerance(4, (Length2d.FromMeters(10, 20)/Length2d.FromMeters(5, 5)).Y, Delta); - } - - [Fact] - public void DistanceUnitsRoundTrip() - { - Length meter = Length.FromMeters(1); - - AssertEx.EqualTolerance(1, Length.FromKilometers(meter.Kilometers).Meters, Delta); - AssertEx.EqualTolerance(1, Length.FromMeters(meter.Meters).Meters, Delta); - AssertEx.EqualTolerance(1, Length.FromDecimeters(meter.Decimeters).Meters, Delta); - AssertEx.EqualTolerance(1, Length.FromCentimeters(meter.Centimeters).Meters, Delta); - AssertEx.EqualTolerance(1, Length.FromMillimeters(meter.Millimeters).Meters, Delta); - AssertEx.EqualTolerance(1, Length.FromMicrometers(meter.Micrometers).Meters, Delta); - AssertEx.EqualTolerance(1, Length.FromNanometers(meter.Nanometers).Meters, Delta); - } - - [Fact] - public void EqualityOperators() - { - Length2d a = Length2d.FromMeters(1, 2); - Length2d b = Length2d.FromMeters(2, 1); - - // ReSharper disable EqualExpressionComparison - // Disable build warning: Comparison made to same variable; did you mean to compare something else? -#pragma warning disable 1718 - Assert.True(a == a); - Assert.True(a != b); - - Assert.False(a == b); - Assert.False(a != a); -#pragma warning restore 1718 - // ReSharper restore EqualExpressionComparison - } - - [Fact] - public void EqualsIsImplemented() - { - Length2d v = Length2d.FromMeters(1, 2); - Assert.True(v.Equals(Length2d.FromMeters(1, 2))); - Assert.False(v.Equals(Length2d.Zero)); - } - - [Fact] - public void EqualsReturnsFalseOnNull() - { - Length2d newton = Length2d.FromMeters(1, 2); - Assert.False(newton.Equals(null)); - } - - [Fact] - public void EqualsReturnsFalseOnTypeMismatch() - { - Length2d newton = Length2d.FromMeters(1, 2); - Assert.False(newton.Equals(new object())); - } - - [Fact] - public void MetersToDistanceUnits() - { - Length2d meter = Length2d.FromMeters(1, 1); - - AssertAreEqual(new Vector2(1), meter.Meters, Delta); - AssertAreEqual(new Vector2(1E2), meter.Centimeters, Delta); - AssertAreEqual(new Vector2(1E3), meter.Millimeters, Delta); - AssertAreEqual(new Vector2(1E-3), meter.Kilometers, Delta); - AssertAreEqual(new Vector2(1), meter.Meters, Delta); - AssertAreEqual(new Vector2(1E1), meter.Decimeters, Delta); - AssertAreEqual(new Vector2(1E2), meter.Centimeters, Delta); - AssertAreEqual(new Vector2(1E3), meter.Millimeters, Delta); - AssertAreEqual(new Vector2(1E6), meter.Micrometers, Delta); - AssertAreEqual(new Vector2(1E9), meter.Nanometers, Delta); - - AssertEx.EqualTolerance(0.000621371, meter.Miles.X, Delta); - AssertEx.EqualTolerance(0.000621371, meter.Miles.Y, Delta); - AssertEx.EqualTolerance(1.09361, meter.Yards.X, Delta); - AssertEx.EqualTolerance(1.09361, meter.Yards.Y, Delta); - AssertEx.EqualTolerance(3.28084, meter.Feet.X, Delta); - AssertEx.EqualTolerance(3.28084, meter.Feet.Y, Delta); - AssertEx.EqualTolerance(39.37007874, meter.Inches.X, Delta); - AssertEx.EqualTolerance(39.37007874, meter.Inches.Y, Delta); - } - - [Fact] - public void VectorLength() - { - var v = new Length2d(3, 4); - Assert.Equal(5, v.Length.Meters); - } - } -} diff --git a/UnitsNet/CustomCode/Quantities/Force.extra.cs b/UnitsNet/CustomCode/Quantities/Force.extra.cs index 925f36002d..f88a21dfec 100644 --- a/UnitsNet/CustomCode/Quantities/Force.extra.cs +++ b/UnitsNet/CustomCode/Quantities/Force.extra.cs @@ -1,16 +1,16 @@ // Copyright (c) 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). // https://github.com/angularsen/UnitsNet -// +// // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: -// +// // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. -// +// // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -66,21 +66,6 @@ public partial struct Force } #endif - // Method overloads with same number of argumnets not supported in Universal Windows Platform (WinRT Components) -#if !WINDOWS_UWP - public static Force FromPressureByArea(Pressure p, Length2d area) - { - double metersSquared = area.Meters.X * area.Meters.Y; - double newtons = p.Pascals * metersSquared; - return new Force(newtons, ForceUnit.Newton); - } - - public static Force FromMassByAcceleration(Mass mass, double metersPerSecondSquared) - { - return new Force(mass.Kilograms * metersPerSecondSquared, ForceUnit.Newton); - } -#endif - public static Force FromPressureByArea(Pressure p, Area area) { double newtons = p.Pascals * area.SquareMeters; diff --git a/UnitsNet/Length2d.cs b/UnitsNet/Length2d.cs deleted file mode 100644 index dd43225dca..0000000000 --- a/UnitsNet/Length2d.cs +++ /dev/null @@ -1,261 +0,0 @@ -// Copyright (c) 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). -// https://github.com/angularsen/UnitsNet -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -#if !WINDOWS_UWP -using System; -using System.Collections.Generic; -using UnitsNet.Units; - -#endif - -namespace UnitsNet -{ - /// - /// A class for representing position in two dimensions. - /// -#if WINDOWS_UWP - public struct Length2d - { - /// - /// Returns a point represented in meters. - /// - public Vector2 Meters; - } -#else - // ReSharper disable once InconsistentNaming - public struct Length2d : IEquatable - { - /// - /// Returns a point represented in meters. - /// - public readonly Vector2 Meters; - - /// - /// Creates an instance based on X and Y in implicitly defined SI units. - /// - public Length2d(double xMeters, double yMeters) - { - Meters = new Vector2(xMeters, yMeters); - } - - public Length2d(Length x, Length y) : this(x.Meters, y.Meters) - { - } - - #region Static - - public static Length GetDistance(Length2d a, Length2d b) - { - Vector2 d = (a - b).Meters; - return Length.FromMeters(Math.Sqrt(d.X*d.X + d.Y*d.Y)); - } - - #endregion - - #region Public properties - - public Length Length - { - get - { - double x = Meters.X; - double y = Meters.Y; - return Length.FromMeters(Math.Sqrt(x*x + y*y)); - } - } - - public Length X => Length.FromMeters(Meters.X); - - public Length Y => Length.FromMeters(Meters.Y); - - public Vector2 Miles => new Vector2(X.Miles, Y.Miles); - - public Vector2 Yards => new Vector2(X.Yards, Y.Yards); - - public Vector2 Feet => new Vector2(X.Feet, Y.Feet); - - public Vector2 Inches => new Vector2(X.Inches, Y.Inches); - - public Vector2 Kilometers => new Vector2(X.Kilometers, Y.Kilometers); - - public Vector2 Decimeters => new Vector2(X.Decimeters, Y.Decimeters); - - /// - /// Returns a point represented in centimeters. - /// - public Vector2 Centimeters => new Vector2(Meters.X*1E2, Meters.Y*1E2); - - /// - /// Returns a point represented in millimeters. - /// - public Vector2 Millimeters => new Vector2(Meters.X*1E3, Meters.Y*1E3); - - public Vector2 Micrometers => new Vector2(X.Micrometers, Y.Micrometers); - - public Vector2 Nanometers => new Vector2(X.Nanometers, Y.Nanometers); - - #endregion - - #region Static methods - - public static Length2d Zero => new Length2d(); - - public static Length2d FromMeters(double xMeters, double yMeters) - { - return new Length2d(xMeters, yMeters); - } - - public static Length2d FromCentimeters(double xCentimeters, double yCentimeters) - { - return new Length2d(xCentimeters*1E-2, yCentimeters*1E-2); - } - - public static Length2d FromMillimeters(double xMillimeters, double yMillimeters) - { - return new Length2d(xMillimeters*1E-3, yMillimeters*1E-3); - } - - #endregion - - #region Arithmetic operators - - public static Length2d operator -(Length2d right) - { - return FromMeters(-right.X.Meters, -right.Y.Meters); - } - - public static Length2d operator +(Length2d left, Length2d right) - { - double x = left.X.Meters + right.X.Meters; - double y = left.Y.Meters + right.Y.Meters; - return FromMeters(x, y); - } - - public static Length2d operator -(Length2d left, Length2d right) - { - double x = left.X.Meters - right.X.Meters; - double y = left.Y.Meters - right.Y.Meters; - return FromMeters(x, y); - } - - public static Length2d operator *(double left, Length2d right) - { - double x = left*right.X.Meters; - double y = left*right.Y.Meters; - return FromMeters(x, y); - } - - public static Length2d operator *(Length2d left, double right) - { - double x = left.X.Meters*right; - double y = left.Y.Meters*right; - return FromMeters(x, y); - } - - public static Length2d operator *(Length2d left, Length2d right) - { - double x = left.X.Meters*right.X.Meters; - double y = left.Y.Meters*right.Y.Meters; - return FromMeters(x, y); - } - - public static Length2d operator /(Length2d left, double right) - { - double x = left.X.Meters/right; - double y = left.Y.Meters/right; - return FromMeters(x, y); - } - - public static Vector2 operator /(Length2d left, Length2d right) - { - double x = left.X.Meters/right.X.Meters; - double y = left.Y.Meters/right.Y.Meters; - return new Vector2(x, y); - } - - #endregion - - #region Public methods - - public override string ToString() - { - return - $"({X.Meters:0.##}, {Y.Meters:0.##}) {UnitSystem.Default.GetDefaultAbbreviation(LengthUnit.Meter)}"; - } - - public Length DistanceTo(Length2d other) - { - double dx = X.Meters - other.X.Meters; - double dy = Y.Meters - other.Y.Meters; - double distance = Math.Sqrt(dx*dx + dy*dy); - - return Length.FromMeters(distance); - } - - #endregion - - #region Equality - - private static IEqualityComparer MetersComparer { get; } = new MetersEqualityComparer(); - - public bool Equals(Length2d other) - { - return MetersComparer.Equals(this, other); - } - - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is Length2d && Equals((Length2d) obj); - } - - public override int GetHashCode() - { - return Meters.GetHashCode(); - } - - public static bool operator !=(Length2d left, Length2d right) - { - return left.Meters != right.Meters; - } - - public static bool operator ==(Length2d left, Length2d right) - { - return left.Meters == right.Meters; - } - - private sealed class MetersEqualityComparer : IEqualityComparer - { - public bool Equals(Length2d x, Length2d y) - { - return x.Meters.Equals(y.Meters); - } - - public int GetHashCode(Length2d obj) - { - return obj.Meters.GetHashCode(); - } - } - - #endregion - } -#endif -}