https://toitlang.org/ logo
Measurement data to RGB-color transformation.
# help
k
Enclosed a working implementation using list. ā“ question: Is there a more sophisticated solution using special list functions ? https://cdn.discordapp.com/attachments/1286021861620322315/1286021861720850494/test-list.toit?ex=66ec64b0&is=66eb1330&hm=7c4ef721e1f9442b4d4d333781f665ea809845ff38eef6037b0ed8e61108ea9f&
f
My observations: - typo:
output-poits
- it's generally more efficient to use custom classes than lists. It might make sense to have a
Hsv
or
Rgb
class. - in `transform`: the
for i := 1; i < in.size; i += 1
. You can use
i++
. - if you do floating-point operations - typically we use american English (
normalize
instead of
normalise
). Obviously not enforced. - these lines don't fully make sense:
Copy code
y := out.first
  if x <= in.first: y = out.first
Did you mean
y/num := ?
?
k
Thank you for your review. - points are corrected - algorithm test -> classes will come soon - not quite sure, if implementation of the lin. curve points is user/app-friendly enough. still thinking there are better list function - that I don't know yet.
f
You could use
reduce
for the `transform`:
Copy code
in.reduce: | previous current |
  if x <= current:
    x-norm/float := normalise x.to-float previous current
    return scale x-norm previous current
  current  // Use 'current' as the next previous.
k
ok: I tried out the reduce function.
Copy code
y := in.reduce: | previous current |
    if x <= current:
      x-norm/float := normalize x.to-float previous current
      scale x-norm previous current
    else:
      current
('return' was not accepted) But I think there is a disadvantage, because each list element is handled
f
The
return
should be fine. What was the error?
as you say: otherwise you have to run through all elements.
small other thing I'm noticing right now: local variables should never need to end with
_
. The trailing
_
is for privacy of globals and fields.