Beispiel #1
0
def determine_square(file_name):
    ' Square for problem '
    polygon_points = []
    with open(file_name) as input_file:
        n_poly = int(input_file.readline())
        for _ in range(n_poly):
            poly_points = int(input_file.readline())
            for _ in range(poly_points):
                point_x, point_y = input_file.readline().strip().split(',')
                point = (Frac(point_x), Frac(point_y))
                polygon_points.append(point)
    min_x = math.inf
    min_y = math.inf
    max_x = -math.inf
    max_y = -math.inf
    for x_coord, y_coord in geom_utils.get_envelope(polygon_points):
        min_x = min(min_x, x_coord)
        min_y = min(min_y, y_coord)
        max_x = max(max_x, x_coord)
        max_y = max(max_y, y_coord)
    #logging.info('The base should be %s %s', min_x, min_x)
    return (min_x, min_y, max_x - min_x, max_y - min_y)
Beispiel #2
0
''' Get the square that surrounds a given figure. Counterclockwise '''

# Sample output: [(0.1516052318668252, 0.6640348542932463), (0.8753126409446882, 0.6640348542932463), (0.8753126409446882, 1.206896551724138), (0.1516052318668252, 1.206896551724138)]

import  geom_utils

print (geom_utils.get_envelope([(310388465/517884436,85973329/129471109),(21348/24389,50875/48778),(364766764/572276111,946795121/1144552222),(402380/621499,1081733/1242998),(7405/14297,34489/28594),(15/29,35/29),(14769/28594,17245/14297),(460893/1242998,545060/621499),(433464041/1144552222,477008164/572276111),(1058/4205,8079/8410),(52977/243890,8079/8410),(255/1682,3619/4205),(78413889/339688310,159632711/169844155),(52924659/129471109,346300385/517884436),(1699/3364,2379/3364)]))