API Reference for Enthought Tool Suite 3.2.0
Define a few simple math functions to avoid dependency on numpy.
The functions provide facilities for clipping a value to a range as well as a number of functions for that treat 2 element lists as vectors. The main purpose of this latter set is for testing the distance of a point from a line (useful in hit testing).
Clip value so that it is betwen low and high values.
>>> clip(5, 0, 10) 5 >>> clip(-5, 0, 10) 0 >>> clip(15, 0, 10) 10
Calculate the distance of the mouse from lint pt1->pt2 All three inputs are 2 element lists of x,y pairs.
>>> distance_to_line([0,0],[1,1],[.5,.5]) 0.0 >>> distance_to_line([0,0],[1,1],[0,0]) 0.0 >>> distance_to_line([0,0],[1,1],[0,1]) 0.70710678118654757 >>> distance_to_line([10,1],[20,5],[15,14]) 10.213243599737853
Calculate the dot product of two 2D vectors.
pt1 and pt2 can be any sort of indexed sequence.
>>> dot([0,1], [1,0]) # orthogonal vectors have zero projection. 0.0 >>> dot([1,1], [1,0]) # 45 degree angle has projection of 1. 1.0
Calculate the magnitude of a vector.
>>> mag([3,4]) 5.0 >>> mag([3,-4]) # ignore 5.0
Returns if the point x,y is in the box.
Inclusive on the lower end, excluive on the upper end.
tolerance -- default 0. It expands the box the given amount.
>>> point_in_box([0,0], [1,1], [.5,.5]) True >>> point_in_box([0,0], [1,1], [1.1,.5]) False
Subtract one 2D vector from another.
>>> subtract([2,1],[.5,.1]) [1.5, 0.90000000000000002]
| Local name | Refers to |
|---|---|
| sqrt | math.sqrt |
© Copyright 2002-2009 Enthought, Inc.