[Bf-python] mathutil PyNumberMethods behaving badly

Gilbert, Joseph T. jgilbert at tigr.ORG
Fri Jul 21 16:43:58 CEST 2006


We don't need -vec no. It is a shorthand operator. However, I thought it
would be nicer for the end-user.

However, now that we have 2 versions of negate(), it's debatable if we
want to deprecate -vec because it may lead to confusion as to what it's
doing.
If we don't want to deprecate it, my suggestion is to give it the
behavior of vector.negated() - i.e. return a modified copy.

As for the confusing part:
Right now you can get the proposed behavior of vector.negated() by
doing:

Vector(vec).negate()

however, most people will do something like this:

Vector(vec.negate())

which will modify the original vector as well.

There needs to be a way to get python-safe copies of wrapped data.

Another option might be to add a method to make the object a safe copy
if it is not already. Like Local() or Safe_Copy() or something....


-----Original Message-----
From: bf-python-bounces at projects.blender.org
[mailto:bf-python-bounces at projects.blender.org] On Behalf Of Ken Hughes
Sent: Friday, July 21, 2006 3:17 AM
To: Blender Foundation Python list
Subject: Re: [Bf-python] mathutil PyNumberMethods behaving badly

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



More information about the Bf-python mailing list