Commits

German Larrain committed 3950a74

tests: no code changes, just whitespace, docstrings and comments formatting
according to PEPs 8 and 257.

Comments (0)

Files changed (7)

tests/external-libs/TrimeshCollision.py

 #!/usr/bin/env python
 
-# Created on 2012.01.15
-#
-# @author: german
+"""Tests the collision of an sphere with a trimesh.
 
-# TODO: update the rotation in the visualization
+It does NOT use ARS or depend on it in any way.
 
 """
-Tests the collision of an sphere with a trimesh.
-It does NOT use ARS or depend on it in any way.
-"""
-
 import math
 from random import random, choice
 
 import ode
 import vtk
 
+# TODO: update the rotation in the visualization
+
+
 TIMER_PERIOD = 50 # milliseconds
 TIMER_EVENT = 'TimerEvent'
 win_size = (1000,600)
 floor = None
 contactGroup = ode.JointGroup()
 
+
 def nearCallback(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."""
+	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
 
 		j = ode.ContactJoint(world, contactgroup, c)
 		j.attach(geom1.getBody(), geom2.getBody())
 
+
 def createOdeWorld(gravity=(0.0,-9.81,0.0), erp=0.8, cfm=1E-4):
 	# create an ODE world object
 	world = ode.World()
 	world.setCFM(cfm)
 	return world
 
+
 def constant_heightfield(num_x, num_z, height=0.0):
 	"""A height field where all the values are the same"""
 	# that x and z are integers, not floats, does not matter
 			verts.append((x, height, z))
 	return verts
 
+
 def random_heightfield(num_x, num_z, scale=1.0):
 	"""Based on 'Edward Dale - Snowballs: An experiment in Winter frivolity
 	(2006).' http://goo.gl/cyaZs
-	A height field where values are completely random."""
+	A height field where values are completely random.
+
+	"""
 	# that x and z are integers, not floats, does not matter
 	verts=[]
 	for x in range(num_x):
 			verts.append( (x,random()*scale,z) )
 	return verts
 
+
 def sinusoidal_heightfield(num_x, num_z, height_scale=1.0, frequency_x=1.0):
 	"""Creates the vertices corresponding to a sinusoidal heightfield along the
 	X axis. The height_scale controls the amplitude of the wave, and
-	frequency_x its frequency."""
+	frequency_x its frequency.
+
+	"""
 	# TODO: fix the frequency units
 	verts=[]
 	for x in range(num_x):
 			verts.append( (x, math.sin(x * frequency_x)*height_scale, z) )
 	return verts
 
+
 def get_faces(num_x, num_z):
 	"""Based on 'Edward Dale - Snowballs: An experiment in Winter frivolity
 	(2006).' http://goo.gl/cyaZs
 	A height field is rectilinear, but the faces are only going to be
 	triangular. This method chooses 3 vertices out of each 4 to make a face and
 	the other set to make another triangular face. This is done randomly to
-	eliminate artifacts."""
+	eliminate artifacts.
+
+	"""
 	faces=[]
 	for z in range(num_z-1):
 		for x in range(num_x-1):
 			# faces += [( three,two,one ),( three,four,two )] #( three,two,one )
 	return faces
 
+
 #noinspection PyUnusedLocal
 def timerCallback(obj, event):
 	performSimStepsPerFrame()
 	iren = obj
 	iren.GetRenderWindow().Render()
 
+
 def performSimStepsPerFrame():
 
 	global stepsPerFrame, world, contactGroup, numIter, simTime
 		# Remove all contact joints
 		contactGroup.empty()
 
+
 def swap_faces_indices(faces):
 	"""Faces had to change their indices to work with ODE. With the initial
 	'get_faces', the normal to the triangle defined by the 3 vertices pointed
 	(following the right-hand rule) downwards. Swapping the third with the
-	first index, now the triangle normal pointed upwards."""
+	first index, now the triangle normal pointed upwards.
 
+	"""
 	new_faces = []
 	for face in faces:
 		new_faces.append((face[2], face[1], face[0]))

tests/graphics_adapters.py

-
-# Created on 2012.01.07
-#
-# @author: german
-
 from ars.graphics.adapters import vtk, VtkAdapter, Axes, Box, Capsule, Cone, Cylinder, Sphere
 from ars.graphics.adapters import ScreenshotRecorder
 
+
 def test_adapter_and_objects():
 	gAdapter = VtkAdapter()
 	gAdapter.create_window("test")
-	
+
 	axes1 = Axes()
 	axes2 = Axes(cylinder_radius=0.02)
 	box = Box(size=(0.5,1.0,2.0), position=(2,2,2))
 	sphere = Sphere(0.5, center=(-2,-2,-2))
 	cyl = Cylinder(length=2, radius=0.25, center=(1,-1,1)) #, orientation=(mut.pi/3,mut.pi/3,mut.pi/3))
 	caps = Capsule(length=2, radius=0.25, center=(-1,-1,-1)) 
-	
+
 	gAdapter.add_object(axes1)
 	gAdapter.add_object(axes2)
 	gAdapter.add_object(box)
 	gAdapter.add_object(sphere)
 	gAdapter.add_object(cyl)
 	gAdapter.add_object(caps)
-	
+
 	# initialized as identity matrix
 	vtk_matrix1 = vtk.vtkMatrix4x4()
 	vtk_matrix2 = vtk.vtkMatrix4x4()
 	vtk_matrix1.SetElement(0, 3, 1)
 	vtk_matrix1.SetElement(1, 3, 0)
 	vtk_matrix1.SetElement(2, 3, 4)
-	
+
 	# axes permutation
 	vtk_matrix2.Zero(); vtk_matrix2.SetElement(3, 3, 1) # don't forget to set the lower left corner value!
 	vtk_matrix2.SetElement(0, 2, 1)
 	vtk_matrix2.SetElement(1, 0, 1)
 	vtk_matrix2.SetElement(2, 1, 1)
-	
+
 	# corresponds to a rotation -74 degrees aprox. around the axis 1/3*(-1,2,2)
 	vtk_matrix3.SetElement(0, 0, 0.36)
 	vtk_matrix3.SetElement(0, 1, 0.48)
 	vtk_matrix3.SetElement(2, 0, 0.48)
 	vtk_matrix3.SetElement(2, 1, 0.64)
 	vtk_matrix3.SetElement(2, 2, 0.60)
-	
+
 	#box.bodyObject.SetUserMatrix(vtk_matrix) # concatenates the transform
 	sphere.actor.PokeMatrix(vtk_matrix1) # sets the final transform
 	cone.actor.PokeMatrix(vtk_matrix2)
 	axes1.actor.PokeMatrix(vtk_matrix3)
 	caps.actor.PokeMatrix(vtk_matrix3)
-	
+
 	gAdapter.start_window()
 
+
 def test_screenshot_recorder():
-	
+
 	global i
 	gAdapter = VtkAdapter()
 	gAdapter.create_window("test")
 	sphere = Sphere(0.5, center=(-2,-2,-2))
 	gAdapter.add_object(sphere)
-	
+
 	#recorder = ScreenshotRecorder()
 	recorder = ScreenshotRecorder('test', gAdapter)
 	i = 0
 		#recorder.set_input(gAdapter.renWin)
 		i += 1
 		recorder.write(i)
-	
+
 	gAdapter.start_window(on_key_press_callback=on_key_press)
 
 if __name__ == '__main__':
 	test_adapter_and_objects()
-	test_screenshot_recorder()
+	test_screenshot_recorder()
-
-# Created on 2012.03.09
-#
-# @author: german
 import math
 
 from ars.app import Program
 	def create_sim_objects(self):
 		self.sim.add_sphere(0.5, (1,10,1), density=1) # radius, center, density
 
+
 class BodyTest2(Program):
 	def create_sim_objects(self):
 		self.sim.add_cylinder(length=1.0, radius=1.0, center=(10,10,25), mass=4.67)
 
+
 class BodyTest3(Program):
 	def create_sim_objects(self):
 		self.sim.add_sphere(0.5, (1,10,1), mass=1) # radius, center, mass
 
+
 def run_body_test():
 
 	# body.get_center_of_gravity() is always (0,0,0) unless changed explicitly
 	print(body.get_position())
 	print('%s / %s' % (1.0 * sphere_volume(0.5), body.get_mass()))
 	print(body.get_inertia_tensor())
-	
+
 	sim_program = BodyTest2()
 	sim_program.start()
 	body = sim_program.sim.get_object("cylinder").body
 	print(body.get_position())
 	print('%s / %s' % (4.67, body.get_mass()))
 	print(body.get_inertia_tensor())
-	
+
 	sim_program = BodyTest3()
 	sim_program.start()
 	body = sim_program.sim.get_object("sphere").body
 	print(body.get_inertia_tensor())
 
 if __name__ == '__main__':
-	run_body_test()
+	run_body_test()
+import ars.model.geometry.base as sh
 
 
-# Created on 2012.01.30
-#
-# @author: german
-#
-
-import ars.model.geometry.base as sh
-
 def test_get_heightfield_faces():
 	print(sh.Trimesh.get_heightfield_faces(5, 5))
 
 if __name__ == '__main__':
-	test_get_heightfield_faces()
+	test_get_heightfield_faces()

tests/utils_containers.py

+import ars.utils.containers as cont
 
-# Created on 2012.05.03
-#
-# @author: german
-
-import ars.utils.containers as cont
 
 def test_Queue():
 	q = cont.Queue()
 	print(q.count())
 
 if __name__ == "__main__":
-	test_Queue()
+	test_Queue()

tests/utils_generic.py

+import ars.utils.generic as gen
 
-# Created on 2012.05.03
-#
-# @author: german
-
-import ars.utils.generic as gen
 
 def test_get_current_epoch_time():
 	print(repr(gen.get_current_epoch_time()))

tests/utils_mathematical.py

-
-# Created on 2011.12.01
-#
-# @author: german
-
 import ars.utils.mathematical as mut
 
 
 	print(_vector_diff_length(mut.cross_product(Z, X), Y))
 	print(_vector_diff_length(mut.cross_product(Y, Z), X))
 
-
 if __name__ == "__main__":
 
 	test_matrix_multiply()