createPercentDivides static method

List<NamedLine> createPercentDivides(
  1. int count, {
  2. NamedLine? fromStartLine,
  3. NamedLine? toEndLine,
  4. END_POINT endPoint = END_POINT.exclude_start_end,
})

创建百分比等分线(含首尾线) 二等分,三条线 三等分,四条线 四等分,五条线

Implementation

static List<NamedLine> createPercentDivides(int count, {
  NamedLine? fromStartLine,
  NamedLine? toEndLine,
  END_POINT endPoint = END_POINT.exclude_start_end}){
  NamedLine fromStart = fromStartLine ?? NamedLine.percent(0.0, name: NAME_START);
  NamedLine toEnd = toEndLine ?? NamedLine.percent(1.0, name: NAME_END);
  assert(count >= 2);
  var excludeStartEnd = List.generate(count - 1, (index){
    return NamedLine.expression(fromStart + (toEnd - fromStart) * ((index + 1) / count),
      name: '${index + 1}/$count:$NAME_DIVIDE}',
    );
  });
  return [
    if(endPoint == END_POINT.include_start_only || endPoint == END_POINT.include_start_end)
      NamedLine.rename(rename: '0/$count$NAME_DIVIDE', copy: fromStart),
    ... excludeStartEnd,
    if(endPoint == END_POINT.include_end_only || endPoint == END_POINT.include_start_end)
      NamedLine.rename(rename: '$count/$count$NAME_DIVIDE', copy: toEnd),
  ];
}