Revision: 3997
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3997&view=rev
Author: mdboom
Date: 2007-10-24 12:22:00 -0700 (Wed, 24 Oct 2007)
Log Message:
-----------
Renamed [xmin, ymin, xmax, ymax] in Bbox to [x0, y0, x1, y1] and
provide functions that really do give xmax etc. as well.
Renamed lbrt to extents and lbwh to bounds (for consistency).
Removed some dead code.
Modified Paths:
--------------
branches/transforms/lib/matplotlib/axes.py
branches/transforms/lib/matplotlib/axis.py
branches/transforms/lib/matplotlib/backend_bases.py
branches/transforms/lib/matplotlib/backends/backend_agg.py
branches/transforms/lib/matplotlib/backends/backend_pdf.py
branches/transforms/lib/matplotlib/collections.py
branches/transforms/lib/matplotlib/figure.py
branches/transforms/lib/matplotlib/image.py
branches/transforms/lib/matplotlib/legend.py
branches/transforms/lib/matplotlib/lines.py
branches/transforms/lib/matplotlib/patches.py
branches/transforms/lib/matplotlib/path.py
branches/transforms/lib/matplotlib/projections/polar.py
branches/transforms/lib/matplotlib/text.py
branches/transforms/lib/matplotlib/transforms.py
Modified: branches/transforms/lib/matplotlib/axes.py
===================================================================
--- branches/transforms/lib/matplotlib/axes.py 2007-10-24 18:49:08 UTC (rev
3996)
+++ branches/transforms/lib/matplotlib/axes.py 2007-10-24 19:22:00 UTC (rev
3997)
@@ -480,7 +480,7 @@
if isinstance(rect, mtransforms.Bbox):
self._position = rect
else:
- self._position = mtransforms.Bbox.from_lbwh(*rect)
+ self._position = mtransforms.Bbox.from_bounds(*rect)
self._originalPosition = self._position.frozen()
self.set_axes(self)
self.set_aspect('auto')
@@ -1696,7 +1696,7 @@
# Call all of the other y-axes that are shared with this one
for other in self._shared_y_axes.get_siblings(self):
if other is not self:
- other.set_ylim(self.viewLim.ymin, self.viewLim.ymax,
emit=False)
+ other.set_ylim(self.viewLim.intervaly, emit=False)
if self.figure.canvas is not None:
self.figure.canvas.draw_idle()
@@ -1902,7 +1902,6 @@
if self.get_aspect() != 'auto':
dx = 0.5 * (dx + dy)
dy = dx
- xmin, ymin, xmax, ymax = p.lim.lbrt
alpha = npy.power(10.0, (dx, dy))
start = p.trans_inverse.transform_point((p.x, p.y))
@@ -5207,7 +5206,7 @@
figBottom = top - (rowNum+1)*figH - rowNum*sepH
figLeft = left + colNum*(figW + sepW)
- self.figbox = mtransforms.Bbox.from_lbwh(figLeft, figBottom, figW,
figH)
+ self.figbox = mtransforms.Bbox.from_bounds(figLeft, figBottom, figW,
figH)
self.rowNum = rowNum
self.colNum = colNum
self.numRows = rows
Modified: branches/transforms/lib/matplotlib/axis.py
===================================================================
--- branches/transforms/lib/matplotlib/axis.py 2007-10-24 18:49:08 UTC (rev
3996)
+++ branches/transforms/lib/matplotlib/axis.py 2007-10-24 19:22:00 UTC (rev
3997)
@@ -1070,7 +1070,7 @@
bottom = self.axes.bbox.ymin
else:
bbox = Bbox.union(bboxes)
- bottom = bbox.ymin
+ bottom = bbox.y0
self.label.set_position( (x, bottom -
self.LABELPAD*self.figure.dpi / 72.0))
else:
@@ -1078,8 +1078,7 @@
top = self.axes.bbox.ymax
else:
bbox = bbox_union(bboxes2)
- top = bbox.ymax
-
+ top = bbox.y1
self.label.set_position( (x, top+self.LABELPAD*self.figure.dpi /
72.0))
def _update_offset_text_position(self, bboxes, bboxes2):
@@ -1092,7 +1091,7 @@
bottom = self.axes.bbox.ymin
else:
bbox = Bbox.union(bboxes)
- bottom = bbox.ymin
+ bottom = bbox.y0
self.offsetText.set_position((x,
bottom-self.OFFSETTEXTPAD*self.figure.dpi/72.0))
def set_ticks_position(self, position):
@@ -1280,9 +1279,8 @@
if not len(bboxes):
left = self.axes.bbox.xmin
else:
-
bbox = Bbox.union(bboxes)
- left = bbox.xmin
+ left = bbox.x0
self.label.set_position( (left-self.LABELPAD*self.figure.dpi/72.0,
y))
@@ -1291,7 +1289,7 @@
right = self.axes.bbox.xmax
else:
bbox = Bbox.union(bboxes2)
- right = bbox.xmax
+ right = bbox.x1
self.label.set_position(
(right+self.LABELPAD*self.figure.dpi/72.0, y))
Modified: branches/transforms/lib/matplotlib/backend_bases.py
===================================================================
--- branches/transforms/lib/matplotlib/backend_bases.py 2007-10-24 18:49:08 UTC
(rev 3996)
+++ branches/transforms/lib/matplotlib/backend_bases.py 2007-10-24 19:22:00 UTC
(rev 3997)
@@ -1422,7 +1422,7 @@
self.draw()
return
- xmin, ymin, xmax, ymax = lim.lbrt
+ x0, y0, x1, y1 = lim.extents
# zoom to rect
inverse = a.transData.inverted()
@@ -1432,49 +1432,49 @@
Ymin,Ymax=a.get_ylim()
if Xmin < Xmax:
- if x<lastx: xmin, xmax = x, lastx
- else: xmin, xmax = lastx, x
- if xmin < Xmin: xmin=Xmin
- if xmax > Xmax: xmax=Xmax
+ if x<lastx: x0, x1 = x, lastx
+ else: x0, x1 = lastx, x
+ if x0 < Xmin: x0=Xmin
+ if x1 > Xmax: x1=Xmax
else:
- if x>lastx: xmin, xmax = x, lastx
- else: xmin, xmax = lastx, x
- if xmin > Xmin: xmin=Xmin
- if xmax < Xmax: xmax=Xmax
+ if x>lastx: x0, x1 = x, lastx
+ else: x0, x1 = lastx, x
+ if x0 > Xmin: x0=Xmin
+ if x1 < Xmax: x1=Xmax
if Ymin < Ymax:
- if y<lasty: ymin, ymax = y, lasty
- else: ymin, ymax = lasty, y
- if ymin < Ymin: ymin=Ymin
- if ymax > Ymax: ymax=Ymax
+ if y<lasty: y0, y1 = y, lasty
+ else: y0, y1 = lasty, y
+ if y0 < Ymin: y0=Ymin
+ if y1 > Ymax: y1=Ymax
else:
- if y>lasty: ymin, ymax = y, lasty
- else: ymin, ymax = lasty, y
- if ymin > Ymin: ymin=Ymin
- if ymax < Ymax: ymax=Ymax
+ if y>lasty: y0, y1 = y, lasty
+ else: y0, y1 = lasty, y
+ if y0 > Ymin: y0=Ymin
+ if y1 < Ymax: y1=Ymax
if self._button_pressed == 1:
- a.set_xlim((xmin, xmax))
- a.set_ylim((ymin, ymax))
+ a.set_xlim((x0, x1))
+ a.set_ylim((y0, y1))
elif self._button_pressed == 3:
if a.get_xscale()=='log':
- alpha=npy.log(Xmax/Xmin)/npy.log(xmax/xmin)
- x1=pow(Xmin/xmin,alpha)*Xmin
- x2=pow(Xmax/xmin,alpha)*Xmin
+ alpha=npy.log(Xmax/Xmin)/npy.log(x1/x0)
+ rx1=pow(Xmin/x0,alpha)*Xmin
+ x2=pow(Xmax/x0,alpha)*Xmin
else:
- alpha=(Xmax-Xmin)/(xmax-xmin)
- x1=alpha*(Xmin-xmin)+Xmin
- x2=alpha*(Xmax-xmin)+Xmin
+ alpha=(Xmax-Xmin)/(x1-x0)
+ rx1=alpha*(Xmin-x0)+Xmin
+ x2=alpha*(Xmax-x0)+Xmin
if a.get_yscale()=='log':
- alpha=npy.log(Ymax/Ymin)/npy.log(ymax/ymin)
- y1=pow(Ymin/ymin,alpha)*Ymin
- y2=pow(Ymax/ymin,alpha)*Ymin
+ alpha=npy.log(Ymax/Ymin)/npy.log(y1/y0)
+ ry1=pow(Ymin/y0,alpha)*Ymin
+ ry2=pow(Ymax/y0,alpha)*Ymin
else:
- alpha=(Ymax-Ymin)/(ymax-ymin)
- y1=alpha*(Ymin-ymin)+Ymin
- y2=alpha*(Ymax-ymin)+Ymin
- a.set_xlim((x1, x2))
- a.set_ylim((y1, y2))
+ alpha=(Ymax-Ymin)/(y1-y0)
+ ry1=alpha*(Ymin-y0)+Ymin
+ ry2=alpha*(Ymax-y0)+Ymin
+ a.set_xlim((rx1, rx2))
+ a.set_ylim((ry1, ry2))
self.draw()
self._xypress = None
Modified: branches/transforms/lib/matplotlib/backends/backend_agg.py
===================================================================
--- branches/transforms/lib/matplotlib/backends/backend_agg.py 2007-10-24
18:49:08 UTC (rev 3996)
+++ branches/transforms/lib/matplotlib/backends/backend_agg.py 2007-10-24
19:22:00 UTC (rev 3997)
@@ -118,7 +118,7 @@
self.mathtext_parser = MathTextParser('Agg')
self._fontd = {}
- self.bbox = Bbox.from_lbwh(0,0, self.width, self.height)
+ self.bbox = Bbox.from_bounds(0, 0, self.width, self.height)
if __debug__: verbose.report('RendererAgg.__init__ done',
'debug-annoying')
@@ -227,7 +227,7 @@
cliprect = gc.get_clip_rectangle()
if cliprect is None: bbox = None
- else: bbox = Bbox.from_lbwh(*cliprect)
+ else: bbox = Bbox.from_bounds(*cliprect)
self.draw_image(x, self.height-y, im, bbox)
def get_canvas_width_height(self):
Modified: branches/transforms/lib/matplotlib/backends/backend_pdf.py
===================================================================
--- branches/transforms/lib/matplotlib/backends/backend_pdf.py 2007-10-24
18:49:08 UTC (rev 3996)
+++ branches/transforms/lib/matplotlib/backends/backend_pdf.py 2007-10-24
19:22:00 UTC (rev 3997)
@@ -1032,12 +1032,12 @@
def writeMarkers(self):
for tup in self.markers.values():
name, object, path, trans, fillp, lw = tup
- bbox = Bbox.from_lbrt(*path.get_extents(trans))
+ bbox = Bbox.from_extents(*path.get_extents(trans))
bbox = bbox.padded(lw * 0.5)
self.beginStream(
object.id, None,
{'Type': Name('XObject'), 'Subtype': Name('Form'),
- 'BBox': list(bbox.lbrt) })
+ 'BBox': list(bbox.extents) })
self.writePath(path, trans)
if fillp:
self.output(Op.fill_stroke)
Modified: branches/transforms/lib/matplotlib/collections.py
===================================================================
--- branches/transforms/lib/matplotlib/collections.py 2007-10-24 18:49:08 UTC
(rev 3996)
+++ branches/transforms/lib/matplotlib/collections.py 2007-10-24 19:22:00 UTC
(rev 3997)
@@ -126,12 +126,12 @@
return self._transforms
def get_datalim(self, transData):
- result = transforms.Bbox.from_lbrt(*path.get_path_collection_extents(
- self.get_transform().frozen(),
- self.get_paths(),
- self.get_transforms(),
- self._offsets,
- self._transOffset.frozen()))
+ result = path.get_path_collection_extents(
+ self.get_transform().frozen(),
+ self.get_paths(),
+ self.get_transforms(),
+ self._offsets,
+ self._transOffset.frozen())
result = result.transformed(transData.inverted())
return result
Modified: branches/transforms/lib/matplotlib/figure.py
===================================================================
--- branches/transforms/lib/matplotlib/figure.py 2007-10-24 18:49:08 UTC
(rev 3996)
+++ branches/transforms/lib/matplotlib/figure.py 2007-10-24 19:22:00 UTC
(rev 3997)
@@ -131,7 +131,7 @@
self._dpi_scale_trans = Affine2D()
self.dpi = dpi
- self.bbox_inches = Bbox.from_lbwh(0, 0, *figsize)
+ self.bbox_inches = Bbox.from_bounds(0, 0, *figsize)
self.bbox = TransformedBbox(self.bbox_inches, self._dpi_scale_trans)
self.frameon = frameon
@@ -351,11 +351,11 @@
def get_figwidth(self):
'Return the figwidth as a float'
- return self.bbox_inches.xmax
+ return self.bbox_inches.width
def get_figheight(self):
'Return the figheight as a float'
- return self.bbox_inches.ymax
+ return self.bbox_inches.height
def get_dpi(self):
'Return the dpi as a float'
@@ -395,7 +395,7 @@
ACCEPTS: float
"""
- self.bbox_inches.xmax = val
+ self.bbox_inches.x1 = val
def set_figheight(self, val):
"""
@@ -403,7 +403,7 @@
ACCEPTS: float
"""
- self.bbox_inches.ymax = val
+ self.bbox_inches.y1 = val
def set_frameon(self, b):
"""
Modified: branches/transforms/lib/matplotlib/image.py
===================================================================
--- branches/transforms/lib/matplotlib/image.py 2007-10-24 18:49:08 UTC (rev
3996)
+++ branches/transforms/lib/matplotlib/image.py 2007-10-24 19:22:00 UTC (rev
3997)
@@ -156,8 +156,8 @@
im.apply_translation(-1, -1)
# the viewport translation
- tx = (xmin-self.axes.viewLim.xmin)/dxintv * numcols
- ty = (ymin-self.axes.viewLim.ymin)/dyintv * numrows
+ tx = (xmin-self.axes.viewLim.x0)/dxintv * numcols
+ ty = (ymin-self.axes.viewLim.y0)/dyintv * numrows
l, b, widthDisplay, heightDisplay = self.axes.bbox.bounds
widthDisplay *= magnification
Modified: branches/transforms/lib/matplotlib/legend.py
===================================================================
--- branches/transforms/lib/matplotlib/legend.py 2007-10-24 18:49:08 UTC
(rev 3996)
+++ branches/transforms/lib/matplotlib/legend.py 2007-10-24 19:22:00 UTC
(rev 3997)
@@ -442,7 +442,7 @@
candidates = []
for l, b in consider:
- legendBox = Bbox.from_lbwh(l, b, width, height)
+ legendBox = Bbox.from_bounds(l, b, width, height)
badness = 0
badness = legendBox.count_contains(verts)
badness += legendBox.count_overlaps(bboxes)
Modified: branches/transforms/lib/matplotlib/lines.py
===================================================================
--- branches/transforms/lib/matplotlib/lines.py 2007-10-24 18:49:08 UTC (rev
3996)
+++ branches/transforms/lib/matplotlib/lines.py 2007-10-24 19:22:00 UTC (rev
3997)
@@ -673,39 +673,6 @@
gc.set_linestyle('solid')
renderer.draw_path(gc, path, trans)
-
- def _step(self, x, y, where):
- if not cbook.iterable(x):
- x = ma.array([x], dtype=npy.float_)
- if not cbook.iterable(y):
- y = ma.array([y], dtype=npy.float_)
-
- if where=='pre':
- x2 = ma.zeros((2*len(x)-1,), npy.float_)
- y2 = ma.zeros((2*len(y)-1,), npy.float_)
-
- x2[0::2], x2[1::2] = x, x[:-1]
- y2[0::2], y2[1:-1:2] = y, y[1:]
-
- elif where=='post':
- x2 = ma.zeros((2*len(x)-1,), npy.float_)
- y2 = ma.zeros((2*len(y)-1,), npy.float_)
-
- x2[::2], x2[1:-1:2] = x, x[1:]
- y2[0::2], y2[1::2] = y, y[:-1]
-
- elif where=='mid':
- x2 = ma.zeros((2*len(x),), npy.float_)
- y2 = ma.zeros((2*len(y),), npy.float_)
-
- x2[1:-1:2] = 0.5*(x[:-1]+x[1:])
- x2[2::2] = 0.5*(x[:-1]+x[1:])
- x2[0], x2[-1] = x[0], x[-1]
-
- y2[0::2], y2[1::2] = y, y
-
- return x2, y2
-
def _draw_steps_pre(self, renderer, gc, path, trans):
vertices = self._xy
Modified: branches/transforms/lib/matplotlib/patches.py
===================================================================
--- branches/transforms/lib/matplotlib/patches.py 2007-10-24 18:49:08 UTC
(rev 3996)
+++ branches/transforms/lib/matplotlib/patches.py 2007-10-24 19:22:00 UTC
(rev 3997)
@@ -346,7 +346,7 @@
left, right = self.convert_xunits((xy[0], xy[0] + width))
bottom, top = self.convert_yunits((xy[1], xy[1] + height))
- self._bbox = transforms.Bbox.from_lbrt(left, bottom, right, top)
+ self._bbox = transforms.Bbox.from_extents(left, bottom, right, top)
self._rect_transform = transforms.BboxTransform(
transforms.Bbox.unit(), self._bbox)
__init__.__doc__ = cbook.dedent(__init__.__doc__) % artist.kwdocd
@@ -367,11 +367,11 @@
def get_x(self):
"Return the left coord of the rectangle"
- return self._bbox.xmin
+ return self._bbox.x0
def get_y(self):
"Return the bottom coord of the rectangle"
- return self._bbox.ymin
+ return self._bbox.y0
def get_width(self):
"Return the width of the rectangle"
@@ -405,7 +405,7 @@
ACCEPTS: float
"""
- self._bbox.xmax = self._bbox.xmin + w
+ self._bbox.x1 = self._bbox.x0 + w
def set_height(self, h):
"""
@@ -413,7 +413,7 @@
ACCEPTS: float
"""
- self._bbox.ymax = self._bbox.ymin + h
+ self._bbox.y1 = self._bbox.y0 + h
def set_bounds(self, *args):
"""
Modified: branches/transforms/lib/matplotlib/path.py
===================================================================
--- branches/transforms/lib/matplotlib/path.py 2007-10-24 18:49:08 UTC (rev
3996)
+++ branches/transforms/lib/matplotlib/path.py 2007-10-24 19:22:00 UTC (rev
3997)
@@ -10,7 +10,8 @@
from numpy import ma as ma
from matplotlib._path import point_in_path, get_path_extents, \
- get_path_collection_extents, point_in_path_collection
+ point_in_path_collection
+import matplotlib._path as _path
from matplotlib.cbook import simple_linear_interpolation
KAPPA = 4.0 * (npy.sqrt(2) - 1) / 3.0
@@ -199,7 +200,7 @@
from transforms import Affine2D, Bbox
if transform is None:
transform = Affine2D()
- return Bbox.from_lbrt(*get_path_extents(self, transform))
+ return Bbox.from_extents(*get_path_extents(self, transform))
def interpolated(self, steps):
"""
@@ -402,3 +403,6 @@
"""
return cls.arc(theta1, theta2, True)
wedge = classmethod(wedge)
+
+def get_path_collection_extents(*args):
+ return Bbox.from_extents(*_path.get_path_collection_extents(*args))
Modified: branches/transforms/lib/matplotlib/projections/polar.py
===================================================================
--- branches/transforms/lib/matplotlib/projections/polar.py 2007-10-24
18:49:08 UTC (rev 3996)
+++ branches/transforms/lib/matplotlib/projections/polar.py 2007-10-24
19:22:00 UTC (rev 3997)
@@ -256,7 +256,7 @@
return Circle((0.5, 0.5), 0.5)
def set_rmax(self, rmax):
- self.viewLim.ymax = rmax
+ self.viewLim.y1 = rmax
angle = self._r_label1_position.to_values()[4]
self._r_label1_position.clear().translate(
angle, rmax * self._rpad)
Modified: branches/transforms/lib/matplotlib/text.py
===================================================================
--- branches/transforms/lib/matplotlib/text.py 2007-10-24 18:49:08 UTC (rev
3996)
+++ branches/transforms/lib/matplotlib/text.py 2007-10-24 19:22:00 UTC (rev
3997)
@@ -253,7 +253,7 @@
xmin -= offsetx
ymin -= offsety
- bbox = Bbox.from_lbwh(xmin, ymin, width, height)
+ bbox = Bbox.from_bounds(xmin, ymin, width, height)
# now rotate the positions around the first x,y position
xys = M.transform(offsetLayout)
@@ -407,7 +407,7 @@
if not self.get_visible(): return Bbox.unit()
if self._text == '':
tx, ty = self._get_xy_display()
- return Bbox.from_lbwh(tx,ty,0,0)
+ return Bbox.from_bounds(tx,ty,0,0)
if renderer is not None:
self._renderer = renderer
Modified: branches/transforms/lib/matplotlib/transforms.py
===================================================================
--- branches/transforms/lib/matplotlib/transforms.py 2007-10-24 18:49:08 UTC
(rev 3996)
+++ branches/transforms/lib/matplotlib/transforms.py 2007-10-24 19:22:00 UTC
(rev 3997)
@@ -196,28 +196,46 @@
def __array__(self, *args, **kwargs):
return self.get_points()
+ def _get_x0(self):
+ return self.get_points()[0, 0]
+ x0 = property(_get_x0)
+
+ def _get_y0(self):
+ return self.get_points()[0, 1]
+ y0 = property(_get_y0)
+
+ def _get_x1(self):
+ return self.get_points()[1, 0]
+ x1 = property(_get_x1)
+
+ def _get_y1(self):
+ return self.get_points()[1, 1]
+ y1 = property(_get_y1)
+
def _get_xmin(self):
- return self.get_points()[0, 0]
+ return min(self.get_points()[:, 0])
xmin = property(_get_xmin)
-
+
def _get_ymin(self):
- return self.get_points()[0, 1]
+ return min(self.get_points()[:, 1])
ymin = property(_get_ymin)
def _get_xmax(self):
- return self.get_points()[1, 0]
+ return max(self.get_points()[:, 0])
xmax = property(_get_xmax)
def _get_ymax(self):
- return self.get_points()[1, 1]
+ return max(self.get_points()[:, 1])
ymax = property(_get_ymax)
-
+
def _get_min(self):
- return self.get_points()[0]
+ return [min(self.get_points()[:, 0]),
+ min(self.get_points()[:, 1])]
min = property(_get_min)
def _get_max(self):
- return self.get_points()[1]
+ return [max(self.get_points()[:, 0]),
+ max(self.get_points()[:, 1])]
max = property(_get_max)
def _get_intervalx(self):
@@ -244,35 +262,35 @@
size = property(_get_size)
def _get_bounds(self):
- ((xmin, ymin), (xmax, ymax)) = self.get_points()
- return (xmin, ymin, xmax - xmin, ymax - ymin)
+ ((x0, y0), (x1, y1)) = self.get_points()
+ return (x0, y0, x1 - x0, y1 - y0)
bounds = property(_get_bounds)
- def _get_lbrt(self):
+ def _get_extents(self):
return self.get_points().flatten().copy()
- lbrt = property(_get_lbrt)
+ extents = property(_get_extents)
def get_points(self):
return NotImplementedError()
def containsx(self, x):
- xmin, xmax = self.intervalx
- return ((xmin < xmax
- and (x >= xmin and x <= xmax))
- or (x >= xmax and x <= xmin))
+ x0, x1 = self.intervalx
+ return ((x0 < x1
+ and (x >= x0 and x <= x1))
+ or (x >= x1 and x <= x0))
def containsy(self, y):
- ymin, ymax = self.intervaly
- return ((ymin < ymax
- and (y >= ymin and y <= ymax))
- or (y >= ymax and y <= ymin))
+ y0, y1 = self.intervaly
+ return ((y0 < y1
+ and (y >= y0 and y <= y1))
+ or (y >= y1 and y <= y0))
def contains(self, x, y):
return self.containsx(x) and self.containsy(y)
def overlaps(self, other):
- ax1, ay1, ax2, ay2 = self._get_lbrt()
- bx1, by1, bx2, by2 = other._get_lbrt()
+ ax1, ay1, ax2, ay2 = self._get_extents()
+ bx1, by1, bx2, by2 = other._get_extents()
if ax2 < ax1:
ax2, ax1 = ax1, ax2
@@ -289,24 +307,24 @@
(by1 > ay2))
def fully_containsx(self, x):
- xmin, xmax = self.intervalx
- return ((xmin < xmax
- and (x > xmin and x < xmax))
- or (x > xmax and x < xmin))
+ x0, x1 = self.intervalx
+ return ((x0 < x1
+ and (x > x0 and x < x1))
+ or (x > x1 and x < x0))
def fully_containsy(self, y):
- ymin, ymax = self.intervaly
- return ((ymin < ymax
- and (x > ymin and x < ymax))
- or (x > ymax and x < ymin))
+ y0, y1 = self.intervaly
+ return ((y0 < y1
+ and (x > y0 and x < y1))
+ or (x > y1 and x < y0))
def fully_contains(self, x, y):
return self.fully_containsx(x) \
and self.fully_containsy(y)
def fully_overlaps(self, other):
- ax1, ay1, ax2, ay2 = self._get_lbrt()
- bx1, by1, bx2, by2 = other._get_lbrt()
+ ax1, ay1, ax2, ay2 = self._get_extents()
+ bx1, by1, bx2, by2 = other._get_extents()
if ax2 < ax1:
ax2, ax1 = ax1, ax2
@@ -354,7 +372,7 @@
or b) a string: C for centered, S for bottom-center, SE for
bottom-left, E for left, etc.
- Optional arg container is the lbwh box within which the BBox
+ Optional arg container is the box within which the BBox
is positioned; it defaults to the initial BBox.
"""
if container is None:
@@ -413,10 +431,10 @@
"""
boxes = []
xf = [0] + list(args) + [1]
- l, b, r, t = self.lbrt
- w = r - l
+ x0, y0, x1, y1 = self._get_extents()
+ w = x1 - x0
for xf0, xf1 in zip(xf[:-1], xf[1:]):
- boxes.append(Bbox([[l + xf0 * w, b], [l + xf1 * w, t]]))
+ boxes.append(Bbox([[x0 + xf0 * w, y0], [x0 + xf1 * w, y1]]))
return boxes
def splity(self, *args):
@@ -429,10 +447,10 @@
"""
boxes = []
yf = [0] + list(args) + [1]
- l, b, r, t = self.lbrt
- h = t - b
+ x0, y0, x1, y1 = self._get_extents()
+ h = y1 - y0
for yf0, yf1 in zip(yf[:-1], yf[1:]):
- boxes.append(Bbox([[l, b + yf0 * h], [r, b + yf1 * h]]))
+ boxes.append(Bbox([[x0, y0 + yf0 * h], [x1, y0 + yf1 * h]]))
return boxes
def count_contains(self, vertices):
@@ -444,12 +462,12 @@
if len(vertices) == 0:
return 0
vertices = npy.asarray(vertices)
- xmin, ymin, xmax, ymax = self._get_lbrt()
- dxmin = npy.sign(vertices[:, 0] - xmin)
- dymin = npy.sign(vertices[:, 1] - ymin)
- dxmax = npy.sign(vertices[:, 0] - xmax)
- dymax = npy.sign(vertices[:, 1] - ymax)
- inside = (abs(dxmin + dxmax) + abs(dymin + dymax)) <= 2
+ x0, y0, x1, y1 = self._get_extents()
+ dx0 = npy.sign(vertices[:, 0] - x0)
+ dy0 = npy.sign(vertices[:, 1] - y0)
+ dx1 = npy.sign(vertices[:, 0] - x1)
+ dy1 = npy.sign(vertices[:, 1] - y1)
+ inside = (abs(dx0 + dx1) + abs(dy0 + dy1)) <= 2
return N.sum(inside)
def count_overlaps(self, bboxes):
@@ -458,7 +476,7 @@
bboxes is a sequence of Bbox objects
"""
- ax1, ay1, ax2, ay2 = self._get_lbrt()
+ ax1, ay1, ax2, ay2 = self._get_extents()
if ax2 < ax1:
ax2, ax1 = ax1, ax2
if ay2 < ay1:
@@ -466,7 +484,7 @@
count = 0
for bbox in bboxes:
- # bx1, by1, bx2, by2 = bbox._get_lbrt() ... inlined...
+ # bx1, by1, bx2, by2 = bbox._get_extents() ... inlined...
bx1, by1, bx2, by2 = bbox.get_points().flatten()
if bx2 < bx1:
bx2, bx1 = bx1, bx2
@@ -534,21 +552,21 @@
if len(bboxes) == 1:
return bboxes[0]
- xmin = npy.inf
- ymin = npy.inf
- xmax = -npy.inf
- ymax = -npy.inf
+ x0 = npy.inf
+ y0 = npy.inf
+ x1 = -npy.inf
+ y1 = -npy.inf
for bbox in bboxes:
points = bbox.get_points()
xs = points[:, 0]
ys = points[:, 1]
- xmin = min(xmin, npy.min(xs))
- ymin = min(ymin, npy.min(ys))
- xmax = max(xmax, npy.max(xs))
- ymax = max(ymax, npy.max(ys))
+ x0 = min(x0, npy.min(xs))
+ y0 = min(y0, npy.min(ys))
+ x1 = max(x1, npy.max(xs))
+ y1 = max(y1, npy.max(ys))
- return Bbox.from_lbrt(xmin, ymin, xmax, ymax)
+ return Bbox.from_extents(x0, y0, x1, y1)
union = staticmethod(union)
@@ -557,10 +575,10 @@
"""
Create a new bounding box.
- points: a 2x2 numpy array of the form [[xmin, ymin], [xmax, ymax]]
+ points: a 2x2 numpy array of the form [[x0, y0], [x1, y1]]
If you need to create Bbox from another form of data, consider the
- class methods unit, from_lbwh and from_lbrt.
+ class methods unit, from_bounds and from_extents.
"""
BboxBase.__init__(self)
self._points = npy.asarray(points, npy.float_)
@@ -572,19 +590,19 @@
"""
Create a new unit BBox from (0, 0) to (1, 1).
"""
- return Bbox.from_lbrt(0., 0., 1., 1.)
+ return Bbox.from_extents(0., 0., 1., 1.)
unit = staticmethod(unit)
[EMAIL PROTECTED]
- def from_lbwh(left, bottom, width, height):
+ def from_bounds(left, bottom, width, height):
"""
Create a new Bbox from left, bottom, width and height.
"""
- return Bbox.from_lbrt(left, bottom, left + width, bottom + height)
- from_lbwh = staticmethod(from_lbwh)
+ return Bbox.from_extents(left, bottom, left + width, bottom + height)
+ from_bounds = staticmethod(from_bounds)
[EMAIL PROTECTED]
- def from_lbrt(*args):
+ def from_extents(*args):
"""
Create a new Bbox from left, bottom, right and top.
@@ -592,7 +610,7 @@
"""
points = npy.array(args, dtype=npy.float_).reshape(2, 2)
return Bbox(points)
- from_lbrt = staticmethod(from_lbrt)
+ from_extents = staticmethod(from_extents)
def __repr__(self):
return 'Bbox(%s)' % repr(self._points)
@@ -648,11 +666,12 @@
npy.float_)
self._minpos = minpos
else:
+ x0, y0, x1, y1 = self._get_extents()
points = npy.array(
- [[min(x.min(), self.xmin),
- min(y.min(), self.ymin)],
- [max(x.max(), self.xmax),
- max(y.max(), self.ymax)]],
+ [[min(x.min(), x0, x1),
+ min(y.min(), y0, y1)],
+ [max(x.max(), x0, x1),
+ max(y.max(), y0, y1)]],
npy.float_)
self._minpos = npy.minimum(minpos, self._minpos)
@@ -672,25 +691,25 @@
"""
return self.update_from_data(xy[:, 0], xy[:, 1], ignore)
- def _set_xmin(self, val):
+ def _set_x0(self, val):
self._points[0, 0] = val
self.invalidate()
- xmin = property(BboxBase._get_xmin, _set_xmin)
+ x0 = property(BboxBase._get_x0, _set_x0)
- def _set_ymin(self, val):
+ def _set_y0(self, val):
self._points[0, 1] = val
self.invalidate()
- ymin = property(BboxBase._get_ymin, _set_ymin)
+ y0 = property(BboxBase._get_y0, _set_y0)
- def _set_xmax(self, val):
+ def _set_x1(self, val):
self._points[1, 0] = val
self.invalidate()
- xmax = property(BboxBase._get_xmax, _set_xmax)
+ x1 = property(BboxBase._get_x1, _set_x1)
- def _set_ymax(self, val):
+ def _set_y1(self, val):
self._points[1, 1] = val
self.invalidate()
- ymax = property(BboxBase._get_ymax, _set_ymax)
+ y1 = property(BboxBase._get_y1, _set_y1)
def _set_min(self, val):
self._points[0] = val
@@ -735,7 +754,7 @@
def get_points(self):
"""
Set the points of the bounding box directly as a numpy array
- of the form: [[xmin, ymin], [xmax, ymax]].
+ of the form: [[x0, y0], [x1, y1]].
"""
self._invalid = 0
return self._points
@@ -743,7 +762,7 @@
def set_points(self, points):
"""
Set the points of the bounding box directly from a numpy array
- of the form: [[xmin, ymin], [xmax, ymax]]. No error checking
+ of the form: [[x0, y0], [x1, y1]]. No error checking
is performed, as this method is mainly for internal use.
"""
if npy.any(self._points != points):
@@ -2137,11 +2156,11 @@
from random import random
import timeit
- bbox = Bbox.from_lbrt(10., 15., 20., 25.)
- assert bbox.xmin == 10
- assert bbox.ymin == 15
- assert bbox.xmax == 20
- assert bbox.ymax == 25
+ bbox = Bbox.from_extents(10., 15., 20., 25.)
+ assert bbox.x0 == 10
+ assert bbox.y0 == 15
+ assert bbox.x1 == 20
+ assert bbox.y1 == 25
assert npy.all(bbox.min == [10, 15])
assert npy.all(bbox.max == [20, 25])
@@ -2160,18 +2179,18 @@
assert bbox.bounds == (11, 16, 10, 10)
- bbox.xmin = 12
- bbox.ymin = 17
- bbox.xmax = 22
- bbox.ymax = 27
+ bbox.x0 = 12
+ bbox.y0 = 17
+ bbox.x1 = 22
+ bbox.y1 = 27
assert bbox.bounds == (12, 17, 10, 10)
- bbox = Bbox.from_lbwh(10, 11, 12, 13)
+ bbox = Bbox.from_bounds(10, 11, 12, 13)
assert bbox.bounds == (10, 11, 12, 13)
bbox_copy = copy.deepcopy(bbox)
- assert (bbox.lbrt == bbox_copy.lbrt).all()
+ assert (bbox.extents == bbox_copy.extents).all()
bbox_copy.max = (14, 15)
assert bbox.bounds == (10, 11, 12, 13)
assert bbox_copy.bounds == (10, 11, 4, 4)
@@ -2180,7 +2199,7 @@
bbox2 = Bbox([[30., 35.], [40., 45.]])
trans = BboxTransform(bbox1, bbox2)
bbox3 = bbox1.transformed(trans)
- assert (bbox3.lbrt == bbox2.lbrt).all()
+ assert (bbox3.extents == bbox2.extents).all()
translation = Affine2D().translate(10, 20)
assert translation.to_values() == (1, 0, 0, 1, 10, 20)
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins