Skip to content

Commit

Permalink
more test
Browse files Browse the repository at this point in the history
  • Loading branch information
rainyl committed Jan 17, 2025
1 parent 1f9a98b commit 18343d0
Show file tree
Hide file tree
Showing 3 changed files with 296 additions and 36 deletions.
25 changes: 2 additions & 23 deletions packages/dartcv/lib/src/core/vec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ class VecCharIterator extends VecIterator<int> {
int operator [](int idx) => dataView[idx];
}

class VecVecChar extends Vec<cvg.VecVecChar, VecChar> {
class VecVecChar extends VecUnmodifible<cvg.VecVecChar, VecChar> {
VecVecChar.fromPointer(super.ptr, [bool attach = true]) : super.fromPointer() {
if (attach) {
finalizer.attach(this, ptr.cast<ffi.Void>(), detach: this);
Expand Down Expand Up @@ -337,31 +337,9 @@ class VecVecChar extends Vec<cvg.VecVecChar, VecChar> {
@override
ffi.Pointer<ffi.Void> asVoid() => throw UnsupportedError('Not supported');

// TODO: add support
@override
void operator []=(int idx, VecChar value) => ccore.std_VecVecChar_set(ptr, idx, value.ptr);

@override
VecChar operator [](int idx) => VecChar.fromPointer(ccore.std_VecVecChar_get(ptr, idx), false);

@override
void add(VecChar element) => ccore.std_VecVecChar_push_back(ptr, element.ref);

@override
void clear() => ccore.std_VecVecChar_clear(ptr);

@override
void extend(Vec other) => throw UnsupportedError("Not supported");

@override
void reserve(int newCapacity) => ccore.std_VecVecChar_reserve(ptr, newCapacity);

@override
void resize(int newSize) => ccore.std_VecVecChar_resize(ptr, newSize);

@override
void shrinkToFit() => ccore.std_VecVecChar_shrink_to_fit(ptr);

@override
int size() => ccore.std_VecVecChar_length(ptr);
}
Expand Down Expand Up @@ -839,6 +817,7 @@ class VecF16 extends Vec<cvg.VecF16, double> {
}

factory VecF16([int length = 0, double value = 0.0]) => VecF16.generate(length, (i) => value);

// TODO: use setRange if dart ffi supports float16
factory VecF16.fromList(List<double> pts) => VecF16.generate(pts.length, (i) => pts[i]);

Expand Down
83 changes: 80 additions & 3 deletions packages/dartcv/test/core/point_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,23 @@ void main() {
vec1[1] = cv.Point(100, 100);
expect(vec1[1], cv.Point(100, 100));

final vec2 = vec1.clone();
vec2.add(cv.Point(10, 10));
expect(vec2.length, points.length + 1);
expect(vec2[vec2.length - 1], cv.Point(10, 10));

final vec3 = cv.VecPoint.generate(vec2.length, (i) => vec2[i]);
vec2.extend(vec3);
expect(vec2.length, vec3.length * 2);

vec3.reserve(21);
vec3.resize(21);
expect(vec3.length, 21);
expect(vec3.size(), 21);
vec3.clear();
vec3.shrinkToFit();
expect(vec3.length, 0);

vec.dispose();
});

Expand Down Expand Up @@ -124,6 +141,23 @@ void main() {
expect(points2.length, 0);
expect(points2.firstOrNull, null);

final vec2 = vec1.clone();
vec2.add(cv.Point2f(10, 10));
expect(vec2.length, points.length + 1);
expect(vec2[vec2.length - 1], cv.Point2f(10, 10));

final vec3 = cv.VecPoint2f.generate(vec2.length, (i) => vec2[i]);
vec2.extend(vec3);
expect(vec2.length, vec3.length * 2);

vec3.reserve(21);
vec3.resize(21);
expect(vec3.length, 21);
expect(vec3.size(), 21);
vec3.clear();
vec3.shrinkToFit();
expect(vec3.length, 0);

vec.dispose();
});

Expand Down Expand Up @@ -162,6 +196,23 @@ void main() {
vec1[1] = cv.Point3f(3, 4, 100);
expect(vec1[1], cv.Point3f(3, 4, 100));

final vec2 = vec1.clone();
vec2.add(cv.Point3f(10, 10, 10));
expect(vec2.length, points.length + 1);
expect(vec2[vec2.length - 1], cv.Point3f(10, 10, 10));

final vec3 = cv.VecPoint3f.generate(vec2.length, (i) => vec2[i]);
vec2.extend(vec3);
expect(vec2.length, vec3.length * 2);

vec3.reserve(21);
vec3.resize(21);
expect(vec3.length, 21);
expect(vec3.size(), 21);
vec3.clear();
vec3.shrinkToFit();
expect(vec3.length, 0);

vec.dispose();
});

Expand Down Expand Up @@ -205,9 +256,26 @@ void main() {
vec1[1] = cv.Point3i(3, 4, 100);
expect(vec1[1], cv.Point3i(3, 4, 100));

final vec2 = cv.VecPoint3i(10);
expect(vec2.length, 10);
expect(vec2.first, cv.Point3i(0, 0, 0));
final vec0 = cv.VecPoint3i(10);
expect(vec0.length, 10);
expect(vec0.first, cv.Point3i(0, 0, 0));

final vec2 = vec1.clone();
vec2.add(cv.Point3i(10, 10, 10));
expect(vec2.length, points.length + 1);
expect(vec2[vec2.length - 1], cv.Point3i(10, 10, 10));

final vec3 = cv.VecPoint3i.generate(vec2.length, (i) => vec2[i]);
vec2.extend(vec3);
expect(vec2.length, vec3.length * 2);

vec3.reserve(21);
vec3.resize(21);
expect(vec3.length, 21);
expect(vec3.size(), 21);
vec3.clear();
vec3.shrinkToFit();
expect(vec3.length, 0);

vec.dispose();
});
Expand Down Expand Up @@ -244,6 +312,9 @@ void main() {
elem[0] = cv.Point(-1, -1);
expect(elem[0], cv.Point(-1, -1));

final list = vec.copyToList();
expect(list[0][0], vec[0][0]);

vec.dispose();
});

Expand All @@ -259,6 +330,9 @@ void main() {
expect(vec.first.first, points.first.first);
expect(vec.last.last, points.last.last);

final list = vec.copyToList();
expect(list[0][0], vec[0][0]);

vec.dispose();
});

Expand All @@ -274,6 +348,9 @@ void main() {
expect(vec.first.first, points.first.first);
expect(vec.last.last, points.last.last);

final list = vec.copyToList();
expect(list[0][0], vec[0][0]);

vec.dispose();
});
}
Loading

0 comments on commit 18343d0

Please sign in to comment.