createExpressionStaticDivides static method

List<NamedLine> createExpressionStaticDivides(
  1. Expression static,
  2. double count, {
  3. (DIRECTION_ENUM, Size)? infinitySample,
  4. NamedLine? fromStartLine,
  5. NamedLine? toEndLine,
  6. END_POINT endPoint = END_POINT.exclude_start_end,
})

Implementation

static List<NamedLine> createExpressionStaticDivides(Expression static, double count, {(DIRECTION_ENUM, Size)? infinitySample,
  NamedLine? fromStartLine,
  NamedLine? toEndLine,
  END_POINT endPoint = END_POINT.exclude_start_end}){
  assert(count != double.infinity || infinitySample != null);
  NamedLine fromStart = fromStartLine ?? NamedLine.percent(0.0, name: NAME_START);
  NamedLine toEnd = toEndLine ?? NamedLine.percent(1.0, name: NAME_END);
  Expression rangeFromStartToEnd = toEnd - fromStart;
  if(count == double.infinity){
    switch(infinitySample!.$1){
      case DIRECTION_ENUM.vertical:
        count = rangeFromStartToEnd.computeWidth(infinitySample.$2) / static.computeWidth(infinitySample.$2);
        break;
      case DIRECTION_ENUM.horizontal:
        count = rangeFromStartToEnd.computeHeight(infinitySample.$2) / static.computeHeight(infinitySample.$2);
    }
  }
  List<NamedLine> excludeStartEnd = List.generate(count.floor(), (index){
    var plusExpr = fromStart + static * (index + 1);
    return NamedLine.expression(plusExpr, name: '$STATIC_DIVIDES-${index+1}:$plusExpr');
  });

  return [
    if(endPoint == END_POINT.include_start_only || endPoint == END_POINT.include_start_end)
      NamedLine.rename(rename: '$STATIC_DIVIDES-$NAME_START', copy: fromStart),
    ...excludeStartEnd,
    if(endPoint == END_POINT.include_end_only || endPoint == END_POINT.include_start_end)
      NamedLine.rename(rename: '$STATIC_DIVIDES-$NAME_END', copy: toEnd),
  ];
}