createReverseStaticDivides static method

List<NamedLine> createReverseStaticDivides(
  1. double staticPercent, {
  2. double count = double.infinity,
  3. NamedLine? fromEndLine,
  4. NamedLine? toStartLine,
  5. bool includeStartEnd = false,
})

Implementation

static List<NamedLine> createReverseStaticDivides(double staticPercent, {double count = double.infinity,
  NamedLine? fromEndLine,
  NamedLine? toStartLine,
  bool includeStartEnd = false}){
  NamedLine fromStart = fromEndLine ?? NamedLine.percent(1.0, name: NAME_END);
  NamedLine toEnd = toStartLine ?? NamedLine.percent(0.0, name: NAME_START);
  assert(staticPercent >0 && staticPercent <1);
  List<NamedLine> excludeStartEnd;
  if(toEnd.percent + staticPercent > fromStart.percent ){
    excludeStartEnd = [];
  }else{
    excludeStartEnd = List.generate(min<double>(((fromStart.percent - toEnd.percent) / staticPercent), count).floor(), (index){
      var minusPercent = fromStart.percent - (index + 1) * staticPercent;
      return NamedLine.percent(
        minusPercent,
        name: '$STATIC_DIVIDES-${index+1}:-$staticPercent:$minusPercent',
      );
    /// 反序输出确保从小到大排列
    }).reversed.toList();
  }
  /// 起始点也应该反序
  return includeStartEnd ? [
    NamedLine.rename(rename: '$STATIC_DIVIDES-$NAME_END', copy: toEnd),
    ...excludeStartEnd,
    NamedLine.rename(rename: '$STATIC_DIVIDES-$NAME_START', copy: fromStart),
  ]: excludeStartEnd;
}