www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Re: simple display (from: GUI library for D)

reply bearophile <bearophileHUGS lycos.com> writes:
 foreach (col; zip(reds, greens, blues))
     image[x, y] = col;

With Color is becomes something like: foreach (col; zip(reds, greens, blues)) image[x, y] = Color(col.tupleof); Bye, bearophile
Apr 08 2011
parent reply Adam D. Ruppe <destructionator gmail.com> writes:
bearophile wrote:
 With Color is becomes something like:
 foreach (col; zip(reds, greens, blues))
    image[x, y] = Color(col.tupleof);

That looks perfectly acceptable to me. I might add an overload so opIndex can take a tuple too though, so the zip example is a little easier, but I really prefer the Color struct.
 I see. But those lambdas are a bit too much large put there. I
 suggest true named function moved elsewhere.
 - Inside the (dchar c) {} a switch seems better.

Yeah, that's what happens when an example grows bigger then intended without refactoring :P
 - In Wrapped struct why are you using a checkLimits() instead of
 an invariant()?

It's not a check (poorly chosen name I guess!) - it actually changes the value (wrapping around) when it hits the limit, so user input never leads to crazy values. Besides, invariants are generally to check the program for bugs, rather than external input from the user like used here.
Apr 08 2011
parent reply Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
On 4/9/11, spir <denis.spir gmail.com> wrote:
 I prefere structs to tuples /everywhere/. They have 2 big advantages:
 * explicite: color.red versus color[0]

But Tuples _are_ structs. And you _can_ use explicit names: http://codepad.org/0ZWAtcL1
Apr 09 2011
parent "Nick Sabalausky" <a a.a> writes:
"Andrej Mitrovic" <andrej.mitrovich gmail.com> wrote in message 
news:mailman.3303.1302360951.4748.digitalmars-d puremagic.com...
 On 4/9/11, spir <denis.spir gmail.com> wrote:
 I prefere structs to tuples /everywhere/. They have 2 big advantages:
 * explicite: color.red versus color[0]

But Tuples _are_ structs. And you _can_ use explicit names: http://codepad.org/0ZWAtcL1

struct gives you more control over internal mechanics, which is important for something as low-level as a representation of a pixel.
Apr 09 2011