guild icon
Toit
#Measurement data to RGB-color transformation.
Thread channel in help
kaxori
kaxori 09/18/2024 05:51 PM
Enclosed a working implementation using list.

:❓: question:
Is there a more sophisticated solution using special list functions ?
floitsch
floitsch 09/18/2024 08:37 PM
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:
y := out.first if x <= in.first: y = out.first
Did you mean y/num := ? ?
kaxori
kaxori 09/19/2024 07:59 AM
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.
floitsch
floitsch 09/19/2024 08:12 AM
You could use reduce for the transform:
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.
kaxori
kaxori 09/19/2024 02:59 PM
ok:
I tried out the reduce function.
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
floitsch
floitsch 09/19/2024 03:00 PM
The return should be fine. What was the error?
floitsch
floitsch 09/19/2024 03:00 PM
as you say: otherwise you have to run through all elements.
floitsch
floitsch 09/19/2024 03:03 PM
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.
8 messages in total