public object Multiply(object x, object y) { if (x == null) { throw new ArgumentNullException(nameof(x)); } if (y == null) { throw new ArgumentNullException(nameof(y)); } if (x is KalkVector vx && y is KalkVector vy) { return(KalkVector.Dot(vx, vy)); } if (x is KalkVector vx1 && y is KalkMatrix my) { return(KalkMatrix.Multiply(vx1, my)); } if (x is KalkMatrix mx && y is KalkVector vy1) { return(KalkMatrix.Multiply(mx, vy1)); } if (x is KalkMatrix mx1 && y is KalkMatrix my2) { return(KalkMatrix.Multiply(mx1, my2)); } throw new ArgumentException($"Unsupported type for matrix multiplication. The combination of {Engine.GetTypeName(x)} * {Engine.GetTypeName(y)} is not supported.", nameof(x)); }
public object Length(object x) { if (x == null) { throw new ArgumentNullException(nameof(x)); } if (_mathModule == null) { throw new InvalidOperationException($"The module {Name} is not initialized."); } if (x is KalkVector v) { return(_mathModule.Sqrt(new KalkDoubleValue(KalkVector.Dot(v, v)))); } return(_mathModule.Abs(new KalkCompositeValue(x))); }
public object Dot(object x, object y) { if (x is KalkVector vx) { if (y is KalkVector vy) { return(KalkVector.Dot(vx, vy)); } return(KalkVector.Dot(vx, vx.FromValue(Engine.ToObject(1, y, vx.ElementType)))); } else if (y is KalkVector vy) { return(KalkVector.Dot(vy.FromValue(Engine.ToObject(1, x, vy.ElementType)), vy)); } return(ScriptBinaryExpression.Evaluate(Engine, Engine.CurrentSpan, ScriptBinaryOperator.Multiply, x, y)); }