~ubuntu-branches/debian/sid/pyx/sid

« back to all changes in this revision

Viewing changes to pyx/normpath.py

  • Committer: Bazaar Package Importer
  • Author(s): Stuart Prescott
  • Date: 2011-05-20 00:13:52 UTC
  • mto: (9.1.1 experimental)
  • mto: This revision was merged to the branch mainline in revision 8.
  • Revision ID: james.westby@ubuntu.com-20110520001352-odcuqpdezuusbbw1
Tags: upstream-0.11.1
Import upstream version 0.11.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- coding: ISO-8859-1 -*-
2
 
#
3
 
#
4
 
# Copyright (C) 2002-2006 J�rg Lehmann <joergl@users.sourceforge.net>
 
1
# -*- encoding: utf-8 -*-
 
2
#
 
3
#
 
4
# Copyright (C) 2002-2011 Jörg Lehmann <joergl@users.sourceforge.net>
5
5
# Copyright (C) 2003-2006 Michael Schindler <m-schindler@users.sourceforge.net>
6
 
# Copyright (C) 2002-2006 Andr� Wobst <wobsta@users.sourceforge.net>
 
6
# Copyright (C) 2002-2011 André Wobst <wobsta@users.sourceforge.net>
7
7
#
8
8
# This file is part of PyX (http://pyx.sourceforge.net/).
9
9
#
21
21
# along with PyX; if not, write to the Free Software
22
22
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
23
23
 
24
 
from __future__ import nested_scopes
25
 
 
26
24
import math
27
 
try:
28
 
    from math import radians, degrees
29
 
except ImportError:
30
 
    # fallback implementation for Python 2.1
31
 
    def radians(x): return x*math.pi/180
32
 
    def degrees(x): return x*180/math.pi
33
 
 
34
25
import mathutils, path, trafo, unit
35
26
import bbox as bboxmodule
36
27
 
37
 
try:
38
 
    sum([])
39
 
except NameError:
40
 
    # fallback implementation for Python 2.2 and below
41
 
    def sum(list):
42
 
        return reduce(lambda x, y: x+y, list, 0)
43
 
 
44
 
try:
45
 
    enumerate([])
46
 
except NameError:
47
 
    # fallback implementation for Python 2.2 and below
48
 
    def enumerate(list):
49
 
        return zip(xrange(len(list)), list)
50
28
 
51
29
# use new style classes when possible
52
30
__metaclass__ = type
317
295
        return normline_pt(self.x1_pt, self.y1_pt, self.x0_pt, self.y0_pt)
318
296
 
319
297
    def rotation(self, params):
320
 
        return [trafo.rotate(degrees(math.atan2(self.y1_pt-self.y0_pt, self.x1_pt-self.x0_pt)))]*len(params)
 
298
        return [trafo.rotate(math.degrees(math.atan2(self.y1_pt-self.y0_pt, self.x1_pt-self.x0_pt)))]*len(params)
321
299
 
322
300
    def segments(self, params):
323
301
        if len(params) < 2:
334
312
        return result
335
313
 
336
314
    def trafo(self, params):
337
 
        rotate = trafo.rotate(degrees(math.atan2(self.y1_pt-self.y0_pt, self.x1_pt-self.x0_pt)))
 
315
        rotate = trafo.rotate(math.degrees(math.atan2(self.y1_pt-self.y0_pt, self.x1_pt-self.x0_pt)))
338
316
        return [trafo.translate_pt(*at_pt) * rotate
339
317
                for param, at_pt in zip(params, self.at_pt(params))]
340
318
 
589
567
            # the length of the line. For curves we want this "relative speed" to be higher than
590
568
            # _minrelspeed:
591
569
            if math.hypot(tdx_pt, tdy_pt)/approxarclen > _minrelspeed:
592
 
                result.append(trafo.rotate(degrees(math.atan2(tdy_pt, tdx_pt))))
 
570
                result.append(trafo.rotate(math.degrees(math.atan2(tdy_pt, tdx_pt))))
593
571
            else:
594
572
                # Note that we can't use the rule of l'Hopital here, since it would
595
573
                # not provide us with a sign for the tangent. Hence we wouldn't
1728
1706
        if not self.normsubpaths:
1729
1707
            raise NormpathException("cannot join to empty path")
1730
1708
        if not other.normsubpaths:
1731
 
            raise PathException("cannot join empty path")
 
1709
            raise NormpathException("cannot join empty path")
1732
1710
        self.normsubpaths[-1].join(other.normsubpaths[0])
1733
1711
        self.normsubpaths.extend(other.normsubpaths[1:])
1734
1712
 
1895
1873
        return self._tangent(self._convertparams(params, self.arclentoparam_pt), length_pt)
1896
1874
    tangent_pt = _valueorlistmethod(tangent_pt)
1897
1875
 
1898
 
    def tangent(self, params, length):
 
1876
    def tangent(self, params, length=1):
1899
1877
        """return tangent vector of path at param(s) or arc length(s)
1900
1878
 
1901
1879
        If length is not None, the tangent vector will be scaled to