1. Manfred Moitzi
  2. geoalg

Commits

Manfred Moitzi  committed 41227de

Python3; relative import; doc edits

  • Participants
  • Parent commits 428bb75
  • Branches default

Comments (0)

Files changed (4)

File geoalg/clothoid.py

View file
  • Ignore whitespace
 # Created: 26.03.2010
 # License: GPLv3
 
+import sys
+# for python3
+if sys.version_info[0] > 2:
+    xrange = range
+
 import math
 
 class Clothoid(object):

File geoalg/polybezier.py

View file
  • Ignore whitespace
 from .nurbs import Bezier4P
 from .vector2d import Vec2, NULLVEC
 from .util import almost_equal_vectors
-from ray import Ray2D
+from .ray import Ray2D
 import math
 
 class PolyBezier(object):

File geoalg/util.py

View file
  • Ignore whitespace
 DOUBLE_PI = 2. * math.pi
 
 def equals_almost(v1, v2, places=7):
-    """compare two float values
-       places: significant decimal places
+    """ Compares two float values with 'places' significant decimal places.
     """
     return round(v1, places) == round(v2, places)
+almost_equal = equals_almost
 
-almost_equal = equals_almost
 def almost_equal_vectors(v1, v2, places=6):
     return all(almost_equal(a, b, places) for a, b in zip(v1, v2))
 
-def normalize_angle(angle): # 0 <= angle <= 2*pi
+def normalize_angle(angle):
+    """ Calibrates angle between 0 an 2*pi.
+    """
     angle = math.fmod(angle, DOUBLE_PI)
     if angle < 0:
         angle += DOUBLE_PI
             equals_almost(angle, THREE_PI_HALF, places))
 
 def get_angle(p1, p2):
-    """calc angle between the line p1-p2 and the x-axis
-    input: points as tuples
-    result: angle in radians
+    """ Returns angle between the line p1-p2 and the x-axis in radians.
     """
     dx = p1[0] - p2[0]
     dy = p1[1] - p2[1]
     return math.atan2(dy, dx)
 
 def distance(p1, p2):
-    """calc distance between p1 and p2
+    """ Distance between p1 and p2.
     """
     dx = p1[0] - p2[0]
     dy = p1[1] - p2[1]
     return (dx**2 + dy**2 + dz**2) ** .5
 
 def mid_point(p1, p2):
-        """ calculates the middle point between p1 and p2
-        input: point as Point2D
-        return: Point2D
+        """ Returns the midpoint between p1 and p2 as 3-tuple.
         """
         x = (p1[0] + p2[0]) / 2.0
         y = (p1[1] + p2[1]) / 2.0
             z = (p1[2] + p2[2]) / 2.0
         except IndexError:
             z = 0.
-        return (x, y, z)
+        return x, y, z
 
 def right_of_line(point, p1, p2):
-    """ True if the point self is right of the line p1 -> p2
+    """ Returns True if the point self is right of the line p1 -> p2.
     """
     return not left_of_line(point, p1, p2)
 
 def left_of_line(point, p1, p2):
-    """ True if the point self is left of the line p1 -> p2
+    """ Returns True if the point self is left of the line p1 -> p2.
     """
     # check if a and b are on the same vertical line
     if p1[0] == p2[0]:

File polybezier_examples.py

View file
  • Ignore whitespace
 import svgwrite
 from dxfwrite import DXFEngine as dxf
 
+import random
 import math
 
 from geoalg import PolyBezier
     dwg.add(dxf.polyline(points, color=1))
     add_defpoints()
     add_tangents()
-    add_curvepoint((22, 16))
-    add_curvepoint((7, 13))
-    add_curvepoint((35, 12))
+    for _ in range(10):
+        add_curvepoint((random.randint(0, 50), random.randint(0, 30)))
     dwg.save()
 
 def print_bezier_data(filename, bezier):