Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

flesh out some documentation

  • Loading branch information...
commit 969ca4f13629b77fcdaac68ad1f8a9893ce63325 1 parent 9407d8c
Rich Wareham authored
3  src/foldbeam/core.py
@@ -72,6 +72,7 @@ def __init__(self, geometry):
72 72
73 73 self.geometry = geometry
74 74
  75 + @property
75 76 def envelope(self):
76 77 """Calculate the bounding axis-aligned envelope which entirely contains this boundary.
77 78
@@ -203,7 +204,7 @@ def transform_to(self, other_spatial_reference, src_seg_len=None, dst_seg_len=No
203 204
204 205 """
205 206 return boundary_from_envelope(self). \
206   - transform_to(other_spatial_reference, src_seg_len, dst_seg_len).envelope()
  207 + transform_to(other_spatial_reference, src_seg_len, dst_seg_len).envelope
207 208
208 209 def __repr__(self):
209 210 return 'Envelope(%f,%f,%f,%f)' % (self.left, self.right, self.top, self.bottom)
41 src/foldbeam/graph.py
@@ -99,6 +99,33 @@ class OutputPad(Pad):
99 99 A strong reference to this pad's container or :py:const:`None` if the container was not set or has been garbage
100 100 collected.
101 101
  102 + .. py:data:: damaged
  103 +
  104 + A signal which can be connected to to be notified when the contents which can be pulled from this pad have
  105 + changed. Connect to it by passing a callable to the :py:meth:`damaged.connect` method::
  106 +
  107 + def damage_cb(boundary):
  108 + recalculate_envelope(boundary.envelope)
  109 +
  110 + # ... pad is the OutputPad of interest
  111 + pad.damaged.connect(damage_cb)
  112 +
  113 + The callable should accept a single parameter which is a :py:class:`Boundary` specifying the geographic area in
  114 + which the output has changed. This can be :py:const:`None` in which case it is assumed that the output should
  115 + always be pulled from.
  116 +
  117 + To notify listeners that an :py:class:`OutputPad` had new data, call the :py:attr:`damaged` signal directly::
  118 +
  119 + # ... pad is the OutputPad of interest
  120 +
  121 + # Notify any listeners that a specific region of the pad has changed:
  122 + boundary = Boundary(
  123 + # ...
  124 + )
  125 + pad.damaged(boundary)
  126 +
  127 + # Notify any listeners that all regions of the pad have changed:
  128 + pad.damaged(None)
102 129 """
103 130 def __init__(self, type_, container, name, pull):
104 131 super(OutputPad, self).__init__(type_, container, name)
@@ -108,11 +135,6 @@ def __init__(self, type_, container, name, pull):
108 135 def __call__(self, **kwargs):
109 136 return self._pull(**kwargs)
110 137
111   - def notify_damage(self, envelope):
112   - """Push a region which has been invalidated."""
113   -
114   - self.damaged(envelope)
115   -
116 138 class PadCollection(collections.OrderedDict):
117 139 """A collection of pads which can be iterated over and indexed like a dictionary with the wrinkle that pads are
118 140 returned in the order they are added.
@@ -201,8 +223,13 @@ def add_output(self, name, type_, pad_cb):
201 223 self.outputs[name] = OutputPad(type_, self, name, pad_cb)
202 224
203 225 def can_connect(src_pad, dst_pad):
204   - """Checks if the types of two pads are compatible for connection."""
205   -
  226 + """
  227 + Checks if the types of two pads are compatible for connection. Currently this simply checks that
  228 + :py:attr:`src_pad.type` is the same object as :py:attr:`dst_pad.type`. Should a more sophisticated type-munging
  229 + scheme be added, this function will be updated and so this function should be used in preference to checking the
  230 + types directly.
  231 +
  232 + """
206 233 if src_pad is None or dst_pad is None:
207 234 return False
208 235
6 src/foldbeam/tests.py
@@ -251,18 +251,18 @@ def damage_cb(d):
251 251 env2 = core.Envelope(0,0,2,2,self.bng_srs)
252 252 self.assertIsNotNone(env2)
253 253
254   - e.notify_damage(env1)
  254 + e.damaged(env1)
255 255 self.assertEqual(len(damages), 1)
256 256 self.assertEqual(damages[-1], env1)
257 257 self.assertNotEqual(damages[-1], env2)
258 258
259   - e.notify_damage(env2)
  259 + e.damaged(env2)
260 260 self.assertEqual(len(damages), 2)
261 261 self.assertEqual(damages[-1], env2)
262 262 self.assertNotEqual(damages[-1], env1)
263 263
264 264 e.damaged.disconnect(damage_cb)
265   - e.notify_damage(env1)
  265 + e.damaged(env1)
266 266 self.assertEqual(len(damages), 2)
267 267 self.assertEqual(damages[-1], env2)
268 268 self.assertNotEqual(damages[-1], env1)

0 comments on commit 969ca4f

Please sign in to comment.
Something went wrong with that request. Please try again.