feat: link douglas peucker to real drawing area
This commit is contained in:
parent
28c4250334
commit
f80b344aa7
34164
SegmentationDouglasPeucker.Flutter/Dali.Segmentation.DouglasPeucker.h
Normal file
34164
SegmentationDouglasPeucker.Flutter/Dali.Segmentation.DouglasPeucker.h
Normal file
File diff suppressed because it is too large
Load Diff
@ -3,4 +3,4 @@ headers:
|
|||||||
entry-points:
|
entry-points:
|
||||||
- 'Dali.Segmentation.DouglasPeucker.h'
|
- 'Dali.Segmentation.DouglasPeucker.h'
|
||||||
# - 'MathLib.h'
|
# - 'MathLib.h'
|
||||||
- 'MyLib.Managed.h'
|
# - 'MyLib.Managed.h'
|
||||||
|
@ -21,6 +21,6 @@
|
|||||||
<key>CFBundleVersion</key>
|
<key>CFBundleVersion</key>
|
||||||
<string>1.0</string>
|
<string>1.0</string>
|
||||||
<key>MinimumOSVersion</key>
|
<key>MinimumOSVersion</key>
|
||||||
<string>11.0</string>
|
<string>12.0</string>
|
||||||
</dict>
|
</dict>
|
||||||
</plist>
|
</plist>
|
||||||
|
@ -358,7 +358,7 @@
|
|||||||
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
||||||
GCC_WARN_UNUSED_FUNCTION = YES;
|
GCC_WARN_UNUSED_FUNCTION = YES;
|
||||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||||
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
|
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
|
||||||
MTL_ENABLE_DEBUG_INFO = NO;
|
MTL_ENABLE_DEBUG_INFO = NO;
|
||||||
SDKROOT = iphoneos;
|
SDKROOT = iphoneos;
|
||||||
SUPPORTED_PLATFORMS = iphoneos;
|
SUPPORTED_PLATFORMS = iphoneos;
|
||||||
@ -483,7 +483,7 @@
|
|||||||
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
||||||
GCC_WARN_UNUSED_FUNCTION = YES;
|
GCC_WARN_UNUSED_FUNCTION = YES;
|
||||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||||
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
|
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
|
||||||
MTL_ENABLE_DEBUG_INFO = YES;
|
MTL_ENABLE_DEBUG_INFO = YES;
|
||||||
ONLY_ACTIVE_ARCH = YES;
|
ONLY_ACTIVE_ARCH = YES;
|
||||||
SDKROOT = iphoneos;
|
SDKROOT = iphoneos;
|
||||||
@ -532,7 +532,7 @@
|
|||||||
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
||||||
GCC_WARN_UNUSED_FUNCTION = YES;
|
GCC_WARN_UNUSED_FUNCTION = YES;
|
||||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||||
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
|
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
|
||||||
MTL_ENABLE_DEBUG_INFO = NO;
|
MTL_ENABLE_DEBUG_INFO = NO;
|
||||||
SDKROOT = iphoneos;
|
SDKROOT = iphoneos;
|
||||||
SUPPORTED_PLATFORMS = iphoneos;
|
SUPPORTED_PLATFORMS = iphoneos;
|
||||||
|
@ -23,6 +23,16 @@ class DaliPoint {
|
|||||||
|
|
||||||
return DaliPoint(x, y);
|
return DaliPoint(x, y);
|
||||||
}
|
}
|
||||||
|
@override
|
||||||
|
bool operator ==(Object other) =>
|
||||||
|
identical(this, other) ||
|
||||||
|
other is DaliPoint &&
|
||||||
|
runtimeType == other.runtimeType &&
|
||||||
|
x == other.x &&
|
||||||
|
y == other.y;
|
||||||
|
|
||||||
|
@override
|
||||||
|
int get hashCode => x.hashCode ^ y.hashCode;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
|
@ -7,62 +7,68 @@ import 'package:segmentation_douglas_peucker_flutter/gen/generated_bindings.dart
|
|||||||
import 'package:segmentation_douglas_peucker_flutter/lib.dart';
|
import 'package:segmentation_douglas_peucker_flutter/lib.dart';
|
||||||
|
|
||||||
abstract class Douglas {
|
abstract class Douglas {
|
||||||
static void runExample() {
|
static List<DaliPoint> transformDouglasPeucker(
|
||||||
final NativeLibrary nativeLibrary = NativeLibrary(Lib.init('Dali.Segmentation.DouglasPeucker'));
|
List<DaliPoint> originePoints) {
|
||||||
|
final NativeLibrary nativeLibrary =
|
||||||
|
NativeLibrary(Lib.init('Dali.Segmentation.DouglasPeucker'));
|
||||||
|
|
||||||
final Pointer<System_Exception_t> exception = calloc();
|
final Pointer<System_Exception_t> exception = calloc();
|
||||||
print('Exception allocated ! ($exception)');
|
|
||||||
|
|
||||||
final System_Type_t type = nativeLibrary.System_Drawing_Point_TypeOf();
|
final System_Type_t type = nativeLibrary.System_Drawing_Point_TypeOf();
|
||||||
|
|
||||||
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_Collections_Generic_List_A1_t points =
|
final System_Collections_Generic_List_A1_t points =
|
||||||
nativeLibrary.System_Collections_Generic_List_A1_Create_1(
|
nativeLibrary.System_Collections_Generic_List_A1_Create_1(
|
||||||
type,
|
type,
|
||||||
3,
|
originePoints.length,
|
||||||
exception,
|
exception,
|
||||||
);
|
);
|
||||||
|
|
||||||
exception.handle(onException: print);
|
for (final point in originePoints) {
|
||||||
|
final System_Drawing_Point_t nativePoint =
|
||||||
print('Points list created ! ($points)');
|
nativeLibrary.System_Drawing_Point_Create(
|
||||||
|
point.x,
|
||||||
|
point.y,
|
||||||
|
exception,
|
||||||
|
);
|
||||||
|
|
||||||
|
exception.handle();
|
||||||
nativeLibrary.System_Collections_Generic_List_A1_Add(
|
nativeLibrary.System_Collections_Generic_List_A1_Add(
|
||||||
points, type, point1, exception);
|
points, type, nativePoint, exception);
|
||||||
|
exception.handle();
|
||||||
|
}
|
||||||
|
|
||||||
|
final douglasPeuckerList = nativeLibrary
|
||||||
|
.DALI_Segmentation_SegmentationDouglasPeucker_DouglasPeuckerReduction(
|
||||||
|
points,
|
||||||
|
1,
|
||||||
|
exception,
|
||||||
|
);
|
||||||
exception.handle();
|
exception.handle();
|
||||||
|
|
||||||
print('Point1 added !');
|
final count = nativeLibrary.System_Collections_Generic_List_A1_Count_Get(
|
||||||
|
douglasPeuckerList,
|
||||||
nativeLibrary.System_Collections_Generic_List_A1_Add(
|
type,
|
||||||
points, type, point2, exception);
|
exception,
|
||||||
|
);
|
||||||
exception.handle();
|
exception.handle();
|
||||||
|
|
||||||
print('Point2 added !');
|
final List<DaliPoint> dartList = [];
|
||||||
|
|
||||||
|
for (int i = 0; i < count; i++) {
|
||||||
|
final douglasPoint =
|
||||||
|
nativeLibrary.System_Collections_Generic_List_A1_Item_Get(
|
||||||
|
douglasPeuckerList,
|
||||||
|
type,
|
||||||
|
i,
|
||||||
|
exception,
|
||||||
|
);
|
||||||
|
|
||||||
nativeLibrary.System_Collections_Generic_List_A1_Add(
|
|
||||||
points, type, point3, exception);
|
|
||||||
exception.handle();
|
exception.handle();
|
||||||
|
dartList.add(
|
||||||
|
DaliPoint.fromPointer(douglasPoint),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
print('Point3 added !');
|
return dartList;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -1,5 +1,8 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:segmentation_douglas_peucker_flutter/dali_point.dart';
|
||||||
import 'package:segmentation_douglas_peucker_flutter/douglas.dart';
|
import 'package:segmentation_douglas_peucker_flutter/douglas.dart';
|
||||||
|
import 'package:segmentation_douglas_peucker_flutter/sketcher_line.dart';
|
||||||
|
import 'package:segmentation_douglas_peucker_flutter/sketcher_points.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
runApp(const MainApp());
|
runApp(const MainApp());
|
||||||
@ -28,77 +31,56 @@ class Main extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _MainState extends State<Main> {
|
class _MainState extends State<Main> {
|
||||||
|
List<DaliPoint> _points = [];
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
// MyLib.runExample();
|
return Stack(
|
||||||
Douglas.runExample();
|
alignment: Alignment.topRight,
|
||||||
|
children: [
|
||||||
return const Text('Hello World!');
|
Listener(
|
||||||
|
behavior: HitTestBehavior.opaque,
|
||||||
// final int sum = nativeLibrary.MathLib_Math_Sum(mathLib, list, outException)
|
onPointerMove: (event) {
|
||||||
|
setState(() {
|
||||||
// final System_Object_t point1 =
|
_points.add(
|
||||||
// nativeLibrary.System_Drawing_Point_Create(200, 400, nullptr);
|
DaliPoint(
|
||||||
// final System_Object_t point2 =
|
event.localPosition.dx.toInt(),
|
||||||
// nativeLibrary.System_Drawing_Point_Create(200, 500, nullptr);
|
event.localPosition.dy.toInt(),
|
||||||
// final System_Object_t point3 =
|
),
|
||||||
// nativeLibrary.System_Drawing_Point_Create(200, 600, nullptr);
|
);
|
||||||
// final System_Object_t point4 =
|
});
|
||||||
// nativeLibrary.System_Drawing_Point_Create(200, 700, nullptr);
|
},
|
||||||
// final System_Type_t type = nativeLibrary.System_Drawing_Point_TypeOf();
|
child: SizedBox(
|
||||||
|
width: MediaQuery.sizeOf(context).width,
|
||||||
// print(DaliPoint.fromPointer(point1));
|
height: MediaQuery.sizeOf(context).height,
|
||||||
|
child: Stack(
|
||||||
// final correctType = nativeLibrary.DNObjectIs(point1, type);
|
children: [
|
||||||
|
CustomPaint(
|
||||||
// print('Correct type: $correctType');
|
painter: SketcherLine(
|
||||||
|
points: _points,
|
||||||
// final points = nativeLibrary.System_Collections_Generic_List_A1_Create_1(
|
),
|
||||||
// type,
|
),
|
||||||
// 4,
|
CustomPaint(
|
||||||
// exception,
|
painter: SketcherPoints(
|
||||||
// );
|
points: _points,
|
||||||
|
),
|
||||||
// DotNetException.handle(exception);
|
),
|
||||||
|
],
|
||||||
// final count = nativeLibrary.System_Collections_Generic_List_A1_Count_Get(
|
),
|
||||||
// points,
|
),
|
||||||
// type,
|
),
|
||||||
// exception,
|
Padding(
|
||||||
// );
|
padding: const EdgeInsets.all(32),
|
||||||
|
child: ElevatedButton(
|
||||||
// print('Count: $count');
|
onPressed: () {
|
||||||
|
final newPoints = Douglas.transformDouglasPeucker(_points);
|
||||||
// DotNetException.handle(exception);
|
setState(() {
|
||||||
|
_points = newPoints;
|
||||||
// return const Text('Hello World!');
|
});
|
||||||
|
},
|
||||||
// nativeLibrary.System_Collections_Generic_List_A1_Add(
|
child: const Text('Apply Douglas Peucker'),
|
||||||
// points, pointType, point1, nullptr);
|
),
|
||||||
// nativeLibrary.System_Collections_Generic_List_A1_Add(
|
)
|
||||||
// points, nullptr, point2, nullptr);
|
],
|
||||||
// nativeLibrary.System_Collections_Generic_List_A1_Add(
|
);
|
||||||
// points, nullptr, point3, nullptr);
|
|
||||||
// nativeLibrary.System_Collections_Generic_List_A1_Add(
|
|
||||||
// points, nullptr, point4, nullptr);
|
|
||||||
|
|
||||||
// final reduction = nativeLibrary
|
|
||||||
// .DALI_Segmentation_SegmentationDouglasPeucker_DouglasPeuckerReduction(
|
|
||||||
// points.cast(), 1, nullptr);
|
|
||||||
|
|
||||||
// final reducted = <DaliPoint>[];
|
|
||||||
|
|
||||||
// for (var i = 0; i < count; i++) {
|
|
||||||
// final item = nativeLibrary.System_Collections_Generic_List_A1_Item_Get(
|
|
||||||
// reduction, nullptr, i, nullptr);
|
|
||||||
// reducted.add(DaliPoint.fromPointer(item));
|
|
||||||
// }
|
|
||||||
|
|
||||||
// nativeLibrary.System_Collections_Generic_List_A1_Destroy(reduction);
|
|
||||||
// nativeLibrary.System_Collections_Generic_List_A1_Destroy(points);
|
|
||||||
|
|
||||||
// print(reducted);
|
|
||||||
|
|
||||||
// return Text('Hello World! ${reducted.length}');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,87 +1,87 @@
|
|||||||
import 'dart:ffi';
|
// import 'dart:ffi';
|
||||||
|
|
||||||
import 'package:ffi/ffi.dart';
|
// import 'package:ffi/ffi.dart';
|
||||||
import 'package:segmentation_douglas_peucker_flutter/dali_point.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/dotnet_exception.dart';
|
||||||
import 'package:segmentation_douglas_peucker_flutter/gen/generated_bindings.dart';
|
// import 'package:segmentation_douglas_peucker_flutter/gen/generated_bindings.dart';
|
||||||
import 'package:segmentation_douglas_peucker_flutter/lib.dart';
|
// import 'package:segmentation_douglas_peucker_flutter/lib.dart';
|
||||||
|
|
||||||
abstract class MyLib {
|
// abstract class MyLib {
|
||||||
static void runExample() {
|
// static void runExample() {
|
||||||
final NativeLibrary nativeLibrary =
|
// final NativeLibrary nativeLibrary =
|
||||||
NativeLibrary(Lib.init('MyLib.Managed'));
|
// NativeLibrary(Lib.init('MyLib.Managed'));
|
||||||
|
|
||||||
final Pointer<System_Exception_t> exception = calloc();
|
// final Pointer<System_Exception_t> exception = calloc();
|
||||||
print('Exception allocated ! ($exception)');
|
// print('Exception allocated ! ($exception)');
|
||||||
|
|
||||||
final MyLib_Hello_t hello = nativeLibrary.MyLib_Hello_Create(exception);
|
// final MyLib_Hello_t hello = nativeLibrary.MyLib_Hello_Create(exception);
|
||||||
exception.handle();
|
// exception.handle();
|
||||||
|
|
||||||
print('Hello created ! ($hello)');
|
// print('Hello created ! ($hello)');
|
||||||
|
|
||||||
final MathLib_Math_t mathLib =
|
// final MathLib_Math_t mathLib =
|
||||||
nativeLibrary.MyLib_Hello_GetMath(hello, exception);
|
// nativeLibrary.MyLib_Hello_GetMath(hello, exception);
|
||||||
exception.handle();
|
// exception.handle();
|
||||||
|
|
||||||
print('MathLib created ! ($mathLib)');
|
// print('MathLib created ! ($mathLib)');
|
||||||
|
|
||||||
final System_Drawing_Point_t point1 =
|
// final System_Drawing_Point_t point1 =
|
||||||
nativeLibrary.System_Drawing_Point_Create(200, 400, exception);
|
// nativeLibrary.System_Drawing_Point_Create(200, 400, exception);
|
||||||
exception.handle();
|
// exception.handle();
|
||||||
final DaliPoint daliPoint1 = DaliPoint.fromPointer(point1);
|
// final DaliPoint daliPoint1 = DaliPoint.fromPointer(point1);
|
||||||
|
|
||||||
print('Point1: $daliPoint1');
|
// print('Point1: $daliPoint1');
|
||||||
|
|
||||||
final System_Drawing_Point_t point2 =
|
// final System_Drawing_Point_t point2 =
|
||||||
nativeLibrary.System_Drawing_Point_Create(200, 500, exception);
|
// nativeLibrary.System_Drawing_Point_Create(200, 500, exception);
|
||||||
exception.handle();
|
// exception.handle();
|
||||||
final DaliPoint daliPoint2 = DaliPoint.fromPointer(point2);
|
// final DaliPoint daliPoint2 = DaliPoint.fromPointer(point2);
|
||||||
|
|
||||||
print('Point2: $daliPoint2');
|
// print('Point2: $daliPoint2');
|
||||||
|
|
||||||
final System_Drawing_Point_t point3 =
|
// final System_Drawing_Point_t point3 =
|
||||||
nativeLibrary.System_Drawing_Point_Create(200, 600, exception);
|
// nativeLibrary.System_Drawing_Point_Create(200, 600, exception);
|
||||||
exception.handle();
|
// exception.handle();
|
||||||
final DaliPoint daliPoint3 = DaliPoint.fromPointer(point3);
|
// final DaliPoint daliPoint3 = DaliPoint.fromPointer(point3);
|
||||||
|
|
||||||
print('Point3: $daliPoint3');
|
// print('Point3: $daliPoint3');
|
||||||
|
|
||||||
final System_Type_t pointType = nativeLibrary.System_Drawing_Point_TypeOf();
|
// final System_Type_t pointType = nativeLibrary.System_Drawing_Point_TypeOf();
|
||||||
|
|
||||||
final System_Collections_Generic_List_A1_t points =
|
// final System_Collections_Generic_List_A1_t points =
|
||||||
nativeLibrary.System_Collections_Generic_List_A1_Create_1(
|
// nativeLibrary.System_Collections_Generic_List_A1_Create_1(
|
||||||
pointType,
|
// pointType,
|
||||||
3,
|
// 3,
|
||||||
exception,
|
// exception,
|
||||||
);
|
// );
|
||||||
|
|
||||||
exception.handle();
|
// exception.handle();
|
||||||
|
|
||||||
print('Points list created ! ($points)');
|
// print('Points list created ! ($points)');
|
||||||
|
|
||||||
nativeLibrary.System_Collections_Generic_List_A1_Add(
|
// nativeLibrary.System_Collections_Generic_List_A1_Add(
|
||||||
points, pointType, point1, exception);
|
// points, pointType, point1, exception);
|
||||||
exception.handle();
|
// exception.handle();
|
||||||
|
|
||||||
print('Point1 added !');
|
// print('Point1 added !');
|
||||||
|
|
||||||
nativeLibrary.System_Collections_Generic_List_A1_Add(
|
// nativeLibrary.System_Collections_Generic_List_A1_Add(
|
||||||
points, pointType, point2, exception);
|
// points, pointType, point2, exception);
|
||||||
exception.handle();
|
// exception.handle();
|
||||||
|
|
||||||
print('Point2 added !');
|
// print('Point2 added !');
|
||||||
|
|
||||||
nativeLibrary.System_Collections_Generic_List_A1_Add(
|
// nativeLibrary.System_Collections_Generic_List_A1_Add(
|
||||||
points, pointType, point3, exception);
|
// points, pointType, point3, exception);
|
||||||
exception.handle();
|
// exception.handle();
|
||||||
|
|
||||||
print('Point3 added !');
|
// print('Point3 added !');
|
||||||
|
|
||||||
final pointSum =
|
// final pointSum =
|
||||||
nativeLibrary.MathLib_Math_SumPoints(mathLib, points, exception);
|
// nativeLibrary.MathLib_Math_SumPoints(mathLib, points, exception);
|
||||||
exception.handle();
|
// exception.handle();
|
||||||
final DaliPoint daliPointSum = DaliPoint.fromPointer(pointSum);
|
// final DaliPoint daliPointSum = DaliPoint.fromPointer(pointSum);
|
||||||
|
|
||||||
print('Point sum: $daliPointSum');
|
// print('Point sum: $daliPointSum');
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
44
SegmentationDouglasPeucker.Flutter/lib/sketcher_line.dart
Normal file
44
SegmentationDouglasPeucker.Flutter/lib/sketcher_line.dart
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
import 'package:flutter/material.dart' hide TextStyle;
|
||||||
|
import 'package:segmentation_douglas_peucker_flutter/dali_point.dart';
|
||||||
|
|
||||||
|
class SketcherLine extends CustomPainter {
|
||||||
|
SketcherLine({
|
||||||
|
required this.points,
|
||||||
|
});
|
||||||
|
|
||||||
|
final List<DaliPoint> points;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void paint(Canvas canvas, Size size) {
|
||||||
|
final Paint paint = Paint()
|
||||||
|
..style = PaintingStyle.stroke
|
||||||
|
..strokeWidth = 10;
|
||||||
|
|
||||||
|
// Set the paint options.
|
||||||
|
paint.color = Colors.blue;
|
||||||
|
|
||||||
|
final path = Path();
|
||||||
|
|
||||||
|
if (points.isEmpty) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Otherwise, draw a line that connects each point with a curve.
|
||||||
|
path.moveTo(
|
||||||
|
points[0].x.toDouble(),
|
||||||
|
points[0].y.toDouble(),
|
||||||
|
);
|
||||||
|
|
||||||
|
for (int i = 0; i < points.length; i++) {
|
||||||
|
path.lineTo(
|
||||||
|
points[i].x.toDouble(),
|
||||||
|
points[i].y.toDouble(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
canvas.drawPath(path, paint);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool shouldRepaint(SketcherLine oldDelegate) => true;
|
||||||
|
}
|
46
SegmentationDouglasPeucker.Flutter/lib/sketcher_points.dart
Normal file
46
SegmentationDouglasPeucker.Flutter/lib/sketcher_points.dart
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
import 'package:flutter/material.dart' hide TextStyle;
|
||||||
|
import 'package:segmentation_douglas_peucker_flutter/dali_point.dart';
|
||||||
|
|
||||||
|
class SketcherPoints extends CustomPainter {
|
||||||
|
SketcherPoints({
|
||||||
|
required this.points,
|
||||||
|
});
|
||||||
|
|
||||||
|
final List<DaliPoint> points;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void paint(Canvas canvas, Size size) {
|
||||||
|
final Paint paint = Paint();
|
||||||
|
|
||||||
|
paint.color = Colors.red;
|
||||||
|
|
||||||
|
final path = Path();
|
||||||
|
|
||||||
|
if (points.isEmpty) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Otherwise, draw a line that connects each point with a curve.
|
||||||
|
path.moveTo(
|
||||||
|
points[0].x.toDouble(),
|
||||||
|
points[0].y.toDouble(),
|
||||||
|
);
|
||||||
|
|
||||||
|
for (int i = 0; i < points.length; i++) {
|
||||||
|
path.addOval(
|
||||||
|
Rect.fromCircle(
|
||||||
|
center: Offset(
|
||||||
|
points[i].x.toDouble(),
|
||||||
|
points[i].y.toDouble(),
|
||||||
|
),
|
||||||
|
radius: 5,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
canvas.drawPath(path, paint);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool shouldRepaint(SketcherPoints oldDelegate) => true;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user