1. NodeBox 1
    1. Homepage
    2. NodeBox 3Node-based app for generative design and data visualization
    3. NodeBox OpenGLHardware-accelerated cross-platform graphics library
    4. NodeBox 1Generate 2D visuals using Python code (Mac OS X only)
  2. Gallery
  3. Documentation
  4. Forum
  5. Blog

Geometric boundaries for any path

Posted by A. Mao on Jan 30, 2008

Hello,

Is there an easy way to get geometric boundaries for any given path?


 
Posted by Mark M on Jan 30, 2008

You can get the rectangular bounds of a bezier path by calling the bounds method on the underlying nsbezierpath object. This may not be a documented feature, so there is guarantee that it will always work. This will give you the rectangular bounds.

Probably easier with an example:

nofill()
stroke(0)
autoclosepath(close=False)
 
## Create Path
beginpath(87,200)
curveto(347, 32, 144, 588, 409, 326)
p = endpath()
 
## call bounds method on underlying cocoa path object
## this returns an NSRect which can be treated like a 2x2 array 
## representing the top left-hand corner and the width and height
bounds =  p._nsBezierPath.bounds()
rect(bounds[0][0], bounds[0][1], bounds[1][0], bounds[1][1])



Posted by A. Mao on Jan 31, 2008

Thank you!