internal Direction( IAlgebraicNumberCalculator <TAlgebraicNumber> calculator, TAlgebraicNumber x, TAlgebraicNumber y) { if (calculator is null) { throw new ArgumentNullException(nameof(calculator)); } if (x is null) { throw new ArgumentNullException(nameof(x)); } if (y is null) { throw new ArgumentNullException(nameof(y)); } if (calculator.IsZero(x) && calculator.IsZero(y)) { throw new ArgumentException( "Both components of the direction cannot be simultaneously zero.", nameof(y)); } _calculator = calculator; X = x; Y = y; }
public static bool AreEqual <TAlgebraicNumber>( this IAlgebraicNumberCalculator <TAlgebraicNumber> calculator, TAlgebraicNumber number1, TAlgebraicNumber number2) { if (calculator is null) { throw new ArgumentNullException(nameof(calculator)); } return(calculator.IsZero(calculator.Subtract(number2, number1))); }
/// <inheritdoc /> public override bool Equals(object?other) { if (other is null) { return(false); } if (ReferenceEquals(this, other)) { return(true); } if (other is Direction <TAlgebraicNumber> direction) { return(_calculator.IsZero(Determinant(direction)) && _calculator.IsStrictlyPositive( _calculator.Add( _calculator.Multiply(X, direction.X), _calculator.Multiply(Y, direction.Y)))); } return(false); }