Commits

German Larrain  committed 3ae8c3e

external-libs.ray_collision: no code changes, just whitespace, docstrings and
comments formatting according to PEPs 8 and 257.

  • Participants
  • Parent commits 2a8b3b8

Comments (0)

Files changed (1)

File tests/external-libs/ray_collision.py

 #!/usr/bin/env python
 
-# Created on 2012.05.09
-#
-# @author: german
+"""Tests the collision of 2 spheres with a ray.
+
+It does not depend on the core of ARS; it uses only the utilities.
 
 """
-Tests the collision of 2 spheres with a ray.
-It does not depend on the core of ARS; it uses only the utilities.
-"""
-
 import math
 
 import ode
 #===========================================================================
 # aux functions
 #===========================================================================
+
+
 def length3(vector):
 	"""Returns the length of a 3-dimensions vector"""
 	return math.sqrt(vector[0]**2 + vector[1]**2 + vector[2]**2)
 
+
 def add3(vector1, vector2):
 	"""Returns the sum of 3-vectors vector1 and vector2"""
 	return (vector1[0] + vector2[0], vector1[1] + vector2[1], vector1[2] + vector2[2])
 
+
 def sub3(vector1, vector2):
 	"""Returns the difference between 3-vectors vector1 and vector2"""
 	return (vector1[0] - vector2[0], vector1[1] - vector2[1], vector1[2] - vector2[2])
 
+
 def timerCallback(obj, event):
 	performSimStepsPerFrame()
 	pos = ball_body.getPosition()
 #===========================================================================
 # collisions functions
 #===========================================================================
+
+
 def handle_ray_collision(ray, other_geom, contact):
 	ray_pos = ray.getPosition()
 	(pos, normal, depth, geom1, geom2) = contact.getContactGeomParams()
 	distance = length3(sub3(pos,ray_pos))
-	print('ray collision between %s and %s. distance: %f' % (ray,other_geom,distance))
+	print('ray collision between %s and %s. distance: %f' %
+		(ray,other_geom,distance))
+
 
 def is_geom_ray(geom):
-	"""Is `geom` a ray?"""
+	"""Check if `geom` if geom is a ray."""
 	return isinstance(geom, ode.GeomRay)
 
+
 def are_geoms_connected(geom1, geom2):
-	"""
-	Are `geom1` and `geom2` connected (through the bodies they are attached to)?
+	"""Check if ``geom1`` and ``geom2`` connected.
+
+	(through the bodies they are attached to)
+
 	"""
 	return ode.areConnected(geom1.getBody(), geom2.getBody())
 
+
 def geoms_near_callback(args, geom1, geom2):
-	"""Callback function for the collide() method. This function checks if the
-	given geoms do collide and creates contact joints if they do."""
+	"""Callback function for the collide() method.
+
+	This function checks if the	given geoms do collide and creates contact
+	joints if they do.
+
+	"""
 	contactJointBounce = 0.2
 	contactJointMu = 500 # 0-5 = very slippery, 50-500 = normal, 5000 = very sticky
 
 #===========================================================================
 # sim functions
 #===========================================================================
+
+
 def createOdeWorld(gravity=(0.0,-9.81,0.0), erp=0.8, cfm=1E-4):
-	"""create and configure and ODE world object"""
+	"""Create and configure and ODE world object."""
 	world = ode.World()
 	world.setGravity(gravity)
 	world.setERP(erp)
 	world.setCFM(cfm)
 	return world
 
+
 def performSimStepsPerFrame():
 
 	global STEPS_PER_FRAME, world, contactGroup, num_iter, sim_time