LCOV - code coverage report
Current view: top level - lib/Clippers - WaveLayer.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 101 123 82.1 %
Date: 2021-03-10 21:05:26 Functions: 0 0 -

          Line data    Source code
       1             : import 'dart:math';
       2             : 
       3             : import 'package:flutter/material.dart';
       4             : import 'package:liquid_swipe/Helpers/Helpers.dart';
       5             : 
       6             : ///Liquid Type PathClipper
       7             : class WaveLayer extends CustomClipper<Path> {
       8             :   double revealPercent;
       9             :   double verReveal;
      10             :   late double waveCenterY;
      11             :   late double waveHorRadius;
      12             :   late double waveVertRadius;
      13             :   late double sideWidth;
      14             :   Size iconSize;
      15             :   SlideDirection? slideDirection;
      16             : 
      17           2 :   WaveLayer({
      18             :     required this.revealPercent,
      19             :     required this.slideDirection,
      20             :     required this.iconSize,
      21             :     required this.verReveal,
      22             :   });
      23             : 
      24           2 :   @override
      25             :   getClip(Size size) {
      26           2 :     Path path = Path();
      27           4 :     sideWidth = sidewidth(size);
      28           4 :     waveVertRadius = waveVertRadiusF(size);
      29             : 
      30           8 :     waveCenterY = size.height * verReveal;
      31           6 :     waveHorRadius = slideDirection == SlideDirection.leftToRight
      32           0 :         ? waveHorRadiusFBack(size)
      33           2 :         : waveHorRadiusF(size);
      34             : 
      35           6 :     var maskWidth = size.width - sideWidth;
      36           6 :     path.moveTo(maskWidth - sideWidth, 0);
      37           2 :     path.lineTo(0, 0);
      38           4 :     path.lineTo(0, size.height);
      39           4 :     path.lineTo(maskWidth, size.height);
      40           6 :     double curveStartY = waveCenterY + waveVertRadius;
      41             : 
      42           2 :     path.lineTo(maskWidth, curveStartY);
      43             : 
      44           2 :     path.cubicTo(
      45             :       maskWidth,
      46           6 :       curveStartY - waveVertRadius * 0.1346194756,
      47           6 :       maskWidth - waveHorRadius * 0.05341339583,
      48           6 :       curveStartY - waveVertRadius * 0.2412779634,
      49           6 :       maskWidth - waveHorRadius * 0.1561501458,
      50           6 :       curveStartY - waveVertRadius * 0.3322374268,
      51             :     );
      52             : 
      53           2 :     path.cubicTo(
      54           6 :       maskWidth - waveHorRadius * 0.2361659167,
      55           6 :       curveStartY - waveVertRadius * 0.4030805244,
      56           6 :       maskWidth - waveHorRadius * 0.3305285625,
      57           6 :       curveStartY - waveVertRadius * 0.4561193293,
      58           6 :       maskWidth - waveHorRadius * 0.5012484792,
      59           6 :       curveStartY - waveVertRadius * 0.5350576951,
      60             :     );
      61             : 
      62           2 :     path.cubicTo(
      63           6 :       maskWidth - waveHorRadius * 0.515878125,
      64           6 :       curveStartY - waveVertRadius * 0.5418222317,
      65           6 :       maskWidth - waveHorRadius * 0.5664134792,
      66           6 :       curveStartY - waveVertRadius * 0.5650349878,
      67           6 :       maskWidth - waveHorRadius * 0.574934875,
      68           6 :       curveStartY - waveVertRadius * 0.5689655122,
      69             :     );
      70             : 
      71           2 :     path.cubicTo(
      72           6 :       maskWidth - waveHorRadius * 0.7283715208,
      73           6 :       curveStartY - waveVertRadius * 0.6397387195,
      74           6 :       maskWidth - waveHorRadius * 0.8086618958,
      75           6 :       curveStartY - waveVertRadius * 0.6833456585,
      76           6 :       maskWidth - waveHorRadius * 0.8774032292,
      77           6 :       curveStartY - waveVertRadius * 0.7399037439,
      78             :     );
      79             : 
      80           2 :     path.cubicTo(
      81           6 :       maskWidth - waveHorRadius * 0.9653464583,
      82           6 :       curveStartY - waveVertRadius * 0.8122605122,
      83           4 :       maskWidth - waveHorRadius,
      84           6 :       curveStartY - waveVertRadius * 0.8936183659,
      85           4 :       maskWidth - waveHorRadius,
      86           4 :       curveStartY - waveVertRadius,
      87             :     );
      88             : 
      89           2 :     path.cubicTo(
      90           4 :       maskWidth - waveHorRadius,
      91           6 :       curveStartY - waveVertRadius * 1.100142878,
      92           6 :       maskWidth - waveHorRadius * 0.9595746667,
      93           6 :       curveStartY - waveVertRadius * 1.1887991951,
      94           6 :       maskWidth - waveHorRadius * 0.8608411667,
      95           6 :       curveStartY - waveVertRadius * 1.270484439,
      96             :     );
      97             : 
      98           2 :     path.cubicTo(
      99           6 :       maskWidth - waveHorRadius * 0.7852123333,
     100           6 :       curveStartY - waveVertRadius * 1.3330544756,
     101           6 :       maskWidth - waveHorRadius * 0.703382125,
     102           6 :       curveStartY - waveVertRadius * 1.3795848049,
     103           6 :       maskWidth - waveHorRadius * 0.5291125625,
     104           6 :       curveStartY - waveVertRadius * 1.4665102805,
     105             :     );
     106             : 
     107           2 :     path.cubicTo(
     108           6 :       maskWidth - waveHorRadius * 0.5241858333,
     109           6 :       curveStartY - waveVertRadius * 1.4689677195,
     110           6 :       maskWidth - waveHorRadius * 0.505739125,
     111           6 :       curveStartY - waveVertRadius * 1.4781625854,
     112           6 :       maskWidth - waveHorRadius * 0.5015305417,
     113           6 :       curveStartY - waveVertRadius * 1.4802616098,
     114             :     );
     115             : 
     116           2 :     path.cubicTo(
     117           6 :       maskWidth - waveHorRadius * 0.3187486042,
     118           6 :       curveStartY - waveVertRadius * 1.5714239024,
     119           6 :       maskWidth - waveHorRadius * 0.2332057083,
     120           6 :       curveStartY - waveVertRadius * 1.6204116463,
     121           6 :       maskWidth - waveHorRadius * 0.1541165417,
     122           6 :       curveStartY - waveVertRadius * 1.687403,
     123             :     );
     124             : 
     125           2 :     path.cubicTo(
     126           6 :       maskWidth - waveHorRadius * 0.0509933125,
     127           6 :       curveStartY - waveVertRadius * 1.774752061,
     128             :       maskWidth,
     129           6 :       curveStartY - waveVertRadius * 1.8709256829,
     130             :       maskWidth,
     131           6 :       curveStartY - waveVertRadius * 2,
     132             :     );
     133             : 
     134           2 :     path.lineTo(maskWidth, 0);
     135           2 :     path.close();
     136             : 
     137             :     return path;
     138             :   }
     139             : 
     140           2 :   double sidewidth(Size size) {
     141             :     var p1 = 0.2;
     142             :     var p2 = 0.8;
     143             : 
     144           4 :     if (revealPercent <= p1) {
     145             :       return 15.0;
     146             :     }
     147             : 
     148           2 :     if (revealPercent >= p2) {
     149           1 :       return size.width;
     150             :     }
     151             : 
     152           0 :     return 15 + (size.width - 15.0) * (revealPercent - p1) / (p2 - p1);
     153             :   }
     154             : 
     155           2 :   @override
     156             :   bool shouldReclip(CustomClipper oldClipper) {
     157             :     return true;
     158             :   }
     159             : 
     160           2 :   double waveVertRadiusF(Size size) {
     161             :     var p1 = 0.4;
     162             : 
     163           4 :     if (revealPercent <= 0) {
     164           4 :       return iconSize.height;
     165             :     }
     166             : 
     167           2 :     if (revealPercent >= p1) {
     168           2 :       return size.height * 0.9;
     169             :     }
     170             : 
     171           0 :     return iconSize.height +
     172           0 :         ((size.height * 0.9) - iconSize.height) * revealPercent / p1;
     173             :   }
     174             : 
     175           2 :   double waveHorRadiusF(Size size) {
     176           4 :     if (revealPercent <= 0) {
     177           4 :       return iconSize.width;
     178             :     }
     179             : 
     180           2 :     if (revealPercent >= 1) {
     181             :       return 0;
     182             :     }
     183             : 
     184             :     var p1 = 0.4;
     185           0 :     if (revealPercent <= p1) {
     186           0 :       return iconSize.width +
     187           0 :           revealPercent / p1 * ((size.width * 0.8) - iconSize.width);
     188             :     }
     189             : 
     190           0 :     var t = (revealPercent - p1) / (1.0 - p1);
     191           0 :     var A = size.width * 0.9;
     192             :     var r = 40;
     193             :     var m = 9.8;
     194           0 :     var beta = r / (2 * m);
     195             :     var k = 50;
     196           0 :     var omega0 = k / m;
     197           0 :     var omega = pow(-pow(beta, 2) + pow(omega0, 2), 0.5);
     198             : 
     199           0 :     return A * exp(-beta * t) * cos(omega * t);
     200             :   }
     201             : 
     202           1 :   double waveHorRadiusFBack(Size size) {
     203           2 :     if (revealPercent <= 0) {
     204           2 :       return iconSize.width;
     205             :     }
     206             : 
     207           0 :     if (revealPercent >= 1) {
     208             :       return 0;
     209             :     }
     210             : 
     211             :     var p1 = 0.4;
     212           0 :     if (revealPercent <= p1) {
     213           0 :       return iconSize.width + revealPercent / p1 * iconSize.width;
     214             :     }
     215             : 
     216           0 :     var t = (revealPercent - p1) / (1.0 - p1);
     217           0 :     var A = iconSize.width + 8;
     218             :     var r = 40;
     219             :     var m = 9.8;
     220           0 :     var beta = r / (2 * m);
     221             :     var k = 50;
     222           0 :     var omega0 = k / m;
     223           0 :     var omega = pow(-pow(beta, 2) + pow(omega0, 2), 0.5);
     224             : 
     225           0 :     return A * exp(-beta * t) * cos(omega * t);
     226             :   }
     227             : }

Generated by: LCOV version 1.15