Skip to content

Commit

Permalink
Implemented de casteljau algorithm for n-degree curve
Browse files Browse the repository at this point in the history
  • Loading branch information
DEVSOG12 committed Nov 21, 2024
1 parent bd460d1 commit 7a72fff
Show file tree
Hide file tree
Showing 22 changed files with 707 additions and 229 deletions.
68 changes: 34 additions & 34 deletions .firebase/hosting.YnVpbGQvd2Vi.cache
Original file line number Diff line number Diff line change
@@ -1,50 +1,50 @@
version.json,1731653320431,f2657e7a1274681b8503dd42ab48b484270572dedbc3e9cb2a19d342e158ec3e
manifest.json,1731644751302,a3b2cb48e7d5d2271ea088005f13a9d8b46d89ba24b569aba4fc6ac0a23c079b
index.html,1731653320343,3a0748d9e72b873dbac286b131700e250d8d7324fda0ca6f8221c8cc06ffa435
favicon.png,1701696321690,fcc7c4545d5b62ad01682589e6fdc7ea03d0a3b42069963c815c344b632eb5cf
flutter_bootstrap.js,1731653320339,18d8aff5194d5c46642e220b5c31ade40a469612ffc92b515c06d5109088b639
flutter.js,1726070018000,dec659847e4e16b505a257eb15bc32ef814f99a319e44e15b9c56294de0c9ecd
flutter_service_worker.js,1731653321718,fb8b133c1d0de9ceedd75758d34900895a30d49eacb003ea562e3182e1cbc4e4
canvaskit/skwasm.worker.js,1726070388000,ff1a6b2c254c1954106d62ce10432547fa6d6a7d99c0aaf9ea6144a23ef0c09b
icons/Icon-maskable-512.png,1703347078778,e7983524dc70254adc61764657d7e03d19284de8da586b5818d737bc08c6d14e
icons/Icon-maskable-192.png,1703347078779,dd96c123fdf6817cdf7e63d9693bcc246bac2e3782a41a6952fa41c0617c5573
icons/Icon-192.png,1701696321690,d2e0131bb7851eb9d98f7885edb5ae4b4d6b7a6c7addf8a25b9b712b39274c0f
icons/Icon-512.png,1701696321690,7a31ce91e554f1941158ca46f31c7f3f2b7c8c129229ea74a8fae1affe335033
assets/FontManifest.json,1731653320499,a3743cd8b7a894a83a61c2192339ca47cd4990b57c998c728909114b1f47c1cc
assets/AssetManifest.json,1731653320498,0522a8dd1892d7eb604de6a8e01fb1f9f9b5bdb2cd550afdc468df9d8bd5ccbc
assets/AssetManifest.bin,1731653320498,cbeea261c0e94208e916b59b036ac0017e491349baeac2ab8f63e34fe6b94e4f
assets/AssetManifest.bin.json,1731653320498,b5129d36e93b92dbc64531067694b76377af1584fa82ccca273ce7b96d4ccecb
assets/shaders/ink_sparkle.frag,1731653320591,80c6e65c75f1de434b1b22dba61e96ad82dba0f2fc5e8b3b59c2def46d794354
icons/Icon-192.png,1701696321690,d2e0131bb7851eb9d98f7885edb5ae4b4d6b7a6c7addf8a25b9b712b39274c0f
assets/packages/flutter_math_fork/lib/katex_fonts/fonts/KaTeX_Typewriter-Regular.ttf,1731649075823,61d65359d17f0c70d1e59da65d86595afc557b378c0eaa6ac644f2195cd13a56
assets/packages/flutter_math_fork/lib/katex_fonts/fonts/KaTeX_Size4-Regular.ttf,1731649075818,281b07b196277453a94403c1e87545be03c99c7388d430e12f415f422cfc484c
assets/packages/flutter_math_fork/lib/katex_fonts/fonts/KaTeX_Size3-Regular.ttf,1731649075823,82b1a431b4f7ebc248477b69513580f0ad6190269a7fd8ee415a0e8f3953828a
assets/packages/flutter_math_fork/lib/katex_fonts/fonts/KaTeX_Size2-Regular.ttf,1731649075820,b0b1f6d5bd0cf7538a7197312ba2097685de3ee590b66a95214ad278a38d0475
assets/packages/flutter_math_fork/lib/katex_fonts/fonts/KaTeX_Size1-Regular.ttf,1731649075819,9e28e11cf934cd01515a8f316644b1b3a22f93fce2fac40923ca12569b7d2d0c
assets/packages/flutter_math_fork/lib/katex_fonts/fonts/KaTeX_Size3-Regular.ttf,1731649075823,82b1a431b4f7ebc248477b69513580f0ad6190269a7fd8ee415a0e8f3953828a
assets/packages/flutter_math_fork/lib/katex_fonts/fonts/KaTeX_Script-Regular.ttf,1731649075823,c13a80c9bb97c063fab70c419c22343f06230da2db7670f869b45a6c4b3a6391
assets/packages/flutter_math_fork/lib/katex_fonts/fonts/KaTeX_SansSerif-Regular.ttf,1731649075820,0bebe5ac29e3304fdc0d551db5d1ff54f49c9bac716e189b1acf284e90e3f23a
assets/packages/flutter_math_fork/lib/katex_fonts/fonts/KaTeX_Fraktur-Bold.ttf,1731649075820,726b9ed77660287254e179c574f205f29d5d5127b473de926d8c2aaffce30706
assets/packages/flutter_math_fork/lib/katex_fonts/fonts/KaTeX_Fraktur-Regular.ttf,1731649075822,b657a37821a0582f42cbc6fcd02da3f9b65f19cd9ca3345bcf84be6d6d1e34d8
assets/packages/cupertino_icons/assets/CupertinoIcons.ttf,1731653321369,a9dec9e47fcee105fc5f7ea79904e588215596ef681f1ba97034cd0829c0554b
assets/fonts/MaterialIcons-Regular.otf,1731653321370,b79d28e6db3c7919023ec2e63190b1bc3322197ec7e63e9e1ec76dfc7a22f197
assets/packages/flutter_math_fork/lib/katex_fonts/fonts/KaTeX_Caligraphic-Regular.ttf,1731649075819,b1250ddd8777e039de487a089f4d0b9badcf91553859924009e1560082a467f4
assets/packages/flutter_math_fork/lib/katex_fonts/fonts/KaTeX_Caligraphic-Bold.ttf,1731649075823,ba3d35b9d7bf313c98a43e1ac25c6b3df1ebb54a3348e22dea213e88d0f180a9
icons/Icon-maskable-512.png,1703347078778,e7983524dc70254adc61764657d7e03d19284de8da586b5818d737bc08c6d14e
assets/packages/flutter_math_fork/lib/katex_fonts/fonts/KaTeX_Typewriter-Regular.ttf,1731649075823,61d65359d17f0c70d1e59da65d86595afc557b378c0eaa6ac644f2195cd13a56
assets/packages/flutter_math_fork/lib/katex_fonts/fonts/KaTeX_SansSerif-Italic.ttf,1731649075821,903ac3c35adce16c00b9b7b71f0e159173c500992e65b491426cff6db385df43
assets/packages/flutter_math_fork/lib/katex_fonts/fonts/KaTeX_SansSerif-Bold.ttf,1731649075823,1612939bfbfc2ce4259a0ee40b5aabf6dd3b509e6dd53a497b72510ec214ab6a
assets/packages/flutter_math_fork/lib/katex_fonts/fonts/KaTeX_Math-BoldItalic.ttf,1731649075818,90dab2eb61d5b18a925525d5fe3c4cc4ece0a55a647f97fa012f77847061e286
assets/packages/flutter_math_fork/lib/katex_fonts/fonts/KaTeX_Math-Italic.ttf,1731649075821,1a27dddd0cc1222a63d1f9c2cbf4c8abad0b39fc50616101ed26f376be3ec8c5
assets/packages/flutter_math_fork/lib/katex_fonts/fonts/KaTeX_Math-BoldItalic.ttf,1731649075818,90dab2eb61d5b18a925525d5fe3c4cc4ece0a55a647f97fa012f77847061e286
assets/packages/flutter_math_fork/lib/katex_fonts/fonts/KaTeX_Main-Regular.ttf,1731649075822,3bafd79cffe8d198b2fa860b7d4cf6dcf0536514e7f01da1b466f1e13e7ac83a
assets/packages/flutter_math_fork/lib/katex_fonts/fonts/KaTeX_Main-Italic.ttf,1731649075820,62177cd5de2fe747f0fafb6d0a35b6fbd52e938faeb89bafd5eaf478727738cf
canvaskit/skwasm.js,1726070388000,3da3d8d5b168f8f2cba2513cba2c65a9bfa650723545145cffa76a102a678e9d
assets/packages/flutter_math_fork/lib/katex_fonts/fonts/KaTeX_Main-BoldItalic.ttf,1731649075818,6a24be083618b051e723bf13d0e895418a0d9da26e0a33fc07ec1ee245e028d8
canvaskit/canvaskit.js,1726070300000,95f051f3c2845fb04127fd56e1fa3e52a69d271eea561869e97bfe4374548109
canvaskit/chromium/canvaskit.js,1726070322000,c448a9b3e29d0dad724aa33a554695e7f1257c58b28baca305177fd18e62e411
assets/packages/flutter_math_fork/lib/katex_fonts/fonts/KaTeX_Main-Bold.ttf,1731649075822,c5c7214e8c8f207e20702411b097858eb3a6a2fe5ce7dcd691316014de26786e
assets/packages/flutter_math_fork/lib/katex_fonts/fonts/KaTeX_Main-Regular.ttf,1731649075822,3bafd79cffe8d198b2fa860b7d4cf6dcf0536514e7f01da1b466f1e13e7ac83a
assets/packages/flutter_math_fork/lib/katex_fonts/fonts/KaTeX_Fraktur-Regular.ttf,1731649075822,b657a37821a0582f42cbc6fcd02da3f9b65f19cd9ca3345bcf84be6d6d1e34d8
assets/packages/flutter_math_fork/lib/katex_fonts/fonts/KaTeX_Fraktur-Bold.ttf,1731649075820,726b9ed77660287254e179c574f205f29d5d5127b473de926d8c2aaffce30706
assets/packages/flutter_math_fork/lib/katex_fonts/fonts/KaTeX_Caligraphic-Regular.ttf,1731649075819,b1250ddd8777e039de487a089f4d0b9badcf91553859924009e1560082a467f4
assets/packages/flutter_math_fork/lib/katex_fonts/fonts/KaTeX_Caligraphic-Bold.ttf,1731649075823,ba3d35b9d7bf313c98a43e1ac25c6b3df1ebb54a3348e22dea213e88d0f180a9
assets/packages/flutter_math_fork/lib/katex_fonts/fonts/KaTeX_AMS-Regular.ttf,1731649075824,786c7693acb17482846b770485db32dca92202e7e2d7320c07751c74fcf2d4ab
assets/NOTICES,1731653320499,8b3196368364ea90a6a2ff21bac239bb296b05586efeb61303a166b13a41d225
canvaskit/chromium/canvaskit.js.symbols,1726070320000,9d7b8e9cc146e9ad2b68af9f0c8092b144a9aac73666941b468b8b2fd36cdb27
canvaskit/canvaskit.js.symbols,1726070298000,7687fed87ac2c6f61e5d991be1e3f8c0191e4271128c73a5afea2f28562ad0b8
canvaskit/skwasm.js.symbols,1726070388000,ea615fdcd1320bad0f3fb6b3e5bcb0dd3a4d8480c221af6a84455860775987c1
main.dart.js,1731652554823,8d54effa914359ccf4c17eff5f5eb8a5cbbc16ac97ea800ed47510d15b98fabc
canvaskit/skwasm.wasm,1726070388000,204bb6c7deaa41ccfdb811d09107bcacd7162a848d8e9faa45e46390fe0dda9a
canvaskit/chromium/canvaskit.wasm,1726070322000,d865adf21902388e4d4af54a5e430479e5ef37ac660649017db1877b29976a08
canvaskit/canvaskit.wasm,1726070300000,2e91b313aa59675be755df469bb88efdfa2be8cdccc4e49bf743f9f22d16f933
version.json,1732211962903,f2657e7a1274681b8503dd42ab48b484270572dedbc3e9cb2a19d342e158ec3e
flutter.js,1731451886000,dec659847e4e16b505a257eb15bc32ef814f99a319e44e15b9c56294de0c9ecd
flutter_service_worker.js,1732211964647,04faa8f4d46174aa99814811ef1015c073b213008801a5b574f6bb70ce5e6c49
index.html,1732211937228,3a0748d9e72b873dbac286b131700e250d8d7324fda0ca6f8221c8cc06ffa435
canvaskit/skwasm.worker.js,1731452204000,ff1a6b2c254c1954106d62ce10432547fa6d6a7d99c0aaf9ea6144a23ef0c09b
flutter_bootstrap.js,1732211937223,5c73364364305a0fd66bde90a9be3e16acfc7eae045382101174e6d2f29c3465
assets/FontManifest.json,1732211962996,a3743cd8b7a894a83a61c2192339ca47cd4990b57c998c728909114b1f47c1cc
assets/AssetManifest.bin.json,1732211962996,b5129d36e93b92dbc64531067694b76377af1584fa82ccca273ce7b96d4ccecb
assets/AssetManifest.json,1732211962996,0522a8dd1892d7eb604de6a8e01fb1f9f9b5bdb2cd550afdc468df9d8bd5ccbc
assets/shaders/ink_sparkle.frag,1732211963089,80c6e65c75f1de434b1b22dba61e96ad82dba0f2fc5e8b3b59c2def46d794354
assets/AssetManifest.bin,1732211962996,cbeea261c0e94208e916b59b036ac0017e491349baeac2ab8f63e34fe6b94e4f
assets/fonts/MaterialIcons-Regular.otf,1732211964381,b79d28e6db3c7919023ec2e63190b1bc3322197ec7e63e9e1ec76dfc7a22f197
assets/packages/cupertino_icons/assets/CupertinoIcons.ttf,1732211964379,a9dec9e47fcee105fc5f7ea79904e588215596ef681f1ba97034cd0829c0554b
canvaskit/canvaskit.js,1731452126000,95f051f3c2845fb04127fd56e1fa3e52a69d271eea561869e97bfe4374548109
canvaskit/skwasm.js,1731452204000,3da3d8d5b168f8f2cba2513cba2c65a9bfa650723545145cffa76a102a678e9d
canvaskit/chromium/canvaskit.js,1731452144000,c448a9b3e29d0dad724aa33a554695e7f1257c58b28baca305177fd18e62e411
assets/NOTICES,1732211962997,a1360b4fe086d972cde16ce0dff675c26395b4e6bb5fc44ffdfbe9a2fdf1710a
canvaskit/chromium/canvaskit.js.symbols,1731452142000,9d7b8e9cc146e9ad2b68af9f0c8092b144a9aac73666941b468b8b2fd36cdb27
canvaskit/canvaskit.js.symbols,1731452124000,7687fed87ac2c6f61e5d991be1e3f8c0191e4271128c73a5afea2f28562ad0b8
canvaskit/skwasm.js.symbols,1731452202000,ea615fdcd1320bad0f3fb6b3e5bcb0dd3a4d8480c221af6a84455860775987c1
main.dart.js,1732211962141,d21336a8e28494a94324c8e4165a82ebb562adfd1c0f82e4a1507e18fcc824c7
canvaskit/skwasm.wasm,1731452204000,204bb6c7deaa41ccfdb811d09107bcacd7162a848d8e9faa45e46390fe0dda9a
canvaskit/chromium/canvaskit.wasm,1731452144000,d865adf21902388e4d4af54a5e430479e5ef37ac660649017db1877b29976a08
canvaskit/canvaskit.wasm,1731452126000,2e91b313aa59675be755df469bb88efdfa2be8cdccc4e49bf743f9f22d16f933
1 change: 1 addition & 0 deletions ios/Flutter/Debug.xcconfig
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
#include "Generated.xcconfig"
1 change: 1 addition & 0 deletions ios/Flutter/Release.xcconfig
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
#include "Generated.xcconfig"
44 changes: 44 additions & 0 deletions ios/Podfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Uncomment this line to define a global platform for your project
# platform :ios, '12.0'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'

project 'Runner', {
'Debug' => :debug,
'Profile' => :release,
'Release' => :release,
}

def flutter_root
generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__)
unless File.exist?(generated_xcode_build_settings_path)
raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first"
end

File.foreach(generated_xcode_build_settings_path) do |line|
matches = line.match(/FLUTTER_ROOT\=(.*)/)
return matches[1].strip if matches
end
raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get"
end

require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)

flutter_ios_podfile_setup

target 'Runner' do
use_frameworks!
use_modular_headers!

flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
target 'RunnerTests' do
inherit! :search_paths
end
end

post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_ios_build_settings(target)
end
end
1 change: 1 addition & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// main.dart
import 'package:bezier_curve_scicomp/src/UI/bezier_curve_screen.dart';
import 'package:flutter/material.dart';

Expand Down
131 changes: 93 additions & 38 deletions lib/src/UI/bezier_canvas.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,28 @@ import 'package:bezier_curve_scicomp/src/math/models/points.dart';
import 'package:flutter/material.dart';

class BezierCanvasPainter extends CustomPainter {
final BezierCurve bezierCurve;
final BezierCurve? bezierCurve; // Optional single Bézier curve
final List<Points>? shapePoints; // Optional combined points for a shape
final int numPoints;
final double tValue;

// Expose the translation offsets
double dx = 0.0;
double dy = 0.0;

BezierCanvasPainter({
required this.bezierCurve,


BezierCanvasPainter(
{
this.bezierCurve,
this.shapePoints,
this.numPoints = 100,
required this.tValue,
});
}) ;
// :
// // both shouldn't be set at the same time
// assert(bezierCurve == null || shapePoints == null);


@override
void paint(Canvas canvas, Size size) {
Expand All @@ -25,20 +34,24 @@ class BezierCanvasPainter extends CustomPainter {
// Draw grid background
_drawGrid(canvas, size);

// Center the curve in the canvas
// Center the shape in the canvas
canvas.save();

// Calculate the offset to center the curve
final curveBounds = _getCurveBounds();
// Calculate the offset to center the shape or curve
final curveBounds = _getBounds();
dx = (size.width - curveBounds.width) / 2 - curveBounds.left;
dy = (size.height - curveBounds.height) / 2 - curveBounds.top;
canvas.translate(dx, dy);

// Draw x and y axes
_drawAxes(canvas, size);

// Draw the Bézier curve
_drawBezierCurve(canvas);
// Draw the shape or Bézier curve
if (shapePoints != null) {
_drawShape(canvas, shapePoints!);
} else if (bezierCurve != null) {
_drawBezierCurve(canvas);
}

// Restore the canvas
canvas.restore();
Expand All @@ -64,9 +77,6 @@ class BezierCanvasPainter extends CustomPainter {
..color = Colors.black
..strokeWidth = 1;

// Since we've translated the canvas to center the curve,
// we need to draw the axes accordingly.

// Calculate the extents of the canvas in the translated coordinate system
double left = -dx;
double right = size.width - dx;
Expand All @@ -88,14 +98,30 @@ class BezierCanvasPainter extends CustomPainter {
);
}

void _drawShape(Canvas canvas, List<Points> points) {
final paint = Paint()
..color = Colors.blue
..strokeWidth = 2
..style = PaintingStyle.stroke;

final path = Path();
if (points.isNotEmpty) {
path.moveTo(points[0].x, points[0].y);
for (int i = 1; i < points.length; i++) {
path.lineTo(points[i].x, points[i].y);
}
canvas.drawPath(path, paint);
}
}

void _drawBezierCurve(Canvas canvas) {
final paint = Paint()
..color = Colors.blue
..strokeWidth = 2
..style = PaintingStyle.stroke;

// Generate curve points using BezierCurve
List<Points> points = bezierCurve.generateCurvePoints(numPoints: numPoints);
List<Points> points = bezierCurve!.generateCurvePoints(numPoints: numPoints);

// Create a path to draw the curve
if (points.isNotEmpty) {
Expand All @@ -108,7 +134,7 @@ class BezierCanvasPainter extends CustomPainter {
}

// Draw the point at tValue
final pointAtT = bezierCurve.evaluate(tValue);
final pointAtT = bezierCurve!.evaluate(tValue);
final pointPaint = Paint()
..color = Colors.green
..style = PaintingStyle.fill;
Expand All @@ -117,6 +143,9 @@ class BezierCanvasPainter extends CustomPainter {

// Draw control points and lines
_drawControlPointsAndLines(canvas);

// Optional: Visualize De Casteljau's algorithm
_drawDeCasteljauLines(canvas, tValue);
}

void _drawControlPointsAndLines(Canvas canvas) {
Expand All @@ -125,10 +154,9 @@ class BezierCanvasPainter extends CustomPainter {
..color = Colors.red
..style = PaintingStyle.fill;

_drawPoint(canvas, bezierCurve.p1, controlPaint);
_drawPoint(canvas, bezierCurve.p2, controlPaint);
_drawPoint(canvas, bezierCurve.p3, controlPaint);
_drawPoint(canvas, bezierCurve.p4, controlPaint);
for (Points point in bezierCurve!.controlPoints) {
_drawPoint(canvas, point, controlPaint);
}

// Draw lines connecting control points
final controlLinePaint = Paint()
Expand All @@ -137,32 +165,25 @@ class BezierCanvasPainter extends CustomPainter {
..style = PaintingStyle.stroke;

final controlPath = Path();
controlPath.moveTo(bezierCurve.p1.x, bezierCurve.p1.y);
controlPath.lineTo(bezierCurve.p2.x, bezierCurve.p2.y);
controlPath.lineTo(bezierCurve.p3.x, bezierCurve.p3.y);
controlPath.lineTo(bezierCurve.p4.x, bezierCurve.p4.y);
canvas.drawPath(controlPath, controlLinePaint);
if (bezierCurve!.controlPoints.isNotEmpty) {
controlPath.moveTo(bezierCurve!.controlPoints[0].x, bezierCurve!.controlPoints[0].y);
for (int i = 1; i < bezierCurve!.controlPoints.length; i++) {
controlPath.lineTo(bezierCurve!.controlPoints[i].x, bezierCurve!.controlPoints[i].y);
}
canvas.drawPath(controlPath, controlLinePaint);
}
}

// Helper method to draw points
void _drawPoint(Canvas canvas, Points point, Paint paint) {
canvas.drawCircle(Offset(point.x, point.y), 6, paint);
}

// Calculate the bounding rectangle of the curve and control points
Rect _getCurveBounds() {
List<double> xs = [
bezierCurve.p1.x,
bezierCurve.p2.x,
bezierCurve.p3.x,
bezierCurve.p4.x
];
List<double> ys = [
bezierCurve.p1.y,
bezierCurve.p2.y,
bezierCurve.p3.y,
bezierCurve.p4.y
];
// Calculate the bounding rectangle of the shape or curve
Rect _getBounds() {
List<Points> points = shapePoints ?? bezierCurve!.generateCurvePoints(numPoints: numPoints);
List<double> xs = points.map((p) => p.x).toList();
List<double> ys = points.map((p) => p.y).toList();

double minX = xs.reduce((a, b) => a < b ? a : b);
double maxX = xs.reduce((a, b) => a > b ? a : b);
Expand All @@ -172,9 +193,43 @@ class BezierCanvasPainter extends CustomPainter {
return Rect.fromLTRB(minX, minY, maxX, maxY);
}

// Optional: Visualize De Casteljau's algorithm
void _drawDeCasteljauLines(Canvas canvas, double t) {
List<Points> points = List.from(bezierCurve!.controlPoints);
final deCasteljauPaint = Paint()
..color = Colors.orange
..strokeWidth = 1
..style = PaintingStyle.stroke;

while (points.length > 1) {
List<Points> nextLevelPoints = [];
for (int i = 0; i < points.length - 1; i++) {
Points p0 = points[i];
Points p1 = points[i + 1];
Points interpolatedPoint = Points(
(1 - t) * p0.x + t * p1.x,
(1 - t) * p0.y + t * p1.y,
);
nextLevelPoints.add(interpolatedPoint);

// Draw line between p0 and p1
canvas.drawLine(
Offset(p0.x, p0.y),
Offset(p1.x, p1.y),
deCasteljauPaint,
);

// Draw the interpolated point
_drawPoint(canvas, interpolatedPoint, deCasteljauPaint);
}
points = nextLevelPoints;
}
}

@override
bool shouldRepaint(covariant BezierCanvasPainter oldDelegate) {
return bezierCurve != oldDelegate.bezierCurve ||
return shapePoints != oldDelegate.shapePoints ||
bezierCurve != oldDelegate.bezierCurve ||
tValue != oldDelegate.tValue;
}
}
Loading

0 comments on commit 7a72fff

Please sign in to comment.