Re: 3d vector struct

2014-02-07 Thread Stanislav Blinov
On Friday, 7 February 2014 at 21:37:26 UTC, Casper Færgemand wrote: On Friday, 7 February 2014 at 10:50:49 UTC, Stanislav Blinov wrote: I know. I also know that people making games are obsessed with performance :) And, where there's 3d vector, there would also be 4d vector and matrices... W

Re: 3d vector struct

2014-02-07 Thread Casper Færgemand
On Friday, 7 February 2014 at 10:50:49 UTC, Stanislav Blinov wrote: I know. I also know that people making games are obsessed with performance :) And, where there's 3d vector, there would also be 4d vector and matrices... Wouldn't it make more sense to aim for a float SIMD implementation in

Re: 3d vector struct

2014-02-07 Thread Stanislav Blinov
On Friday, 7 February 2014 at 04:03:58 UTC, Marco Leise wrote: Am Mon, 03 Feb 2014 22:01:14 + schrieb "Stanislav Blinov" : Return-by-value being optimized as a move might be one more reason why you would like to use slices... 3 doubles is only one machine word more than an array slice an

Re: 3d vector struct

2014-02-06 Thread Marco Leise
Am Mon, 03 Feb 2014 22:01:14 + schrieb "Stanislav Blinov" : > Return-by-value being optimized as a move might be one more > reason why you would like to use slices instead of variables to > store coordinates (since that would mean just moving a pointer > and a size_t), but that might have t

Re: 3d vector struct

2014-02-04 Thread Francesco Cattoglio
On Monday, 3 February 2014 at 20:10:59 UTC, Brenton wrote: 6) Any other comments or suggestions? I know that the "I'm learning the language" factor plays a huge role, but after you are done studying your vector implementation, I think you could forget about it and use the ones provided by ot

Re: 3d vector struct

2014-02-03 Thread Stanislav Blinov
On Monday, 3 February 2014 at 20:10:59 UTC, Brenton wrote: 4) Is it advisable for the cross method to return by value? In C++, I would declare this method as inline and in a header file. Can I trust D to inline away this inefficiency? Perhaps I should pass in the result as a "ref" or "out"

Re: 3d vector struct

2014-02-03 Thread Martijn Pot
On Monday, 3 February 2014 at 20:10:59 UTC, Brenton wrote: double dot(in Vector3d other) inout { return x * other.x + y * other.y + z * other.z; } Vector3d cross(in Vector3d other) inout { const Vector3d result = { y

Re: 3d vector struct

2014-02-03 Thread Craig Dillabaugh
5) I notice that a lot of other people online prefer using fixed arrays not structs for Vectors in D, why? It does make some calculations more straightforward. For example I have code that calculates distance between points as follows: double euclideanDistance( double[] pt1, double[] pt2 ) in

Re: 3d vector struct

2014-02-03 Thread bearophile
Brenton: 1) I initialize the vector to a null vector, not nans Why? 2) The dot and cross are "inout" methods, i.e. available for mutable, const, and immutable objects. There is no reason to declare "inout" methods as being "const". But I suggest to add pure/nothrow. 3) The dot and cro

3d vector struct

2014-02-03 Thread Brenton
Hi, I'm just getting to know D and so am hoping that someone more experienced with the language could review this 3d vector struct and my comments below. I'm planning on building a little ray tracer in the next week or so :) struct Vector3d { double x = 0, y = 0, z = 0;