内置 Godot 类型的运算符在哪里定义?

Where are operators for built-in Godot types defined?

许多内置的 Godot 类型(Vector2、Rect2 等)支持未随类型一起记录的运算符(+/-/* 等)。在哪里可以找到有关所有类型支持的运算符及其语义的信息?

如果没有可用的文档,在 Godot 源代码的何处可以找到这些运算符的绑定?

我现在感兴趣的具体情况是将 Rect2 转换为 bool 作为 if 语句的一部分,即,

func my_func(area: Rect2):
    if area:
        # When do I get here?
        # Is this equivalent to if !area.has_no_area()?

Where can I find information about the supported operators and their semantics for all types?

If there is no documentation available, where in the Godot source code can the bindings for these operators be found?

对于 Godot 3.x,唯一完整的规范源是 Variant 的源代码。文件 variant_op.cpp 更准确。

但是,Godot 4.0 的文档已经在 class 页上包含了运算符。


The specific case I am interested in right now is converting a Rect2 to bool as part of an if statement, i.e.,

func my_func(area: Rect2):
    if area:
        # When do I get here?
        # Is this equivalent to if !area.has_no_area()?

注意:这不是运算符。

此处使用的布尔值转换由 booleanize method, which delegate to is_zero 处理(如在归零内存中)。通常,未初始​​化的变量会转换为 false。

对于 Rect2 这意味着当位置为零 ((0,0)) 且大小为零 ((0,0)) 时,Rect2 将转换为 false,任何其他转换为真。