-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
323 additions
and
89 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
lib/data/organization_structure_data.dart → lib/constants/organization_structure.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
import '../geometry/fit_point_spline.dart'; | ||
import '../geometry/point.dart'; | ||
import '../widgets/editor/editor_config.dart'; | ||
|
||
extension CanvasExtension on Canvas { | ||
void drawPoint(Point point, double scaleInverse) { | ||
final Paint paint = Paint() | ||
..color = Colors.white | ||
..strokeWidth = 2 * scaleInverse | ||
..style = PaintingStyle.fill; | ||
|
||
final Paint outlinePaint = Paint() | ||
..color = Colors.grey.shade900 | ||
..strokeWidth = 2 * scaleInverse | ||
..style = PaintingStyle.stroke; | ||
|
||
double radius = EditorConfig.pointRadius * scaleInverse; | ||
drawCircle(point.toOffset(), radius, paint); | ||
drawCircle(point.toOffset(), radius, outlinePaint); | ||
} | ||
|
||
// TODO figure out a way to draw the spline (auto resolving the Start/End points) - remove the parameters start and end | ||
void drawFitPointSpline(FitPointSpline spline, FixedPoint a, FixedPoint b, | ||
double scaleInverse, bool showControlPoints) { | ||
final Paint splinePaint = Paint() | ||
..color = Colors.white | ||
..strokeWidth = 2 * scaleInverse | ||
..style = PaintingStyle.stroke; | ||
|
||
final Paint tangentHandleLinePaint = Paint() | ||
..color = Colors.white | ||
..strokeWidth = 1 * scaleInverse | ||
..style = PaintingStyle.stroke; | ||
|
||
List<VoidCallback> topLayer = []; | ||
|
||
Path path = Path(); | ||
path.moveTo(a.x, a.y); | ||
FixedPoint lastOut = a + spline.aRelativeOut; | ||
|
||
for (int i = 0; i < spline.controlPoints.length; i++) { | ||
ControlPoint current = spline.controlPoints[i]; | ||
FixedPoint inTangent = current.inTangent; | ||
|
||
path.cubicTo( | ||
lastOut.x, lastOut.y, inTangent.x, inTangent.y, current.x, current.y); | ||
|
||
lastOut = current.outTangent; | ||
|
||
if (!showControlPoints) continue; | ||
|
||
FixedPoint outTangent = current.outTangent; | ||
topLayer.add(() { | ||
drawPoint(current, scaleInverse); | ||
|
||
drawPoint(inTangent, scaleInverse); | ||
drawPoint(outTangent, scaleInverse); | ||
drawLine(inTangent.toOffset(), outTangent.toOffset(), | ||
tangentHandleLinePaint); | ||
}); | ||
} | ||
|
||
FixedPoint bIn = b + spline.bRelativeIn; | ||
|
||
path.cubicTo(lastOut.x, lastOut.y, bIn.x, bIn.y, b.x, b.y); | ||
|
||
drawPath(path, splinePaint); | ||
|
||
for (VoidCallback topLayerAction in topLayer) { | ||
topLayerAction(); | ||
} | ||
} | ||
} |
6 changes: 5 additions & 1 deletion
6
lib/extensions/list_extensions.dart → lib/extensions/list_extension.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import 'package:toolfoam/models/json_serializable.dart'; | ||
import 'package:toolfoam/models/tf_id.dart'; | ||
|
||
abstract class Curve implements JsonSerializable { | ||
abstract TfId a; | ||
abstract TfId b; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import 'package:toolfoam/geometry/point.dart'; | ||
import 'package:toolfoam/geometry/tangent_handle.dart'; | ||
import 'package:toolfoam/models/tf_id.dart'; | ||
|
||
import 'curve.dart'; | ||
|
||
class FitPointSpline extends Curve { | ||
@override | ||
TfId a; | ||
|
||
@override | ||
TfId b; | ||
|
||
// Tangents at the start and end of the spline (relative to A and B) | ||
FixedPoint aRelativeOut; | ||
FixedPoint bRelativeIn; | ||
|
||
List<ControlPoint> controlPoints = []; | ||
|
||
FitPointSpline( | ||
this.a, this.aRelativeOut, this.b, this.bRelativeIn, this.controlPoints); | ||
|
||
factory FitPointSpline.auto(TfId aId, TfId bId, FixedPoint aPoint, | ||
FixedPoint bPoint, List<FixedPoint> points) { | ||
if (points.isEmpty) { | ||
FixedPoint mid = (aPoint + bPoint) / 2; | ||
return FitPointSpline(aId, aPoint - mid, bId, bPoint - mid, []); | ||
} | ||
|
||
List<ControlPoint> controlPoints = | ||
ControlPoint.autoTangent(points, aPoint, bPoint); | ||
FixedPoint aRelativeOut = | ||
TangentHandle.autoNeighbours(aPoint, controlPoints.first) | ||
.relativeInTangent; | ||
FixedPoint bRelativeIn = | ||
TangentHandle.autoNeighbours(controlPoints.last, bPoint) | ||
.relativeOutTangent; | ||
|
||
return FitPointSpline(aId, aRelativeOut, bId, bRelativeIn, controlPoints); | ||
} | ||
|
||
@override | ||
Map<String, dynamic> toJson() { | ||
// TODO: implement toJson | ||
throw UnimplementedError(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import 'package:toolfoam/geometry/point.dart'; | ||
|
||
class TangentHandle { | ||
FixedPoint inUnit; | ||
|
||
double inMagnitude; | ||
double outMagnitude; | ||
|
||
FixedPoint get relativeInTangent => inUnit * -inMagnitude; | ||
FixedPoint get relativeOutTangent => inUnit * outMagnitude; | ||
|
||
TangentHandle(this.inUnit, this.inMagnitude, this.outMagnitude); | ||
|
||
factory TangentHandle.autoNeighbours(Point a, Point b) { | ||
FixedPoint tangent = (b - a) / 2; | ||
|
||
double inMagnitude = tangent.distance / 3; | ||
FixedPoint unit = tangent.unit; | ||
|
||
FixedPoint inUnit = -unit; | ||
return TangentHandle(inUnit, inMagnitude, inMagnitude); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import '../geometry/fit_point_spline.dart'; | ||
import 'identifiable_json_map.dart'; | ||
|
||
class FitPointSplineData extends IdentifiableJsonHashMap<FitPointSpline> {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import 'package:toolfoam/geometry/point.dart'; | ||
import 'package:toolfoam/models/identifiable_json_bimap.dart'; | ||
import 'package:toolfoam/models/identifiable_json_map.dart'; | ||
|
||
class FixedPointData extends IdentifiableJsonBiMap<FixedPoint> {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.