Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 9 additions & 18 deletions parallelogram/parallelogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,23 +49,21 @@ def make_object( x1, y1, max_dim=100 ):

def make_square( x1, y1, max_dim=100 ):
if max_dim<2: raise ValueError
lim = min( [max(x1,y1)+max_dim, 99] )
delta = random.randint( max(x1,y1)+1, lim )
lim = min( [max(x1,y1)+max_dim, 99-max(x1,y1)] )
delta = random.randint( 1, lim )
x2 = x1+delta
y2 = y1+delta
return ( x1, y1, x2, y2 )

def make_long( x1, y1, max_dim=100 ):
if max_dim<2: raise ValueError
# x1,y1 at the edge, impossible to fit long
if x1 == 98 and y1 == 98: raise ValueError
lim_x2 = min( [x1+max_dim,99] )
lim_y2 = min( [y1+max_dim,99] )
delta_x = random.randint( x1+1, lim_x2 )
delta_y = random.randint( y1+1, lim_y2 )
lim_x2 = min( [x1+max_dim,99-x1] )
lim_y2 = min( [y1+max_dim,99-y1] )
delta_x = random.randint( 1, lim_x2 )
delta_y = random.randint( 1, lim_y2 )
while delta_x == delta_y:
delta_x = random.randint( x1+1, lim_x2 )
delta_y = random.randint( y1+1, lim_y2 )
delta_x = random.randint( 1, lim_x2 )
delta_y = random.randint( 1, lim_y2 )
x2 = x1+delta_x
y2 = y1+delta_y
return ( x1, y1, x2, y2 )
Expand Down Expand Up @@ -95,14 +93,7 @@ def make_production_dataset( n ):
for i in range(0,math.ceil(n/2)):
x1 = random.randint( 0, 97 )
y1 = random.randint( 0, 97 )
try:
o = make_long( x1, y1, 72 )
except:
# x1,y1 at the edge,
# impossible to fit long
x1 = random.randint( 0, 90 )
y1 = random.randint( 0, 90 )
o = make_long( x1, y1 )
o = make_long( x1, y1, 72 )
data.append( o )
for i in range(0,math.ceil(n/2)):
x1 = random.randint( 0, 98 )
Expand Down