pull from osm branch
This commit is contained in:
parent
422af94b37
commit
2037979ac0
|
@ -20,15 +20,25 @@ class Drawing(object):
|
|||
for line in data.split('\n'):
|
||||
points = line.strip().split()
|
||||
points = [map(float, x.split(',')) for x in points]
|
||||
if points:
|
||||
paths.append(points)
|
||||
return cls(paths)
|
||||
|
||||
@classmethod
|
||||
def load(cls, filename):
|
||||
with open(filename, 'r') as fp:
|
||||
return cls.loads(fp.read())
|
||||
|
||||
def dumps(self):
|
||||
lines = []
|
||||
for path in self.paths:
|
||||
lines.append(' '.join('%f,%f' % (x, y) for x, y in path))
|
||||
return '\n'.join(lines)
|
||||
|
||||
def dump(self, filename):
|
||||
with open(filename, 'w') as fp:
|
||||
fp.write(self.dumps())
|
||||
|
||||
@property
|
||||
def bounds(self):
|
||||
if not self._bounds:
|
||||
|
@ -148,11 +158,12 @@ class Drawing(object):
|
|||
return drawing.scale(scale, scale).center(width, height)
|
||||
|
||||
def remove_paths_outside(self, width, height):
|
||||
e = 1e-8
|
||||
paths = []
|
||||
for path in self.paths:
|
||||
ok = True
|
||||
for x, y in path:
|
||||
if x < 0 or y < 0 or x > width or y > height:
|
||||
if x < -e or y < -e or x > width + e or y > height + e:
|
||||
ok = False
|
||||
break
|
||||
if ok:
|
||||
|
|
13
axi/paths.py
13
axi/paths.py
|
@ -64,10 +64,12 @@ def join_paths(paths, tolerance):
|
|||
return result
|
||||
|
||||
def crop_interpolate(x1, y1, x2, y2, ax, ay, bx, by):
|
||||
t1 = (x1 - ax) / (bx - ax)
|
||||
t2 = (y1 - ay) / (by - ay)
|
||||
t3 = (x2 - ax) / (bx - ax)
|
||||
t4 = (y2 - ay) / (by - ay)
|
||||
dx = bx - ax
|
||||
dy = by - ay
|
||||
t1 = (x1 - ax) / dx if dx else -1
|
||||
t2 = (y1 - ay) / dy if dy else -1
|
||||
t3 = (x2 - ax) / dx if dx else -1
|
||||
t4 = (y2 - ay) / dy if dy else -1
|
||||
ts = [t1, t2, t3, t4]
|
||||
ts = [t for t in ts if t >= 0 and t <= 1]
|
||||
t = min(ts)
|
||||
|
@ -76,12 +78,13 @@ def crop_interpolate(x1, y1, x2, y2, ax, ay, bx, by):
|
|||
return (x, y)
|
||||
|
||||
def crop_path(path, x1, y1, x2, y2):
|
||||
e = 1e-9
|
||||
result = []
|
||||
buf = []
|
||||
previous_point = None
|
||||
previous_inside = False
|
||||
for x, y in path:
|
||||
inside = x >= x1 and y >= y1 and x <= x2 and y <= y2
|
||||
inside = x >= x1 - e and y >= y1 - e and x <= x2 + e and y <= y2 + e
|
||||
if inside:
|
||||
if not previous_inside and previous_point:
|
||||
px, py = previous_point
|
||||
|
|
Loading…
Reference in New Issue