image-js / image-js-typescript

Temporary repository to work on the migration of image-js to TypeScript
https://image-js.github.io/image-js-typescript/
MIT License
5 stars 5 forks source link

feat: add options to mean, median and variance #471

Closed EscapedGibbon closed 2 months ago

EscapedGibbon commented 2 months ago

close: https://github.com/image-js/image-js-typescript/issues/470

stropitek commented 2 months ago

Variance will return the result of a 0-division if the array of points is empty. Did you think about what should happen in that case?

Same question is relevant for the other operations.

EscapedGibbon commented 2 months ago

Variance will return the result of a 0-division if the array of points is empty. Did you think about what should happen in that case?

Indeed this should throw. Should we also check the validity of a coordinate? Right now the user can input any value there, regardless whether the point belongs to an image or not.

stropitek commented 2 months ago

Indeed this should throw.

I agree

Should we also check the validity of a coordinate? Right now the user can input any value there, regardless whether the point belongs to an image or not.

I think it should throw as well. To be efficient, I suggest that you first convert the points to indices so that you don't do it twice, checking their value (compare with size) and then use getValue safely.

Please add test cases for each of those scenarios (no points, invalid points).