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
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)))
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
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, )))
def arctan(self, x: Any) -> GraphNode: x = GraphNode.wrap(x) return GraphNode(node=Node(arctan_op=Node.ArcTan(x=x.node)))
def tan(self, x: Any) -> GraphNode: x = GraphNode.wrap(x) return GraphNode(node=Node(tan_op=Node.Tan(x=x.node)))
def arccos(self, x: Any) -> GraphNode: x = GraphNode.wrap(x) return GraphNode(node=Node(arccos_op=Node.ArcCos(x=x.node)))
def cos(self, x: Any) -> GraphNode: x = GraphNode.wrap(x) return GraphNode(node=Node(cos_op=Node.Cos(x=x.node)))
def sin(self, x: Any) -> GraphNode: x = GraphNode.wrap(x) return GraphNode(node=Node(sin_op=Node.Sin(x=x.node)))
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)))
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)))
def ceil(self, x: Any) -> GraphNode: x = GraphNode.wrap(x) return GraphNode(node=Node(ceil_op=Node.Ceil(x=x.node)))
def floor(self, x: Any) -> GraphNode: x = GraphNode.wrap(x) return GraphNode(node=Node(floor_op=Node.Floor(x=x.node)))
def abs(self, x: Any) -> GraphNode: x = GraphNode.wrap(x) return GraphNode(node=Node(abs_op=Node.Abs(x=x)))
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)))
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)))