[x3d-public] SFRotation constructor axis argument by reference or value ?
Andreas Plesch
andreasplesch at gmail.com
Tue Mar 3 09:57:51 PST 2020
Hi Don,
yes, that the objects become independent is what I assumed first.
But then I tried to find out about the actual situation as prescribed
by the spec. and found not much except that in ecmascript objects are
passed by reference (primitives by value but SFVec3f is not a
primitive).
I guess it suffices that the spec. defines SFRotation only in terms of
four properties which are primitives: x,y,z,angle . That should mean
that the x,y,z values are never references (for example to axis.x) but
copied values.
At least I convinced myself now, thanks for thinking along, Andreas
On Tue, Mar 3, 2020 at 12:23 PM Don Brutzman <brutzman at nps.edu> wrote:
>
> [Dick and I are on a teleconference]
>
> The way that you have written this, it looks to us like each object is independent.
>
> Thus if you create a 'rot' SFRotation object, its values are passed by value only change if they are directly modified.
>
> This seems to be a straightforward case of object encapsulation. For those interested in learning more, general information:
>
> * Encapsulation (computer programming)
> https://en.wikipedia.org/wiki/Encapsulation_(computer_programming)
>
>
> On 3/3/2020 7:06 AM, Andreas Plesch wrote:
> > In the ecmascript SAI, SFRotation has a constructor which has the
> > rotation axis as a SFVec3f argument:
> >
> > new SFRotation ( SFVec3f axis, numeric angle )
> >
> > https://www.web3d.org/documents/specifications/19777-1/V3.3/Part1/functions.html#SFRotation
> > (Table 7.18, -url in the first sentence is off-)
> >
> > The question is when I make a new SFRotation and later change the
> > SFVec3f which was used for the axis, does the previously constructed
> > SFRotation also change ?
> >
> > axis = new SFVec3f ( 0, 0, 1 );
> > rot = new SFRotation( axis, 3.14 );
> > axis.y = 1.0
> > axis.z = 0.0
> > // rot.y is ?
> > // constructed by value: rot.y = 0.0
> > // constructed by reference: rot.y = 1.0
> >
> > I did not check the abstract SAI spec. for guidance so it is very
> > possible I missed something.
> >
> > This is just an example. There are of course other constructors which
> > use objects as parameters. It is also probably rare that a script
> > would want to do this.
> >
> > It may depend on the scripting language. In ecmascript objects are
> > passed by reference, you have to explicitly make a copy if you need
> > it. This is for performance. So I would guess for ecmascript it should
> > be rot.y = 1.0 .
> >
> > -Andreas
>
>
> all the best, Don
> --
> Don Brutzman Naval Postgraduate School, Code USW/Br brutzman at nps.edu
> Watkins 270, MOVES Institute, Monterey CA 93943-5000 USA +1.831.656.2149
> X3D graphics, virtual worlds, navy robotics http://faculty.nps.edu/brutzman
--
Andreas Plesch
Waltham, MA 02453
More information about the x3d-public
mailing list