rainyl / opencv_dart

OpenCV bindings for Dart language and Flutter. Support Asynchronous Now!
https://pub.dev/packages/opencv_dart
Apache License 2.0
138 stars 18 forks source link

added from list #165

Closed abdelaziz-mahdy closed 4 months ago

abdelaziz-mahdy commented 4 months ago

fix https://github.com/rainyl/opencv_dart/issues/164

what do you think?

rainyl commented 4 months ago

@abdelaziz-mahdy Thanks for your contribution!

An important problem is that, the multi-dimenssional List in dart is jagged array, which means users may input some 2D list without alignment.

so maybe we should warn users if the list is not aligned, e.g.,

final data = [
  [1, 2],
  [4, 5, 6, 7],
  [7, 8, 9],
];
abdelaziz-mahdy commented 4 months ago

@abdelaziz-mahdy Thanks for your contribution!

An important problem is that, the multi-dimenssional List in dart is jagged array, which means users may input some 2D list without alignment.

so maybe we should warn users if the list is not aligned, e.g.,

final data = [
  [1, 2],
  [4, 5, 6, 7],
  [7, 8, 9],
];

do you have any idea how to check on that without reducing performance? i like the idea but i cant think of a way to check on it without checking when expanding that the length is the same

abdelaziz-mahdy commented 4 months ago

i added checks to ensure the input is correct, to avoid bugs, let me know what you think

rainyl commented 4 months ago

do you have any idea how to check on that without reducing performance? i like the idea but i cant think of a way to check on it without checking when expanding that the length is the same

Since dart have no such thing as multidimensional array like C#, so the easiest way is to check the element length of a 2D array, i.e., data.every((e)=>e.length==data.first.length);, but I am not sure how much performance will be lost.

abdelaziz-mahdy commented 4 months ago

do you have any idea how to check on that without reducing performance? i like the idea but i cant think of a way to check on it without checking when expanding that the length is the same

Since dart have no such thing as multidimensional array like C#, so the easiest way is to check the element length of a 2D array, i.e., data.every((e)=>e.length==data.first.length);, but I am not sure how much performance will be lost.

i did add the checks as a separated loops if you think they should be included in the expand (i think it will be better to iterate the list only once) let me know

rainyl commented 4 months ago

i did add the checks as a separated loops if you think they should be included in the expand (i think it will be better to iterate the list only once) let me know

Agree that it should be iterated once, I changed it to linq style to make it clearer and more concise, hope you won't mind it.

rainyl commented 4 months ago

@abdelaziz-mahdy Looks good to me now, what do you think? If no further problems I am going to merge it.

abdelaziz-mahdy commented 4 months ago

looks good to me, but the every keyword will make the loop iterated first then flattened so the list is iterated twice? also asserts or exception? asserts only works in debug right? that will lead to crashes on release this is why i used exception?

rainyl commented 4 months ago

looks good to me, but the every keyword will make the loop iterated first then flattened so the list is iterated twice? also asserts or exception? asserts only works in debug right? that will lead to crashes on release this is why i used exception?

Oh, you are right, I didn't know the assert in dart will only throw in debug mode, such a strange feature....

I have fixed it, could you please review it?

rainyl commented 4 months ago

Merged, thanks for your contribution!