The problem is that the varible 'origen' is assigned at the start as
[0, 0, 0], and it isn't assigned anymore along the method but when the
method ends it returns a completly different value than the assigned.
I'm very angry about this because it's just stupid and it taked me 30
minutes!
Anyone knows why this happens?
def dibujarRubik(longitud, cubos)
origen = [0, 0, 0]
origenContador = origen
cubos.times do #CUBOS EN Z
cubos.times do # Cubos en Y
cubos.times do # Cubos en X
dibujarCubo(longitud, origenContador)
origenContador.x += longitud
end
origenContador.x = origen.x
origenContador.y += longitud
end
origenContador.y = origen.y
origenContador.z += longitud
end
origen
end
origen = ORIGIN
origenContador = ORIGIN
That should fix it. Todd
NO that will not work. Because the '=' is creating an alias instead of
a new variable. Be careful! The constant 'ORIGIN' is frozen, and
frozen variables are not wanted.
(NO que no funcionará. Debido a que el '=' es crear un alias en lugar
de una nueva variable. ¡Ten cuidado! La constante 'ORIGIN' es
congelado, y las variables congelados no son deseados.)
Make sure to create a new object, and only reference the constant
'ORIGIN'. Then duplicate the variable using '.dup'
(Asegúrese de crear un nuevo objeto, y sólo la referencia constante
'ORIGIN'. Luego duplica la variable usando '.dup')
origen = Array.new( ORIGIN.to_a )
origenContador = origen.dup
If you wish to use 'Point3d':
(Si desea utilizar 'Point3d'):
origen = Geom::Point3d.new( ORIGIN )
origenContador = origen.clone
*Geom::Point3d class has no 'dup' method.
(Clase Geom::Point3d no tiene «método 'dup'.)
I said that. Wasn't I clear enough?
> On Jan 10, 7:12 am, Dan Rathbun wrote:
>
> > If you wish to use 'Point3d':
> > (Si desea utilizar 'Point3d'):
>
> > origen = Geom::Point3d.new( ORIGIN )
> > origenContador = origen.clone
On Jan 10, 8:51 am, TIG wrote:
> Note that '.clone' is equivalent to '.dup' for a Point3d...
Agreed. But it should not be.
This is another error in the Sketchup API.
.clone copies the frozen state of the object
.dup is NOT supposed to copy the frozen state
Both are supposed to copy the tainted state.
Geom::Point3d.clone violates the rule, and does not copy the frozen
state.
I suppose the .clone methods for Vector3d and Transformation are also
incorrect. ??