Skip to content

Commit

Permalink
fix: [MDS-564] Remove vector_math transitive dependency (#196)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kypsis committed Jun 20, 2023
1 parent fab5037 commit fa8490a
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions lib/src/utils/squircle/processed_squircle_radius.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'dart:math' as math;

import 'package:moon_design/src/utils/squircle/squircle_radius.dart';
import 'package:vector_math/vector_math.dart' as vector;

// The article from figma's blog
// https://www.figma.com/blog/desperately-seeking-squircles/
Expand All @@ -24,6 +23,12 @@ class ProcessedSquircleRadius {
required double width,
required double height,
}) {
/// Constant factor to convert and angle from degrees to radians.
const double degrees2Radians = math.pi / 180.0;

/// Convert [degrees] to radians.
double radians(double degrees) => degrees * degrees2Radians;

final cornerSmoothing = radius.cornerSmoothing;
var cornerRadius = radius.cornerRadius;

Expand Down Expand Up @@ -55,14 +60,14 @@ class ProcessedSquircleRadius {

// This was called `h_longest` in the original code
// In the article this is the distance between 2 control points: P3 and P4
final p3ToP4Distance = cornerRadius * math.tan(vector.radians(angleTheta / 2));
final p3ToP4Distance = cornerRadius * math.tan(radians(angleTheta / 2));

// This was called `l` in the original code
final circularSectionLength = math.sin(vector.radians(angleBeta / 2)) * cornerRadius * math.sqrt(2);
final circularSectionLength = math.sin(radians(angleBeta / 2)) * cornerRadius * math.sqrt(2);

// a, b, c and d are from 11.1 in the article
final c = p3ToP4Distance * math.cos(vector.radians(angleAlpha));
final d = c * math.tan(vector.radians(angleAlpha));
final c = p3ToP4Distance * math.cos(radians(angleAlpha));
final d = c * math.tan(radians(angleAlpha));
final b = (p - circularSectionLength - c - d) / 3;
final a = 2 * b;

Expand Down

0 comments on commit fa8490a

Please sign in to comment.