Пример #1
0
def test_points_can_be_subtracted():
    point_1 = point.Vec2([1, 2])
    point_2 = point.Vec2([3, 4])

    resultant = point_1 - point_2
    assert resultant.x == -2
    assert resultant.y == -2
Пример #2
0
def test_points_can_be_added():
    point_1 = point.Vec2([1, 2])
    point_2 = point.Vec2([3, 4])

    resultant = point_1 + point_2
    assert resultant.x == 4
    assert resultant.y == 6
Пример #3
0
    def location(self):
        if self._location:
            return self._location

        points = [node.location.nd for node in self.nodes]

        # If we have a relay node, make sure to include it in the centroid
        # calculation.
        if self.relay_node:
            points.append(self.relay_node.location.nd)

        location = linalg.centroid(np.array(points))
        self._location = point.Vec2(location)
        return self._location
Пример #4
0
    def __init__(self, row, column, environment):
        """

        :param row:
        :param column:
        :param environment:
        :type environment: core.environment.Environment
        """

        self.cell_id = Cell.count
        Cell.count += 1

        # Maintain the grid position.
        self.grid_location = np.array([row, column])

        # Calculate the physical location of the center of this cell.
        side_len = side_length(environment)
        x_pos = column * side_len + (side_len / 2.)
        y_pos = row * side_len + (side_len / 2.)
        self.location = point.Vec2(np.array([x_pos, y_pos]))  # * pq.meter

        # The segments within radio range of this cell.
        self.segments = list()

        # The (maximum eight) cells immediately adjacent to this cell.
        self.neighbors = list()

        # The number of segments within radio range of any neighbor cell
        self.signal_hop_count = 0

        # The cell distance between this cell and the centroid cell, G.
        self.proximity = 0

        # The numeric identifier of the virtual cluster this cell belongs to.
        self.virtual_cluster_id = -1

        # The numeric identifier of the cluster this cell belongs to.
        self._cluster_id = -1
Пример #5
0
    def __init__(self, nd):
        self.segment_id = Segment.count
        Segment.count += 1

        self.location = point.Vec2(nd)
        self.cluster_id = -1
Пример #6
0
def test_points_can_be_set_by_lists():
    vec = point.Vec2([1, -2])
    assert vec.x == 1
    assert vec.y == -2
Пример #7
0
def test_empty_points_default_to_0_0():
    vec = point.Vec2()
    assert vec.x == 0
    assert vec.y == 0
Пример #8
0
def test_points_can_be_set_by_np_arrays():
    vec = point.Vec2(np.array([1, -2]))
    assert vec.x == 1
    assert vec.y == -2
Пример #9
0
 def __init__(self, position):
     self.location = point.Vec2(position)
     self.cluster_id = -1