Addition doesn’t use the expression logic, instead it is defined for a limited number of known types and their interrelationships. You can add integers to booleans, vectors to colours, but not complex numbers to colours.
A bunch of IGH_Goo
types in the core assembly implement the additional IGH_QuickCast
interface and make it more efficient for the arithmetic operator components to figure out which addition/multiplication/subtraction method to use and what the type of the result is.
You cannot add a new IGH_QuickCast
type, as there is an enumeration listing all known types which cannot be extended.
If your goo however contains data that is just like one of the quick cast types, then I guess you can implement the interface and return whatever is inside your GH_Variant
as a boolean, integer, double, complex, vector, colour, …
Here’s the interface as defined in the Grasshopper source:
''' <summary>
''' IGH_QuickCast allows certain components to speed up type detection for inputs.
''' This interface is a Grasshopper core interface only, do not implement it. Do not use it.
''' </summary>
''' <exclude/>
Public Interface IGH_QuickCast
''' <summary>
''' Gets the QuickCast type for this instance.
''' </summary>
<Browsable(False), EditorBrowsable(EditorBrowsableState.Never)> _
ReadOnly Property QC_Type As GH_QuickCastType
<Browsable(False), EditorBrowsable(EditorBrowsableState.Never)> _
Function QC_Distance(other As IGH_QuickCast) As Double
<Browsable(False), EditorBrowsable(EditorBrowsableState.Never)> _
Function QC_Hash() As Int32
<Browsable(False), EditorBrowsable(EditorBrowsableState.Never)> _
Function QC_Bool() As Boolean
<Browsable(False), EditorBrowsable(EditorBrowsableState.Never)> _
Function QC_Int() As Int32
<Browsable(False), EditorBrowsable(EditorBrowsableState.Never)> _
Function QC_Num() As Double
<Browsable(False), EditorBrowsable(EditorBrowsableState.Never)> _
Function QC_Text() As String
<Browsable(False), EditorBrowsable(EditorBrowsableState.Never)> _
Function QC_Col() As Color
<Browsable(False), EditorBrowsable(EditorBrowsableState.Never)> _
Function QC_Pt() As Point3d
<Browsable(False), EditorBrowsable(EditorBrowsableState.Never)> _
Function QC_Vec() As Vector3d
<Browsable(False), EditorBrowsable(EditorBrowsableState.Never)> _
Function QC_Complex() As Complex
<Browsable(False), EditorBrowsable(EditorBrowsableState.Never)> _
Function QC_Matrix() As Matrix
<Browsable(False), EditorBrowsable(EditorBrowsableState.Never)> _
Function QC_Interval() As Interval
<Browsable(False), EditorBrowsable(EditorBrowsableState.Never)> _
Function QC_CompareTo(other As IGH_QuickCast) As Int32
End Interface
The problem lies in that case where your GH_Variant
doesn’t represent one of the quick cast predefined types. There’s no lee-way build into the mechanism for ‘unknown’ or ‘other’ types. I guess you can always say it’s text
in that case and just return a string.