Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
self.region.height, resolution=3)
width_factory = discrete_perlin_noise_factory(
self.region.height, resolution=6, octaves=2)
center = random_normal_int(
self.region.center().x, self.region.width / 4 / 3)
for y in self.region.range_height():
center += (center_factory(y) - 0.5) * 3
width = width_factory(y) * 2 + 5
x0 = int(center - width / 2)
x1 = int(x0 + width + 0.5)
for x in range(x0, x1 + 1):
self.map_canvas.set_architecture(Point(x, y), e.Water)
left_side[y] = (Span(self.region.left, x0 - 1),)
right_side[y] = (Span(x1 + 1, self.region.right),)
river[y] = (Span(x0, x1),)
return Blob(left_side), Blob(river), Blob(right_side)
center_factory = discrete_perlin_noise_factory(
self.region.height, resolution=3)
width_factory = discrete_perlin_noise_factory(
self.region.height, resolution=6, octaves=2)
center = random_normal_int(
self.region.center().x, self.region.width / 4 / 3)
for y in self.region.range_height():
center += (center_factory(y) - 0.5) * 3
width = width_factory(y) * 2 + 5
x0 = int(center - width / 2)
x1 = int(x0 + width + 0.5)
for x in range(x0, x1 + 1):
self.map_canvas.set_architecture(Point(x, y), e.Water)
left_side[y] = (Span(self.region.left, x0 - 1),)
right_side[y] = (Span(x1 + 1, self.region.right),)
river[y] = (Span(x0, x1),)
return Blob(left_side), Blob(river), Blob(right_side)
center_factory = discrete_perlin_noise_factory(
self.region.height, resolution=3)
width_factory = discrete_perlin_noise_factory(
self.region.height, resolution=6, octaves=2)
center = random_normal_int(
self.region.center().x, self.region.width / 4 / 3)
for y in self.region.range_height():
center += (center_factory(y) - 0.5) * 3
width = width_factory(y) * 2 + 5
x0 = int(center - width / 2)
x1 = int(x0 + width + 0.5)
for x in range(x0, x1 + 1):
self.map_canvas.set_architecture(Point(x, y), e.Water)
left_side[y] = (Span(self.region.left, x0 - 1),)
right_side[y] = (Span(x1 + 1, self.region.right),)
river[y] = (Span(x0, x1),)
return Blob(left_side), Blob(river), Blob(right_side)
def vertical_span(self):
return Span(self.top, self.bottom)
def horizontal_span(self):
return Span(self.left, self.right)
new_spans[y] = self.spans[y]
else:
my_spans = deque(self.spans[y])
combined_spans = []
# For each 'other' span, find which spans it overlaps, and
# merge all of them into a single new span.
for span in other.spans[y]:
starts = [span.start]
ends = [span.end]
while my_spans and span.overlaps(my_spans[0]):
subsumed_span = my_spans.popleft()
starts.append(subsumed_span.start)
ends.append(subsumed_span.end)
combined_spans.append(Span(min(starts), max(ends)))
combined_spans.extend(my_spans)
combined_spans.sort()
new_spans[y] = tuple(combined_spans)
return type(self)(new_spans)
for other_span in other_spans:
if not span.overlaps(other_span):
break
# Subtracting one span from another may leave zero, one, or
# two pieces remaining: the left end, the right end, both,
# or neither. Check for each end.
# Note that we need a < on the matching end, because if the
# subtracted span has the same endpoint, there's nothing
# left over on that end to make a new span.
if span.start < other_span.start <= span.end:
left_piece = Span(span.start, other_span.start - 1)
resolved_spans.append(left_piece)
if span.start <= other_span.end < span.end:
right_piece = Span(other_span.end + 1, span.end)
# DON'T add the right piece yet -- it might intersect
# another subtracted span! Instead, treat it as the
# current span.
span = right_piece
else:
# There was a left overlap, but no right overlap, so
# there's nothing left to subtract from.
span = None
break
# Add any leftover span
if span:
resolved_spans.append(span)
if resolved_spans:
new_spans[y] = tuple(resolved_spans)
# Remove any subtracted spans that don't overlap ours
while other_spans and other_spans[0].end < span.start:
other_spans.popleft()
for other_span in other_spans:
if not span.overlaps(other_span):
break
# Subtracting one span from another may leave zero, one, or
# two pieces remaining: the left end, the right end, both,
# or neither. Check for each end.
# Note that we need a < on the matching end, because if the
# subtracted span has the same endpoint, there's nothing
# left over on that end to make a new span.
if span.start < other_span.start <= span.end:
left_piece = Span(span.start, other_span.start - 1)
resolved_spans.append(left_piece)
if span.start <= other_span.end < span.end:
right_piece = Span(other_span.end + 1, span.end)
# DON'T add the right piece yet -- it might intersect
# another subtracted span! Instead, treat it as the
# current span.
span = right_piece
else:
# There was a left overlap, but no right overlap, so
# there's nothing left to subtract from.
span = None
break
# Add any leftover span
if span: