[Bf-python] mathutil PyNumberMethods behaving badly

Campbell Barton cbarton at metavr.com
Fri Jul 21 12:53:57 CEST 2006


Im not sure when this is best added in release wise etc. but IMHO We 
need both..

Python has
for a in reversed(ls): ...
and
ls.reverse()

and sorted(ls),   ls.sort()

Of course its a bit different comparing python builtins to methods, but 
it seems to me a fairly good english way to define the 2.

Its important to be clear weather were operating on..
If we say, only ever return a copy. then we can do without invert(ed), 
normaliz(ed) etc.

But I think we need both and a clear way to define each.


Ken Hughes wrote:
> Personally I think having -vec, vec.negate() and veg.negated() is a 
> bit like flammable, inflammable and non-flammable.  A little confusing 
> and somewhat redundant.  I like the math operations, but don't think 
> we need a duplicate method for them (if I understand Joseph's 
> suggestion).
>
> Also, I was just pointing out a bug.  It needs to be fixed prior to 
> 2.43, but that's a long way off.  If any of the API rewrite is going 
> to be done prior to 2.43, I'd like to see the discussion first before 
> the implementation.
>
> $0.02 -- Ken
>
> Campbell Barton wrote:
>> Hi Joseph, read through this and It sounds like what we want
>>
>> Think I suggested that in the first place but we can take it further.
>> invert() inverted() - inverted would be realy usefull because at the 
>> moment You have to copy a matrix and then invert it wich can be a bit 
>> wordy
>>
>> omat_i=Blender.Mathutils.Matrix( ob.matrixLocal )  # (wrapped)
>> omat_i.invert()
>>
>> - could be replaced with
>>
>> omat_i= ob.matrixLocal.inverted()
>>
>> Do you want help with this or would you rather do yourself?
>> Id like to have this for 2.43
>>
>> - Cam
>>
>>
>> Gilbert, Joseph T. wrote:
>>> This was something we discussed a few months ago.
>>> The proposal was to have a 2 methods. One which returns a self-modified
>>> reference and another that returns a modified-copy.
>>>
>>> Example:
>>> ref_to_orig_vector = vector.negate()
>>> new_mod_vector = vector.negated()
>>>
>>> The -vec are shortcuts in pymath. They should be bound to either of the
>>> 2 above methods. It would make sense to have them be bound to the
>>> version that returns a new_modified_vector for safety.
>>>
>>> To keep the current API "negate" would continue to do what it does now.
>>> We would need to add "negated", etc. for all the self-modifying methods
>>> of all the py math objects that require them.
>>>
>>> -----Original Message-----
>>> From: bf-python-bounces at projects.blender.org
>>> [mailto:bf-python-bounces at projects.blender.org] On Behalf Of Ken Hughes
>>> Sent: Thursday, July 20, 2006 2:29 PM
>>> To: Blender Foundation Python list
>>> Subject: [Bf-python] mathutil PyNumberMethods behaving badly
>>>
>>> Cam discovered a problem in the mathutils with expressions like this:
>>>
>>> me = Mesh.Get('Cube')
>>> x = -me.verts[0].co
>>> print x
>>> print me.verts[0].co
>>>
>>> You get this:
>>>
>>> [-0.565980, -1.386673, 0.000000](vector)
>>> [-0.565980, -1.386673, 0.000000](vector)
>>>
>>> Joseph put in code which modifies the original object, since script 
>>> users wanted to concatenate operations, but I don't think we really 
>>> want
>>>
>>> to this with math operations (i.e., PyNumberMethods).
>>>
>>> Seems to me we need two type of operations in mathutils: one modify 
>>> the original data and return it and ones that don't (now on three: 
>>> 1, 2, 3, "Duh").  Obviously the math operations shouldn't do this, 
>>> but looks like
>>>
>>> we need to "un-deprecate" some of the original methods like
>>> vector.negate()
>>>
>>> Ken
>>> _______________________________________________
>>> Bf-python mailing list
>>> Bf-python at projects.blender.org
>>> http://projects.blender.org/mailman/listinfo/bf-python
>>> _______________________________________________
>>> Bf-python mailing list
>>> Bf-python at projects.blender.org
>>> http://projects.blender.org/mailman/listinfo/bf-python
>>>
>>>   
>>
>>
>
> _______________________________________________
> Bf-python mailing list
> Bf-python at projects.blender.org
> http://projects.blender.org/mailman/listinfo/bf-python
>


-- 
Campbell J Barton

133 Hope Street
Geelong West, Victoria 3218 Australia

URL:    http://www.metavr.com
e-mail: cbarton at metavr.com
phone: AU (03) 5229 0241



More information about the Bf-python mailing list