← Back to team overview

yade-dev team mailing list archive

[Branch ~yade-dev/yade/trunk] Rev 1768: Workaround bug #416335; static members of Vector3 work only on instance, e.g. Vector3.ZERO will n...

 

------------------------------------------------------------
revno: 1768
committer: Václav Šmilauer <vaclav@flux>
branch nick: trunk
timestamp: Sat 2009-09-19 21:41:52 +0200
message:
  Workaround bug #416335; static members of Vector3 work only on instance, e.g. Vector3.ZERO will not work, you have to use Vector3().ZERO; changed all occurences in the code accordingly, update your scripts as well.\n2.Some undocumented and untested enhancements for parameter table (backwards compatible)
modified:
  py/miniWm3Wrap/miniWm3Wrap-funcs.ipp
  py/miniWm3Wrap/miniWm3Wrap-generate.py
  py/miniWm3Wrap/miniWm3Wrap.cpp
  py/pack.py
  py/tests/wrapper.py
  py/utils.py
  scripts/test/gts-random-pack-obb.py
  scripts/test/wm3-wrap.py


--
lp:yade
https://code.launchpad.net/~yade-dev/yade/trunk

Your team Yade developers is subscribed to branch lp:yade.
To unsubscribe from this branch go to https://code.launchpad.net/~yade-dev/yade/trunk/+edit-subscription.
=== modified file 'py/miniWm3Wrap/miniWm3Wrap-funcs.ipp'
--- py/miniWm3Wrap/miniWm3Wrap-funcs.ipp	2009-07-07 10:54:14 +0000
+++ py/miniWm3Wrap/miniWm3Wrap-funcs.ipp	2009-09-19 19:41:52 +0000
@@ -17,6 +17,15 @@
 int Quaternion_len(){return 4;}
 #undef IDX_CHECK
 
+#if 1
+	// workarounds for static methods; disabled for now, see comment in miniWm3Wrap-generate.py
+	#define _WORKAROUND(clss,member) clss clss##_##member(const clss& self){return clss::member;}
+	_WORKAROUND(Vector2r,ONE); _WORKAROUND(Vector2r,UNIT_X); _WORKAROUND(Vector2r,UNIT_Y); _WORKAROUND(Vector2r,ZERO);
+	_WORKAROUND(Vector3r,ONE); _WORKAROUND(Vector3r,UNIT_X); _WORKAROUND(Vector3r,UNIT_Y); _WORKAROUND(Vector3r,UNIT_Z); _WORKAROUND(Vector3r,ZERO);
+	_WORKAROUND(Quaternionr,IDENTITY); _WORKAROUND(Quaternionr,ZERO);
+	#undef _WORKAROUND
+#endif
+
 // automagic converter from tuple to Vector3r
 struct custom_Vector3r_from_tuple{
 	custom_Vector3r_from_tuple(){

=== modified file 'py/miniWm3Wrap/miniWm3Wrap-generate.py'
--- py/miniWm3Wrap/miniWm3Wrap-generate.py	2009-07-07 10:54:14 +0000
+++ py/miniWm3Wrap/miniWm3Wrap-generate.py	2009-09-19 19:41:52 +0000
@@ -32,6 +32,8 @@
 mb.decls(lambda d: 'Matrix3' in str(d) or 'Matrix2' in str(d) or 'Vector4' in str(d)).exclude()
 # exclude operator[] since we implement __getitem__/__setitem__ by ourselves
 mb.member_operators(lambda o: o.symbol=='[]').exclude()
+##
+
 
 # register manual wraps
 v2,v3,q4=mb.class_(lambda d: d.name=='Vector2<double>'),mb.class_(lambda d: d.name=='Vector3<double>'),mb.class_(lambda d: d.name=='Quaternion<double>')
@@ -39,6 +41,14 @@
 v3.add_registration_code('def("__len__",&::Vector3_len)   .staticmethod("__len__").def("__setitem__",&::Vector3_set_item)   .def("__getitem__",&::Vector3_get_item)   .def("__str__",&::Vector3_str)   .def("__repr__",&::Vector3_str)')
 q4.add_registration_code('def("__len__",&::Quaternion_len).staticmethod("__len__").def("__setitem__",&::Quaternion_set_item).def("__getitem__",&::Quaternion_get_item).def("__str__",&::Quaternion_str).def("__repr__",&::Quaternion_str)')
 
+## workarounds for def_readonly on static members
+# disabled, doesn't work on types (e.g. Vector3.ZERO), must pass instance (e.g. Vector3().ZERO)
+if 1:
+	mb.decls(lambda d: 'UNIT_' in str(d) or 'ZERO' in str(d) or 'IDENTITY' in str(d) or 'ONE' in str(d)).exclude()
+	v2.add_registration_code('.'.join('add_property("%s",::Vector2r_%s)'%(prop,prop) for prop in ('ZERO','UNIT_X','UNIT_Y','ONE')))
+	v3.add_registration_code('.'.join('add_property("%s",::Vector3r_%s)'%(prop,prop) for prop in ('ZERO','UNIT_X','UNIT_Y','UNIT_Z','ONE')))
+	q4.add_registration_code('.'.join('add_property("%s",::Quaternionr_%s)'%(prop,prop) for prop in ('ZERO','IDENTITY')))
+
 # arg0 and arg1 will be returned as tuple, instead of the references ToAxisAngle takes
 mb.member_functions('ToAxisAngle').add_transformation(FT.output(0),FT.output(1))
 # quaternion operations returning itself

=== modified file 'py/miniWm3Wrap/miniWm3Wrap.cpp'
--- py/miniWm3Wrap/miniWm3Wrap.cpp	2009-07-08 07:41:42 +0000
+++ py/miniWm3Wrap/miniWm3Wrap.cpp	2009-09-19 19:41:52 +0000
@@ -317,11 +317,10 @@
         Quaternion_exposer.def( bp::self == bp::self );
         Quaternion_exposer.def( bp::self > bp::self );
         Quaternion_exposer.def( bp::self >= bp::self );
-        Quaternion_exposer.def_readonly( "IDENTITY", Wm3::Quaternion< double >::IDENTITY );
-        Quaternion_exposer.def_readonly( "ZERO", Wm3::Quaternion< double >::ZERO );
         Quaternion_exposer.def( bp::self * bp::other< Wm3::Vector3< double > >() );
         Quaternion_exposer.def( bp::self_ns::str( bp::self ) );
         Quaternion_exposer.def("__len__",&::Quaternion_len).staticmethod("__len__").def("__setitem__",&::Quaternion_set_item).def("__getitem__",&::Quaternion_get_item).def("__str__",&::Quaternion_str).def("__repr__",&::Quaternion_str);
+        Quaternion_exposer.add_property("ZERO",::Quaternionr_ZERO).add_property("IDENTITY",::Quaternionr_IDENTITY);
     }
 
     { //::Wm3::Vector2< double >
@@ -495,15 +494,12 @@
         Vector2_exposer.def( bp::self == bp::self );
         Vector2_exposer.def( bp::self > bp::self );
         Vector2_exposer.def( bp::self >= bp::self );
-        Vector2_exposer.def_readonly( "ONE", Wm3::Vector2< double >::ONE );
-        Vector2_exposer.def_readonly( "UNIT_X", Wm3::Vector2< double >::UNIT_X );
-        Vector2_exposer.def_readonly( "UNIT_Y", Wm3::Vector2< double >::UNIT_Y );
-        Vector2_exposer.def_readonly( "ZERO", Wm3::Vector2< double >::ZERO );
         Vector2_exposer.staticmethod( "ComputeExtremes" );
         Vector2_exposer.staticmethod( "GenerateOrthonormalBasis" );
         Vector2_exposer.staticmethod( "Orthonormalize" );
         Vector2_exposer.def( bp::other< Real >() * bp::self );
         Vector2_exposer.def("__len__",&::Vector2_len)   .staticmethod("__len__").def("__setitem__",&::Vector2_set_item)   .def("__getitem__",&::Vector2_get_item)   .def("__str__",&::Vector2_str)   .def("__repr__",&::Vector2_str);
+        Vector2_exposer.add_property("ZERO",::Vector2r_ZERO).add_property("UNIT_X",::Vector2r_UNIT_X).add_property("UNIT_Y",::Vector2r_UNIT_Y).add_property("ONE",::Vector2r_ONE);
     }
 
     { //::Wm3::Vector3< double >
@@ -689,16 +685,12 @@
         Vector3_exposer.def( bp::self == bp::self );
         Vector3_exposer.def( bp::self > bp::self );
         Vector3_exposer.def( bp::self >= bp::self );
-        Vector3_exposer.def_readonly( "ONE", Wm3::Vector3< double >::ONE );
-        Vector3_exposer.def_readonly( "UNIT_X", Wm3::Vector3< double >::UNIT_X );
-        Vector3_exposer.def_readonly( "UNIT_Y", Wm3::Vector3< double >::UNIT_Y );
-        Vector3_exposer.def_readonly( "UNIT_Z", Wm3::Vector3< double >::UNIT_Z );
-        Vector3_exposer.def_readonly( "ZERO", Wm3::Vector3< double >::ZERO );
         Vector3_exposer.staticmethod( "ComputeExtremes" );
         Vector3_exposer.staticmethod( "GenerateOrthonormalBasis" );
         Vector3_exposer.staticmethod( "Orthonormalize" );
         Vector3_exposer.def( bp::self_ns::str( bp::self ) );
         Vector3_exposer.def("__len__",&::Vector3_len)   .staticmethod("__len__").def("__setitem__",&::Vector3_set_item)   .def("__getitem__",&::Vector3_get_item)   .def("__str__",&::Vector3_str)   .def("__repr__",&::Vector3_str);
+        Vector3_exposer.add_property("ZERO",::Vector3r_ZERO).add_property("UNIT_X",::Vector3r_UNIT_X).add_property("UNIT_Y",::Vector3r_UNIT_Y).add_property("UNIT_Z",::Vector3r_UNIT_Z).add_property("ONE",::Vector3r_ONE);
     }
 
     { //::componentMaxVector

=== modified file 'py/pack.py'
--- py/pack.py	2009-08-25 14:21:44 +0000
+++ py/pack.py	2009-09-19 19:41:52 +0000
@@ -74,7 +74,7 @@
 
 class inSpace(Predicate):
 	"""Predicate returning True for any points, with infinite bounding box."""
-	def __init__(self, _center=Vector3.ZERO): self._center=_center
+	def __init__(self, _center=Vector3().ZERO): self._center=_center
 	def aabb(self):
 		inf=float('inf'); return Vector3(-inf,-inf,-inf),Vector3(inf,inf,inf)
 	def center(self): return self._center
@@ -145,7 +145,7 @@
 	pts=[Vector3(v.x,v.y,v.z) for v in surf.vertices()]
 	return cloudBestFitOBB(tuple(pts))
 
-def revolutionSurfaceMeridians(sects,angles,origin=Vector3.ZERO,orientation=Quaternion.IDENTITY):
+def revolutionSurfaceMeridians(sects,angles,origin=Vector3().ZERO,orientation=Quaternion().IDENTITY):
 	"""Revolution surface given sequences of 2d points and sequence of corresponding angles,
 	returning sequences of 3d points representing meridian sections of the revolution surface.
 	The 2d sections are turned around z-axis, but they can be transformed

=== modified file 'py/tests/wrapper.py'
--- py/tests/wrapper.py	2009-08-05 07:32:18 +0000
+++ py/tests/wrapper.py	2009-09-19 19:41:52 +0000
@@ -86,8 +86,8 @@
 	def testVector2(self):
 		v=Vector2(1,2); v2=Vector2(3,4)
 		self.assert_(v+v2==Vector2(4,6))
-		self.assert_(Vector2.UNIT_X.Dot(Vector2.UNIT_Y)==0)
-		self.assert_(Vector2.ZERO.Length()==0)
+		self.assert_(Vector2().UNIT_X.Dot(Vector2().UNIT_Y)==0)
+		self.assert_(Vector2().ZERO.Length()==0)
 	def testVector3(self):
 		v=Vector3(3,4,5); v2=Vector3(3,4,5)
 		self.assert_(v[0]==3 and v[1]==4 and v[2]==5)
@@ -95,7 +95,7 @@
 		self.assert_(v==(3,4,5)) # comparison with list/tuple
 		self.assert_(v==[3,4,5])
 		self.assert_(v==v2)
-		x,y,z,one=Vector3.UNIT_X,Vector3.UNIT_Y,Vector3.UNIT_Z,Vector3.ONE
+		x,y,z,one=Vector3().UNIT_X,Vector3().UNIT_Y,Vector3().UNIT_Z,Vector3().ONE
 		self.assert_(x+y+z==one)
 		self.assert_(x.Dot(y)==0)
 		self.assert_(x.Cross(y)==z)
@@ -104,18 +104,18 @@
 		q1=Quaternion((0,0,1),pi/2)
 		q2=Quaternion(Vector3(0,0,1),pi/2)
 		q1==q2
-		x,y,z,one=Vector3.UNIT_X,Vector3.UNIT_Y,Vector3.UNIT_Z,Vector3.ONE
+		x,y,z,one=Vector3().UNIT_X,Vector3().UNIT_Y,Vector3().UNIT_Z,Vector3().ONE
 		self.assertVQAlmostEqual(q1*x,y)
 		self.assertVQAlmostEqual(q1*q1*x,-x)
-		self.assertVQAlmostEqual(q1*q1.Conjugate(),Quaternion.IDENTITY)
+		self.assertVQAlmostEqual(q1*q1.Conjugate(),Quaternion().IDENTITY)
 		self.assertVQAlmostEqual(q1.ToAxisAngle()[0],(0,0,1))
 		self.assertAlmostEqual(q1.ToAxisAngle()[1],pi/2)
 	# not really wm3 thing, but closely related
 	def testSe3Conversion(self):
 		pp=PhysicalParameters()
-		pp['se3']=(Vector3.ZERO,Quaternion.IDENTITY)
-		self.assert_(pp['se3'][0]==Vector3.ZERO)
-		self.assert_(pp['se3'][1]==Quaternion.IDENTITY)
+		pp['se3']=(Vector3().ZERO,Quaternion().IDENTITY)
+		self.assert_(pp['se3'][0]==Vector3().ZERO)
+		self.assert_(pp['se3'][1]==Quaternion().IDENTITY)
 		pp['se3']=((1,2,3),Quaternion((1,1,1),pi/4))
 		self.assert_(pp['se3'][0]==(1,2,3))
 		self.assert_(pp['se3'][0]==pp.pos)

=== modified file 'py/utils.py'
--- py/utils.py	2009-09-01 12:34:25 +0000
+++ py/utils.py	2009-09-19 19:41:52 +0000
@@ -388,6 +388,12 @@
 		o.tags['line']='l'+tableLine
 		# the empty '#' line to make line number 1-based
 		ll=[l for l in ['#']+open(tableFile).readlines()]; values=ll[int(tableLine)].split('#')[0].split()
+		for i in range(0,len(values)):
+			lineNo=int(tableLine)-1
+			while values[i]=='=':
+				values[i]=ll[lineNo].split('#')[0].split()[i]
+				if lineNo==0: raise RuntimeError("the = specifier doesn't refer to a value at some previous line.")
+				lineNo-=1
 		names=None
 		for l in ll:
 			if not re.match(r'^\s*(#.*)?$',l): names=l.split(); break
@@ -404,7 +410,9 @@
 			if names[i]=='description': continue
 			if names[i] not in kw.keys():
 				if (not unknownOk) and names[i][0]!='!': raise NameError("Parameter `%s' has no default value assigned"%names[i])
-			else: kw.pop(names[i])
+			else:
+				if values[i]!='*': kw.pop(names[i])
+				else: continue
 			if names[i][0]!='!':
 				exec('%s=%s'%(names[i],values[i])) in __builtins__; tagsParams+=['%s=%s'%(names[i],values[i])]; dictParams[names[i]]=values[i]
 	defaults=[]

=== modified file 'scripts/test/gts-random-pack-obb.py'
--- scripts/test/gts-random-pack-obb.py	2009-08-22 15:05:20 +0000
+++ scripts/test/gts-random-pack-obb.py	2009-09-19 19:41:52 +0000
@@ -6,7 +6,7 @@
 poly=((3+.1,0),(3+0,.1),(3+sq2,.1+sq2),(3+.1+sq2,sq2),(3+.1,0))
 #pylab.plot(*zip(*poly)); pylab.xlim(xmin=0); pylab.grid(); pylab.title('Meridian of the revolution surface\n(close to continue)'); pylab.gca().set_aspect(aspect='equal',adjustable='box'); pylab.show()
 thetas=arange(0,pi/8,pi/24)
-pts=pack.revolutionSurfaceMeridians([poly for theta in thetas],thetas,origin=Vector3(-4,0,-1),orientation=Quaternion.IDENTITY)
+pts=pack.revolutionSurfaceMeridians([poly for theta in thetas],thetas,origin=Vector3(-4,0,-1),orientation=Quaternion().IDENTITY)
 surf=pack.sweptPolylines2gtsSurface(pts,capStart=True,capEnd=True,threshold=1e-4)
 O.bodies.append(pack.gtsSurface2Facets(surf,color=(1,0,1)))
 # fill this solid with triaxial packing; it will compute minimum-volume oriented bounding box

=== modified file 'scripts/test/wm3-wrap.py'
--- scripts/test/wm3-wrap.py	2009-08-05 07:32:18 +0000
+++ scripts/test/wm3-wrap.py	2009-09-19 19:41:52 +0000
@@ -1,5 +1,5 @@
 # constructors, constants as static objects
-x,y,z,one=Vector3.UNIT_X,Vector3.UNIT_Y,Vector3.UNIT_Z,Vector3.ONE
+x,y,z,one=Vector3().UNIT_X,Vector3().UNIT_Y,Vector3().UNIT_Z,Vector3().ONE
 x2=Vector3(x)
 # conversions to sequence types
 list(x2)