Divide#
Math / Divide Number
Can Read
Cannot Write
Description#
Divides all components of a vector by a scalar value
Parameters#
| Name | Description |
|---|---|
| Vector | The vector that is divided |
| Scalar | The value every component is divided by. Zero returns a zero vector |
Code#
using System;
using UnityEngine;
using VisualScript.Icons;
namespace VisualScript.Runtime
{
[Get]
[Title("Divide")]
[Category("Math/Divide", "Number")]
[Description("Divides all components of a vector by a scalar value")]
[Image(typeof(IconDivideCircle), ColorTheme.Type.Yellow)]
[Parameter("Vector", "The vector that is divided")]
[Parameter("Scalar", "The value every component is divided by. Zero returns a zero vector")]
[Keywords("Vector", "Divide", "Quotient", "Split", "Half")]
[Serializable]
public class TypeVector2MathDivideNumber : TypeVector2
{
[SerializeField] private GetVector2 m_Vector = new GetVector2();
[SerializeField] private GetNumber m_Scalar = new GetNumber(1f);
public override Vector2 GetPreview(GameObject source) => Divide(
this.m_Vector.GetPreview(source),
this.m_Scalar.GetPreview(source)
);
public override Vector2 Get(Args args) => Divide(this.m_Vector.Get(args), this.m_Scalar.Get(args));
private static Vector2 Divide(Vector2 vector, double scalar)
{
return Math.Abs(scalar) <= double.Epsilon ? Vector2.zero : vector / (float) scalar;
}
public override string ToString()
{
return $"{this.m_Vector} / {this.m_Scalar}";
}
protected override SubscriptionMode Subscription => SubscriptionMode.OnChange;
}
}