[Bf-python] Re: vector.negate() question

Germán Alonso german at sistrans.com
Mon May 15 12:28:50 CEST 2006


Hi again:

Why don't we use class variables to access to the wrapped data?

I think that would be great as it is like changing a variable and you did 
what you think you're doing, changing an instance variable value.

ob.matrix         # wrapped data
ob.getMatrix() # copy of the matrix

As i'm a newbie, may be this have problems that i can't see or it's just a 
bad idea, in both cases i'd love to know why, to avoid as many silly 
suggestions as possible in the future :)

Thanks for reading.

Germán


----- Original Message ----- 
From: "Gilbert, Joseph T." <jgilbert at tigr.ORG>
To: <cbarton at metavr.com>; "Blender Foundation Python list" 
<bf-python at projects.blender.org>
Sent: Friday, May 12, 2006 5:44 PM
Subject: RE: [Bf-python] vector.negate() question


These are great ideas ideasman. ty
I still worry about the wrapped/not-wrapped mess... However, I think this 
would be a great help.
I would propose then we have:
vector.negate()/vector.negated()
vector.normalize()/vector.normalized()
vector.zero()/vector.zeroed()
etc..
Where the first operation is a self operation and the second method is 
returns a new python non-wrapped object.

-----Original Message-----
From: bf-python-bounces at projects.blender.org 
[mailto:bf-python-bounces at projects.blender.org] On Behalf Of Campbell Barton
Sent: Tuesday, May 09, 2006 11:22 AM
To: Blender Foundation Python list
Subject: Re: [Bf-python] vector.negate() question

Hey All


Gut feeling is...
v= -vec # A new vector
veg.negate() # Operates on self. dosent return anything

If you want a negate that returnes new data. we could use "ed" like
python 2.4 did with revers"ed"

for i in reversed(xrange(10)): print i
9,8,7,6,5

same as
__ r= range(10)
__ r.reverse()
__ for i in r: print i


why not,
v.normalize() - normalizes vector
vn= v.normalized() - returnes a new normalized

matrix.invert() - inverts the matrix in place,
m= matrix.inverted() - Make a new inverted matrix.

- Cam


Gilbert, Joseph T. wrote:
> I believe vec1 - vec2 is available (I hope so!). There are a lot of 
> pythonic math operations that are not commonly used but are shorthand 
> (like ~vec). I added some of these to the object classes for quick 
> scripting.
>
> I think a more difficult issue to address is why vector.negate (or -vec) 
> doesn't return a NEW vector as opposed to a self operation (which is 
> extremely non-pythonic). This goes back to the vector_proxy issue and the 
> wraping of internal data structures for modification.
>
> object.matrix.blah(x) in a truly pythonic sense doesn't modify the data 
> but creates a new matrix for you and returns it. We had problems with 
> people not understanding why when they did object.matrix.blah(x) the data 
> was not modified internally. So we came up with the idea of wrapping 
> internal data (i.e. you DON'T get back a new matrix but modify the data 
> directly in C). But to make this work you need self operations on data 
> types or else it gets confusing.
>
> object.matrix(wrapped data).blah(self operation).negate(returns a new 
> matrix)()!!
>
> Personally I think it's a bit of a mess. It may be we need 2 separate 
> methods for every operation, 1 for self modification and another for 
> returning a new value. vector.negate_self() and vector.negate_new() or 
> something. ??
>
>
> -----Original Message-----
> From: bf-python-bounces at projects.blender.org 
> [mailto:bf-python-bounces at projects.blender.org] On Behalf Of Toni Alatalo
> Sent: Tuesday, May 09, 2006 10:33 AM
> To: Blender Foundation Python list
> Subject: Re: [Bf-python] vector.negate() question
>
> Gilbert, Joseph T. wrote:
>
>
>> lol you make great points. -vector is really a shorthand for 
>> vector.negate(). No harm in having both available.
>>
>>
>>
>
> i think -vector should definitely not do anything, but vector1 - vector2
> should return vec_sub(vec1, vec2)
> .. that is how python normally works, and how e.g. the soya3d api does it.
>
> ~Toni
>
>
>> ________________________________________
>> From: bf-python-bounces at projects.blender.org 
>> [mailto:bf-python-bounces at projects.blender.org] On Behalf Of Germán 
>> Alonso
>> Sent: Tuesday, May 09, 2006 7:36 AM
>> To: Blender Foundation Python list
>> Subject: [Bf-python] vector.negate() question
>>
>> Good morning to all:
>>
>> I'd love to know why vector.negate() has been depreciated, to use -vector 
>> instead of it.
>>
>> I think that the explicit method would be better and more natural than 
>> the minus prefix, as this new can make undesired negations of vectors 
>> that may be difficult to detect if you're not used to this behaviour.
>>
>> For example when you pass to a function an integer negated you use:
>> function( -integer )
>> and this don't change the integer variable value, but if you pass a 
>> vector:
>> function( -vector )
>> the vector value changes and you'll have to use:
>> function( -Vector(vector) )
>> if you don't want the vector variable to change.
>>
>> I think this is a little odd, and purpose restore the old vector.negate() 
>> method, as is an explicit action instead of being hidden behind the minus 
>> symbol.
>>
>> Thanks for reading.
>>
>> Germán
>> _______________________________________________
>> 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
_______________________________________________
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