November 27, 2017
On 11/27/2017 10:47 AM, Dmitry wrote:
> On Monday, 27 November 2017 at 18:40:41 UTC, Ali Çehreli wrote:
>
>> So, it looks like the original code was accessing out of bounds and
>> probably that's why you inserted the ((index + 3) < N) check in the D
>> version because D was catching that error at runtime.
> Yes, it is.

This is exactly the kind of bug Walter wanted to avoid when leaving C's arrays behind. (This includes C++'s std::vector because vector::operator[] is permissive. (To be safe, one needs to use .at() or check indexes explicitly.))

So, as advertised, port your programs to D and the results will likely be more correct. I like it! :)

Ali

P.S. I think you have an unnecessary 'ref' on the D version because a slice is already a reference to elements:

// C++
void alpha_bleeding(unsigned char *image, int width, int height)

// D
private void alphaBleeding(ref ubyte[] data, int width, int height)

You would need that 'ref' if you wanted to modify the original array itself by e.g. adding elements to it.

November 28, 2017
On Monday, 27 November 2017 at 19:01:28 UTC, Ali Çehreli wrote:
> P.S. I think you have an unnecessary 'ref' on the D version because a slice is already a reference to elements:
Fixed, thank you.

November 28, 2017
On Tuesday, 28 November 2017 at 06:46:18 UTC, Dmitry wrote:
> On Monday, 27 November 2017 at 19:01:28 UTC, Ali Çehreli wrote:
>> P.S. I think you have an unnecessary 'ref' on the D version because a slice is already a reference to elements:
> Fixed, thank you.

https://pastebin.com/xJXPBh0n
Converted it and it works as expected.
November 28, 2017
On Tuesday, 28 November 2017 at 09:01:47 UTC, Temtaime wrote:
> https://pastebin.com/xJXPBh0n
> Converted it and it works as expected.
What did you use for it?
In future I'll be needed to convert some more C++ code.

P.S. /And it works wrong, because uses unsafe pointer (ubyte *image). So, it takes wrong values (Blue of the next pixel instead of Alpha of the current pixel). Same with original code./

P.P.S. Anyway, I already found all things I did wrong. But also I found in your code that there is `swap` function, didn't know it. Thank you!


1 2
Next ›   Last »