# Path: spriteworld/sprite.py
# FACTOR_NAMES = (
#     'x',  # x-position of sprite center-of-mass (float)
#     'y',  # y-position of sprite center-of-mass (float)
#     'shape',  # shape (string)
#     'angle',  # angle in degrees (scalar)
#     'scale',  # size of sprite (float)
#     'c0',  # first color component (scalar)
#     'c1',  # second color component (scalar)
#     'c2',  # third color component (scalar)
#     'x_vel',  # x-component of velocity (float)
#     'y_vel',  # y-component of velocity (float)
# )
# _MAX_TRIES = int(1e6)
# class Sprite(object):
#   def __init__(self,
#                x=0.5,
#                y=0.5,
#                shape='square',
#                angle=0,
#                scale=0.1,
#                c0=0,
#                c1=0,
#                c2=0,
#                x_vel=0.0,
#                y_vel=0.0):
#   def _reset_centered_path(self):
#   def move(self, motion, keep_in_frame=False):
#   def update_position(self, keep_in_frame=False):
#   def contains_point(self, point):
#   def sample_contained_position(self):
#   def vertices(self):
#   def out_of_frame(self):
#   def x(self):
#   def y(self):
#   def shape(self):
#   def shape(self, s):
#   def angle(self):
#   def angle(self, a):
#   def scale(self):
#   def scale(self, s):
#   def c0(self):
#   def c1(self):
#   def c2(self):
#   def x_vel(self):
#   def y_vel(self):
#   def color(self):
#   def position(self):
#   def velocity(self):
#   def factors(self):


from absl.testing import absltest
from absl.testing import parameterized
from six.moves import range
from spriteworld import sprite
import numpy as np
              [False, True, False, False],
              [True, True, True, False],
              [False, True, False, False],
              [False, False, False, False],
          ]),
  )
  def testContainsPoint(self, x, y, shape, angle, scale, containment):
    # As we use plots to prepare these tests, it's easier to write the matrix
    # "in the wrong orientation" (i.e. with origin='lower') and flip it.
    containment = np.flipud(containment)
    linspace = np.linspace(0.1, 0.9, 4)
    grid = np.stack(np.meshgrid(linspace, linspace), axis=-1)
    s = sprite.Sprite(x=x, y=y, shape=shape, angle=angle, scale=scale)

    eval_containment = np.array(
        [[s.contains_point(p) for p in row] for row in grid])
    self.assertTrue(np.allclose(eval_containment, containment))

  @parameterized.parameters(
      (0.5, 0.5, 'square', 0, 0.25),
      (0.1, 0.8, 'square', 0, 0.25),
      (0.5, 0.5, 'triangle', 0, 0.5),
      (0.5, 0.5, 'triangle', 30, 0.5))
  def testSampleContainedPosition(self, x, y, shape, angle, scale):
    s = sprite.Sprite(x=x, y=y, shape=shape, angle=angle, scale=scale)
    for _ in range(5):
      p = s.sample_contained_position()
      self.assertTrue(s.contains_point(p))

  def testResetShape(self):

# Path: spriteworld/sprite.py
# FACTOR_NAMES = (
#     'x',  # x-position of sprite center-of-mass (float)
#     'y',  # y-position of sprite center-of-mass (float)
#     'shape',  # shape (string)
#     'angle',  # angle in degrees (scalar)
#     'scale',  # size of sprite (float)
#     'c0',  # first color component (scalar)
#     'c1',  # second color component (scalar)
#     'c2',  # third color component (scalar)
#     'x_vel',  # x-component of velocity (float)
#     'y_vel',  # y-component of velocity (float)
# )
# _MAX_TRIES = int(1e6)
# class Sprite(object):
#   def __init__(self,
#                x=0.5,
#                y=0.5,
#                shape='square',
#                angle=0,
#                scale=0.1,
#                c0=0,
#                c1=0,
#                c2=0,
#                x_vel=0.0,
#                y_vel=0.0):
#   def _reset_centered_path(self):
#   def move(self, motion, keep_in_frame=False):
#   def update_position(self, keep_in_frame=False):
#   def contains_point(self, point):
#   def sample_contained_position(self):
#   def vertices(self):
#   def out_of_frame(self):
#   def x(self):
#   def y(self):
#   def shape(self):
#   def shape(self, s):
#   def angle(self):
#   def angle(self, a):
#   def scale(self):
#   def scale(self, s):
#   def c0(self):
#   def c1(self):
#   def c2(self):
#   def x_vel(self):
#   def y_vel(self):
#   def color(self):
#   def position(self):
#   def velocity(self):
#   def factors(self):


# Path: tests/sprite_test.py
from absl.testing import absltest
from absl.testing import parameterized
from six.moves import range
from spriteworld import sprite
import numpy as np

              [False, True, False, False],
              [True, True, True, False],
              [False, True, False, False],
              [False, False, False, False],
          ]),
  )
  def testContainsPoint(self, x, y, shape, angle, scale, containment):
    # As we use plots to prepare these tests, it's easier to write the matrix
    # "in the wrong orientation" (i.e. with origin='lower') and flip it.
    containment = np.flipud(containment)
    linspace = np.linspace(0.1, 0.9, 4)
    grid = np.stack(np.meshgrid(linspace, linspace), axis=-1)
    s = sprite.Sprite(x=x, y=y, shape=shape, angle=angle, scale=scale)

    eval_containment = np.array(
        [[s.contains_point(p) for p in row] for row in grid])
    self.assertTrue(np.allclose(eval_containment, containment))

  @parameterized.parameters(
      (0.5, 0.5, 'square', 0, 0.25),
      (0.1, 0.8, 'square', 0, 0.25),
      (0.5, 0.5, 'triangle', 0, 0.5),
      (0.5, 0.5, 'triangle', 30, 0.5))
  def testSampleContainedPosition(self, x, y, shape, angle, scale):
    s = sprite.Sprite(x=x, y=y, shape=shape, angle=angle, scale=scale)
    for _ in range(5):
      p = s.sample_contained_position()
      self.assertTrue(s.contains_point(p))

  def testResetShape(self):

    s = sprite.Sprite(scale=0.25, shape='square')