pull/1/head
parent
32844507ea
commit
e927bd307e
|
@ -534,7 +534,8 @@ class LTLayoutContainer(LTContainer):
|
||||||
return
|
return
|
||||||
|
|
||||||
def get_textboxes(self, laparams, lines):
|
def get_textboxes(self, laparams, lines):
|
||||||
plane = Plane(lines)
|
plane = Plane(self.bbox)
|
||||||
|
plane.extend(lines)
|
||||||
boxes = {}
|
boxes = {}
|
||||||
for line in lines:
|
for line in lines:
|
||||||
neighbors = line.find_neighbors(plane, laparams.line_margin)
|
neighbors = line.find_neighbors(plane, laparams.line_margin)
|
||||||
|
@ -596,7 +597,8 @@ class LTLayoutContainer(LTContainer):
|
||||||
obj2 = boxes[j]
|
obj2 = boxes[j]
|
||||||
dists.append((0, dist(obj1, obj2), obj1, obj2))
|
dists.append((0, dist(obj1, obj2), obj1, obj2))
|
||||||
dists.sort()
|
dists.sort()
|
||||||
plane = Plane(boxes)
|
plane = Plane(self.bbox)
|
||||||
|
plane.extend(boxes)
|
||||||
while dists:
|
while dists:
|
||||||
(c,d,obj1,obj2) = dists.pop(0)
|
(c,d,obj1,obj2) = dists.pop(0)
|
||||||
if c == 0 and isany(obj1, obj2):
|
if c == 0 and isany(obj1, obj2):
|
||||||
|
|
|
@ -221,13 +221,11 @@ def matrix2str((a,b,c,d,e,f)):
|
||||||
##
|
##
|
||||||
class Plane(object):
|
class Plane(object):
|
||||||
|
|
||||||
def __init__(self, objs=None, gridsize=50):
|
def __init__(self, bbox, gridsize=50):
|
||||||
self._objs = set()
|
self._objs = set()
|
||||||
self._grid = {}
|
self._grid = {}
|
||||||
self.gridsize = gridsize
|
self.gridsize = gridsize
|
||||||
if objs is not None:
|
(self.x0, self.y0, self.x1, self.y1) = bbox
|
||||||
for obj in objs:
|
|
||||||
self.add(obj)
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
|
@ -243,11 +241,21 @@ class Plane(object):
|
||||||
return obj in self._objs
|
return obj in self._objs
|
||||||
|
|
||||||
def _getrange(self, (x0,y0,x1,y1)):
|
def _getrange(self, (x0,y0,x1,y1)):
|
||||||
|
x0 = max(self.x0, x0)
|
||||||
|
y0 = max(self.y0, y0)
|
||||||
|
x1 = min(self.x1, x1)
|
||||||
|
y1 = min(self.y1, y1)
|
||||||
for y in drange(y0, y1, self.gridsize):
|
for y in drange(y0, y1, self.gridsize):
|
||||||
for x in drange(x0, x1, self.gridsize):
|
for x in drange(x0, x1, self.gridsize):
|
||||||
yield (x,y)
|
yield (x,y)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# extend(objs)
|
||||||
|
def extend(self, objs):
|
||||||
|
for obj in objs:
|
||||||
|
self.add(obj)
|
||||||
|
return
|
||||||
|
|
||||||
# add(obj): place an object.
|
# add(obj): place an object.
|
||||||
def add(self, obj):
|
def add(self, obj):
|
||||||
for k in self._getrange((obj.x0, obj.y0, obj.x1, obj.y1)):
|
for k in self._getrange((obj.x0, obj.y0, obj.x1, obj.y1)):
|
||||||
|
|
Loading…
Reference in New Issue