createReverseExpressionStaticDivides static method
List<NamedLine>
createReverseExpressionStaticDivides(
- Expression static,
- double count, {
- (DIRECTION_ENUM, Size)? infinitySample,
- NamedLine? fromEndLine,
- NamedLine? toStartLine,
- END_POINT endPoint = END_POINT.exclude_start_end,
创建定宽等分线(start end可以颠倒) 注意只从start开始定宽 Size大小会改变数量,无法使用 PercentGetter 创建,需要在外部根据Size变化每次重新 createStaticDivides
Implementation
// @Deprecated('not support expression, use createExpressionStaticDivides instead !')
// static List<NamedLine> createStaticDivides(double staticPercent, {double count = double.infinity,
// NamedLine? fromStartLine,
// NamedLine? toEndLine,
// bool includeStartEnd = false}){
// NamedLine fromStart = fromStartLine ?? NamedLine.percent(0.0, name: NAME_START);
// NamedLine toEnd = toEndLine ?? NamedLine.percent(1.0, name: NAME_END);
// assert(staticPercent >0 && staticPercent <1);
// if(fromStart.percent < toEnd.percent){
// List<NamedLine> excludeStartEnd;
// if(staticPercent + fromStart.percent > toEnd.percent) {
// excludeStartEnd = [];
// }else{
// excludeStartEnd = List.generate(min<double>(((toEnd.percent - fromStart.percent) / staticPercent), count).floor(), (index){
// var plusPercent = fromStart.percent + (index + 1) * staticPercent;
// return NamedLine.percent(
// plusPercent,
// name: '$STATIC_DIVIDES-${index+1}:+$staticPercent:$plusPercent',
// );
// });
// }
// return includeStartEnd ? [
// NamedLine.rename(rename: '$STATIC_DIVIDES-$NAME_START', copy: fromStart),
// ...excludeStartEnd,
// NamedLine.rename(rename: '$STATIC_DIVIDES-$NAME_END', copy: toEnd),
// ]: excludeStartEnd;
// }else{
// return createReverseStaticDivides(staticPercent,
// count: count, fromEndLine: toEndLine, toStartLine: fromStartLine, includeStartEnd: includeStartEnd);
// }
// }
// @Deprecated('not support expression, use createReverseExpressionStaticDivides instead !')
// 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;
// }
static List<NamedLine> createReverseExpressionStaticDivides(Expression static, double count, {(DIRECTION_ENUM, Size)? infinitySample,
NamedLine? fromEndLine,
NamedLine? toStartLine,
END_POINT endPoint = END_POINT.exclude_start_end,
}){
assert(count != double.infinity || infinitySample != null);
NamedLine fromStart = fromEndLine ?? NamedLine.percent(1.0, name: NAME_END);
NamedLine toEnd = toStartLine ?? NamedLine.percent(0.0, name: NAME_START);
Expression rangeFromStartToEnd = fromStart - toEnd;
if(count == double.infinity){
switch(infinitySample!.$1){
case DIRECTION_ENUM.vertical:
// count = ((fromStart - toEnd) as Expression).verticalWidthMergeLiteral(infinitySample.$3 ?? PxUnit.wpc)(infinitySample.$2).$1 / staticExpr.verticalWidthMergeLiteral(infinitySample.$3 ?? PxUnit.wpc)(infinitySample.$2).$1;
count = rangeFromStartToEnd.computeWidth(infinitySample.$2) / static.computeWidth(infinitySample.$2);
break;
case DIRECTION_ENUM.horizontal:
// count = ((fromStart - toEnd) as Expression).horizontalHeightMergeLiteral(infinitySample.$3 ?? PxUnit.hpc)(infinitySample.$2).$1 / staticExpr.horizontalHeightMergeLiteral(infinitySample.$3 ?? PxUnit.hpc)(infinitySample.$2).$1;
count = rangeFromStartToEnd.computeHeight(infinitySample.$2) / static.computeWidth(infinitySample.$2);
}
}
List<NamedLine> excludeStartEnd = List.generate(count.floor(), (index){
var minusExpr = fromStart - static * (index + 1);
return NamedLine.expression(minusExpr, name: '$STATIC_DIVIDES-${index+1}:$minusExpr');
/// 反序输出确保从小到大排列
}).reversed.toList();
/// 起始点也应该反序
return [
if(endPoint == END_POINT.include_end_only || endPoint == END_POINT.include_start_end)
NamedLine.rename(rename: '$STATIC_DIVIDES-$NAME_END', copy: toEnd),
...excludeStartEnd,
if(endPoint == END_POINT.include_start_only || endPoint == END_POINT.include_start_end)
NamedLine.rename(rename: '$STATIC_DIVIDES-$NAME_START', copy: fromStart),
];
}