[Model.py 03]Modification for creating terrain matrix3.

Other 2 function.

get_rectangle_coordinates函数

    def get_rectangle_coordinates(self, x1, y1, x2, y2):
        '''
        获得由(x1,y1)(x2,y2)所围成的矩阵边上的坐标列表
        '''
        # Ensure (x1, y1) is the bottom-left corner and (x2, y2) is the top-right corner
        x_min = min(x1, x2)
        x_max = max(x1, x2)
        y_min = min(y1, y2)
        y_max = max(y1, y2)

        # Calculate coordinates of the four corners
        bottom_left = (x_min, y_min)
        bottom_right = (x_max, y_min)
        top_left = (x_min, y_max)
        top_right = (x_max, y_max)

        # Generate points along each edge
        left_edge = [(x_min, y) for y in range(y_min, y_max + 1)]
        right_edge = [(x_max, y) for y in range(y_min, y_max + 1)]
        bottom_edge = [(x, y_min) for x in range(x_min, x_max + 1)]
        top_edge = [(x, y_max) for x in range(x_min, x_max + 1)]

        # Combine all the points
        all_points = [bottom_left, bottom_right, top_left, top_right]
        all_points.extend(left_edge)
        all_points.extend(right_edge)
        all_points.extend(bottom_edge)
        all_points.extend(top_edge)

        return list(set(all_points))

get_coordinates_in_range函数

def get_coordinates_in_range(self, bottom_left, top_right):
    '''
    获得沟渠内所有的坐标
    '''
    coordinates = []
    for x in range(bottom_left[0], top_right[0] + 1):
        for y in range(bottom_left[1], top_right[1] + 1):
            coordinates.append((x, y))
    return coordinates

你可能感兴趣的:(python)