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 TypeVector3MathDivideNumber : TypeVector3
{
[SerializeField] private GetVector3 m_Vector = new GetVector3();
[SerializeField] private GetNumber m_Scalar = new GetNumber(1f);
public override Vector3 GetPreview(GameObject source) => Divide(
this.m_Vector.GetPreview(source),
this.m_Scalar.GetPreview(source)
);
public override Vector3 Get(Args args) => Divide(this.m_Vector.Get(args), this.m_Scalar.Get(args));
private static Vector3 Divide(Vector3 vector, double scalar)
{
return Math.Abs(scalar) <= double.Epsilon ? Vector3.zero : vector / (float) scalar;
}
public override string ToString()
{
return $"{this.m_Vector} / {this.m_Scalar}";
}
protected override SubscriptionMode Subscription => SubscriptionMode.OnChange;
}
}