88 lines
2.6 KiB
Dart

import 'dart:ffi';
import 'package:ffi/ffi.dart';
import 'package:segmentation_douglas_peucker_flutter/dali_point.dart';
import 'package:segmentation_douglas_peucker_flutter/dotnet_exception.dart';
import 'package:segmentation_douglas_peucker_flutter/gen/generated_bindings.dart';
import 'package:segmentation_douglas_peucker_flutter/lib.dart';
abstract class MyLib {
static void runExample() {
final NativeLibrary nativeLibrary =
NativeLibrary(Lib.init('MyLib.Managed'));
final Pointer<System_Exception_t> exception = calloc();
print('Exception allocated ! ($exception)');
final MyLib_Hello_t hello = nativeLibrary.MyLib_Hello_Create(exception);
exception.handle();
print('Hello created ! ($hello)');
final MathLib_Math_t mathLib =
nativeLibrary.MyLib_Hello_GetMath(hello, exception);
exception.handle();
print('MathLib created ! ($mathLib)');
final System_Drawing_Point_t point1 =
nativeLibrary.System_Drawing_Point_Create(200, 400, exception);
exception.handle();
final DaliPoint daliPoint1 = DaliPoint.fromPointer(point1);
print('Point1: $daliPoint1');
final System_Drawing_Point_t point2 =
nativeLibrary.System_Drawing_Point_Create(200, 500, exception);
exception.handle();
final DaliPoint daliPoint2 = DaliPoint.fromPointer(point2);
print('Point2: $daliPoint2');
final System_Drawing_Point_t point3 =
nativeLibrary.System_Drawing_Point_Create(200, 600, exception);
exception.handle();
final DaliPoint daliPoint3 = DaliPoint.fromPointer(point3);
print('Point3: $daliPoint3');
final System_Type_t pointType = nativeLibrary.System_Drawing_Point_TypeOf();
final System_Collections_Generic_List_A1_t points =
nativeLibrary.System_Collections_Generic_List_A1_Create_1(
pointType,
3,
exception,
);
exception.handle();
print('Points list created ! ($points)');
nativeLibrary.System_Collections_Generic_List_A1_Add(
points, pointType, point1, exception);
exception.handle();
print('Point1 added !');
nativeLibrary.System_Collections_Generic_List_A1_Add(
points, pointType, point2, exception);
exception.handle();
print('Point2 added !');
nativeLibrary.System_Collections_Generic_List_A1_Add(
points, pointType, point3, exception);
exception.handle();
print('Point3 added !');
final pointSum =
nativeLibrary.MathLib_Math_SumPoints(mathLib, points, exception);
exception.handle();
final DaliPoint daliPointSum = DaliPoint.fromPointer(pointSum);
print('Point sum: $daliPointSum');
}
}