Exemplo n.º 1
0
	def test_cartesian2d(self):
		a = coordinates.Cartesian2D(1,2)
		b = coordinates.Cartesian2D(-1,-1)
		
		# Should always equal their equivilent tuples
		self.assertEqual(a, (1,2))
		self.assertEqual(b, (-1,-1))
		
		# Basic operators
		self.assertEqual(a+b, (0,1))
		self.assertEqual(a-b, (2,3))
		self.assertEqual(abs(b), (1,1))
		
		# Magnitude
		self.assertEqual(a.magnitude(), (1**2 + 2**2)**0.5)
		self.assertEqual(b.magnitude(), (2)**0.5)
Exemplo n.º 2
0
    def __init__(self,
                 rack=None,
                 dimensions=coordinates.Cartesian3D(40.0, 180.0, 25.0),
                 num_racks=10,
                 rack_spacing=2,
                 rack_offset=None):
        """
		dimensions is a Cartesian3D(width, height, depth).
		
		num_racks is the number of racks the cabinet fits
		
		rack_spacing is the additional (vertical) space between each rack
		
		rack_offset is the offset of the 0th rack from (0,0,0) of the rack. If
		not specified, the racks are centered within the rack's vertical and
		horizontal axes and placed at depth 0.
		
		rack is a Rack definition.
		"""
        rack = rack or Rack()
        self.volume = rack
        self.rack = rack

        self.num_racks = num_racks
        self.rack_spacing = rack_spacing

        _Container.__init__(self, dimensions, (1, num_racks),
                            coordinates.Cartesian2D(0.0, rack_spacing),
                            rack_offset)
Exemplo n.º 3
0
    def __init__(self,
                 slot=None,
                 dimensions=coordinates.Cartesian3D(30.0, 15.0, 20.0),
                 num_slots=24,
                 slot_spacing=0.1,
                 slot_offset=None):
        """
		dimensions is a Cartesian3D(width, height, depth).
		
		num_slots is the number of slots the rack fits
		
		slot_spacing is the additional (horizontal) space between each slot
		
		slot_offset is the offset of the 0th slot from (0,0,0) of the rack. If
		not specified, the slots are centered within the rack's vertical and
		horizontal axes and placed at depth 0.
		
		slot is a Slot definition.
		"""
        slot = slot or Slot()
        self.volume = slot
        self.slot = slot

        self.num_slots = num_slots
        self.slot_spacing = slot_spacing

        _Container.__init__(self, dimensions, (num_slots, 1),
                            coordinates.Cartesian2D(slot_spacing, 0.0),
                            slot_offset)
Exemplo n.º 4
0
def hex_to_cartesian(coords):
    """
	Convert a set of hexagonal coordinates into equivalent (for presentation
	purposes) Cartesian values.
	"""

    old_x, old_y = to_xy(coords)

    new_x = old_x
    new_y = (old_y * 2) - old_x

    return coordinates.Cartesian2D(new_x, new_y)
Exemplo n.º 5
0
def hex_to_skewed_cartesian(coords):
    """
	Convert a set of hexagonal coordinates into equivalent Cartesian values
	skewed to make x and y in the coordinate space match x and y in Cartesian
	space.
	"""

    old_x, old_y = to_xy(coords)

    new_x = old_x + old_y
    new_y = (old_y * 2) - old_x

    return coordinates.Cartesian2D(new_x, new_y)