Detect whether r1, r2 are neighbors. Defined as: The minimum distance between points of r1 and points of r2 is not larger than some delta. This check supports empty rect-likes and thus also lines. Note: This type of check is MUCH faster than native
(r1, r2)
| 2264 | clip = prect |
| 2265 | |
| 2266 | def are_neighbors(r1, r2): |
| 2267 | """Detect whether r1, r2 are neighbors. |
| 2268 | |
| 2269 | Defined as: |
| 2270 | The minimum distance between points of r1 and points of r2 is not |
| 2271 | larger than some delta. |
| 2272 | |
| 2273 | This check supports empty rect-likes and thus also lines. |
| 2274 | |
| 2275 | Note: |
| 2276 | This type of check is MUCH faster than native Rect containment checks. |
| 2277 | """ |
| 2278 | if ( # check if x-coordinates of r1 are within those of r2 |
| 2279 | r2.x0 - snap_x <= r1.x0 <= r2.x1 + snap_x |
| 2280 | or r2.x0 - snap_x <= r1.x1 <= r2.x1 + snap_x |
| 2281 | ) and ( # ... same for y-coordinates |
| 2282 | r2.y0 - snap_y <= r1.y0 <= r2.y1 + snap_y |
| 2283 | or r2.y0 - snap_y <= r1.y1 <= r2.y1 + snap_y |
| 2284 | ): |
| 2285 | return True |
| 2286 | |
| 2287 | # same check with r1 / r2 exchanging their roles (this is necessary!) |
| 2288 | if ( |
| 2289 | r1.x0 - snap_x <= r2.x0 <= r1.x1 + snap_x |
| 2290 | or r1.x0 - snap_x <= r2.x1 <= r1.x1 + snap_x |
| 2291 | ) and ( |
| 2292 | r1.y0 - snap_y <= r2.y0 <= r1.y1 + snap_y |
| 2293 | or r1.y0 - snap_y <= r2.y1 <= r1.y1 + snap_y |
| 2294 | ): |
| 2295 | return True |
| 2296 | return False |
| 2297 | |
| 2298 | def clean_graphics(npaths=None): |
| 2299 | """Detect and join rectangles of "connected" vector graphics.""" |
no outgoing calls
no test coverage detected
searching dependent graphs…