Ejemplo n.º 1
0
def test_graph_ecs_node_wrap():
    wrap_cases = [
        ["w", GraphNode(node=wrap_const("w"))],
        [wrap_const(1), GraphNode(node=wrap_const(1))],
        [GraphNode(node=wrap_const(True)),
         GraphNode(node=wrap_const(True))],
    ]

    for val, expected in wrap_cases:
        assert GraphNode.wrap(val) == expected
Ejemplo n.º 2
0
    def random(self, low: Any, high: Any) -> GraphNode:
        """Creates a Random Node that evaluates to a random float in range [`low`,`high`]

        Args:
            low: Expression that evaluates to the lower bound of the random number generated (inclusive).
            high: Expression that evaluates to the upper bound of the random number generated (inclusive).

        Returns:
            Random Graph Node that evaluates to a random float in range [`low`,`high`]
        """
        low, high = GraphNode.wrap(low), GraphNode.wrap(high)
        return GraphNode(node=Node(
            random_op=Node.Random(low=low.node, high=high.node)))
Ejemplo n.º 3
0
def test_graph_ecs_component_get_attr_preserve_set_graph():
    entity_id = 1
    position = GraphComponent.from_def(entity_id, Position)

    # check that getting an attribute from a component preserves
    # any graph that has already being built by set_attr()
    position.x = 2

    pos_x = position.x
    expected_node = GraphNode.wrap(2)
    assert to_yaml_proto(pos_x.node) == to_yaml_proto(
        expected_node.node)  # type: ignore
Ejemplo n.º 4
0
    def switch(self, condition: Any, true: Any, false: Any) -> GraphNode:
        """Creates a conditional Switch Node that evaluates based on condition.

        The switch evalutes to `true` if the `condition` is true, `false` otherwise.

        Args:
            condition: Defines the condition. Should evaluate to true or false.
            true: Switch Node evaluates to this expression if `condition` evaluates to true.
            false: Switch Node evaluates to this expression if `condition` evaluates to false.
        Return:
            Switch Node Graph Node that evaluates based on the condition Node.
        """
        condition, true, false = (
            GraphNode.wrap(condition),
            GraphNode.wrap(true),
            GraphNode.wrap(false),
        )
        return GraphNode.wrap(
            Node(switch_op=Node.Switch(
                condition_node=condition.node,
                true_node=true.node,
                false_node=false.node,
            )))
Ejemplo n.º 5
0
 def arctan(self, x: Any) -> GraphNode:
     x = GraphNode.wrap(x)
     return GraphNode(node=Node(arctan_op=Node.ArcTan(x=x.node)))
Ejemplo n.º 6
0
 def tan(self, x: Any) -> GraphNode:
     x = GraphNode.wrap(x)
     return GraphNode(node=Node(tan_op=Node.Tan(x=x.node)))
Ejemplo n.º 7
0
 def arccos(self, x: Any) -> GraphNode:
     x = GraphNode.wrap(x)
     return GraphNode(node=Node(arccos_op=Node.ArcCos(x=x.node)))
Ejemplo n.º 8
0
 def cos(self, x: Any) -> GraphNode:
     x = GraphNode.wrap(x)
     return GraphNode(node=Node(cos_op=Node.Cos(x=x.node)))
Ejemplo n.º 9
0
 def sin(self, x: Any) -> GraphNode:
     x = GraphNode.wrap(x)
     return GraphNode(node=Node(sin_op=Node.Sin(x=x.node)))
Ejemplo n.º 10
0
 def mod(self, x: Any, y: Any) -> GraphNode:
     x, y = GraphNode.wrap(x), GraphNode.wrap(y)
     return GraphNode(node=Node(mod_op=Node.Mod(x=x.node, y=y.node)))
Ejemplo n.º 11
0
 def pow(self, x: Any, y: Any) -> GraphNode:
     x, y = GraphNode.wrap(x), GraphNode.wrap(y)
     return GraphNode(node=Node(pow_op=Node.Pow(x=x.node, y=y.node)))
Ejemplo n.º 12
0
 def ceil(self, x: Any) -> GraphNode:
     x = GraphNode.wrap(x)
     return GraphNode(node=Node(ceil_op=Node.Ceil(x=x.node)))
Ejemplo n.º 13
0
 def floor(self, x: Any) -> GraphNode:
     x = GraphNode.wrap(x)
     return GraphNode(node=Node(floor_op=Node.Floor(x=x.node)))
Ejemplo n.º 14
0
 def abs(self, x: Any) -> GraphNode:
     x = GraphNode.wrap(x)
     return GraphNode(node=Node(abs_op=Node.Abs(x=x)))
Ejemplo n.º 15
0
 def min(self, x: Any, y: Any) -> GraphNode:
     x, y = GraphNode.wrap(x), GraphNode.wrap(y)
     return GraphNode(node=Node(min_op=Node.Min(x=x.node, y=y.node)))
Ejemplo n.º 16
0
 def max(self, x: Any, y: Any) -> GraphNode:
     x, y = GraphNode.wrap(x), GraphNode.wrap(y)
     return GraphNode(node=Node(max_op=Node.Max(x=x.node, y=y.node)))