I have the following list of points that represent walls:
walls = [[ 76.7403, 1283.2495, 894.5198, 1310.0122],
[ 864.3867, 415.2406, 891.3730, 1287.3810],
[ 80.0975, 402.9981, 899.7578, 428.0596],
[ 75.9861, 404.3390, 101.6148, 1292.0922],
[ 469.9275, 1118.6304, 481.1644, 1300.6523],
[ 500.6000, 897.3496, 876.6120, 908.2079],
[ 102.0548, 753.6523, 402.9403, 764.0107],
[ 247.2823, 968.0134, 320.4769, 977.5980],
[ 503.2201, 898.0987, 515.2742, 1136.6272],
[ 400.9270, 689.1513, 411.8462, 907.2622],
[ 353.0995, 1123.1868, 362.8233, 1293.9554],
[ 248.6094, 967.5870, 261.0458, 1124.8018],
[ 246.0828, 896.9332, 411.2629, 906.4570],
[ 880.6799, 60.5249, 892.5886, 411.2219],
[ 249.5214, 1116.5377, 259.7009, 1290.2698],
[ 309.1409, 899.7199, 320.3546, 978.5977],
[ 85.6537, 1118.2689, 259.5562, 1128.9491],
[ 249.0276, 763.1385, 261.5212, 905.9616],
[ 86.2850, 1117.8192, 501.5602, 1128.5548],
[ 240.1799, 1117.4913, 385.9280, 1128.2761],
[ 288.5830, 1117.4141, 515.1036, 1128.3738],
[ 512.2842, 1015.8013, 592.7465, 1022.5025],
[ 249.2041, 748.7802, 260.6894, 1140.3009],
[ 401.1811, 687.2712, 411.9943, 779.8344],
[ 380.8932, 1040.3300, 386.9687, 1126.2324]]
I'm forming a set of polygons from these walls with the following:
polys = []
for w in walls:
x0, y0, x1, y1 = w
poly = [
(x0, y0), (x1, y0),
(x1, y1), (x0, y1)
]
poly = list(itertools.chain.from_iterable(poly))
polys.append(poly)
The polygons end up looking as follows:
What I would like to do is connect the wall endpoints such that they wouldn't overlap as seen in the picture. What would be an optimal algorithm to do this?
Here is the code to produce the image:
<svg width="1200" height="1300">
<polygon points='76.7403, 1283.2495, 894.5198, 1283.2495, 894.5198, 1310.0122, 76.7403, 1310.0122'/>
<polygon points='864.3867, 415.2406, 891.373, 415.2406, 891.373, 1287.381, 864.3867, 1287.381'/>
<polygon points='80.0975, 402.9981, 899.7578, 402.9981, 899.7578, 428.0596, 80.0975, 428.0596'/>
<polygon points='75.9861, 404.339, 101.6148, 404.339, 101.6148, 1292.0922, 75.9861, 1292.0922'/>
<polygon points='469.9275, 1118.6304, 481.1644, 1118.6304, 481.1644, 1300.6523, 469.9275, 1300.6523'/>
<polygon points='500.6, 897.3496, 876.612, 897.3496, 876.612, 908.2079, 500.6, 908.2079'/>
<polygon points='102.0548, 753.6523, 402.9403, 753.6523, 402.9403, 764.0107, 102.0548, 764.0107'/>
<polygon points='247.2823, 968.0134, 320.4769, 968.0134, 320.4769, 977.598, 247.2823, 977.598'/>
<polygon points='503.2201, 898.0987, 515.2742, 898.0987, 515.2742, 1136.6272, 503.2201, 1136.6272'/>
<polygon points='400.927, 689.1513, 411.8462, 689.1513, 411.8462, 907.2622, 400.927, 907.2622'/>
<polygon points='353.0995, 1123.1868, 362.8233, 1123.1868, 362.8233, 1293.9554, 353.0995, 1293.9554'/>
<polygon points='248.6094, 967.587, 261.0458, 967.587, 261.0458, 1124.8018, 248.6094, 1124.8018'/>
<polygon points='246.0828, 896.9332, 411.2629, 896.9332, 411.2629, 906.457, 246.0828, 906.457'/>
<polygon points='880.6799, 60.5249, 892.5886, 60.5249, 892.5886, 411.2219, 880.6799, 411.2219'/>
<polygon points='249.5214, 1116.5377, 259.7009, 1116.5377, 259.7009, 1290.2698, 249.5214, 1290.2698'/>
<polygon points='309.1409, 899.7199, 320.3546, 899.7199, 320.3546, 978.5977, 309.1409, 978.5977'/>
<polygon points='85.6537, 1118.2689, 259.5562, 1118.2689, 259.5562, 1128.9491, 85.6537, 1128.9491'/>
<polygon points='249.0276, 763.1385, 261.5212, 763.1385, 261.5212, 905.9616, 249.0276, 905.9616'/>
<polygon points='86.285, 1117.8192, 501.5602, 1117.8192, 501.5602, 1128.5548, 86.285, 1128.5548'/>
<polygon points='240.1799, 1117.4913, 385.928, 1117.4913, 385.928, 1128.2761, 240.1799, 1128.2761'/>
<polygon points='288.583, 1117.4141, 515.1036, 1117.4141, 515.1036, 1128.3738, 288.583, 1128.3738'/>
<polygon points='512.2842, 1015.8013, 592.7465, 1015.8013, 592.7465, 1022.5025, 512.2842, 1022.5025'/>
<polygon points='249.2041, 748.7802, 260.6894, 748.7802, 260.6894, 1140.3009, 249.2041, 1140.3009'/>
<polygon points='401.1811, 687.2712, 411.9943, 687.2712, 411.9943, 779.8344, 401.1811, 779.8344'/>
<polygon points='380.8932, 1040.33, 386.9687, 1040.33, 386.9687, 1126.2324, 380.8932, 1126.2324'/>
</svg>


