getNearbyPoint method
Implementation
LineTouchBackModel getNearbyPoint(Offset localPosition,
{bool outsidePointClear = true}) {
if (localPosition.dx < _startX ||
localPosition.dx > _endX ||
localPosition.dy > _startY ||
localPosition.dy < _endY) {
//不在坐标轴内部的点击
if (outsidePointClear) {
return LineTouchBackModel(
startOffset: null,
);
} else {
return LineTouchBackModel(needRefresh: false, startOffset: null);
}
}
_lineTouchCellModels
.sort((a, b) => a.begainPoint.dx.compareTo(b.begainPoint.dx));
LineTouchCellModel? touchModel;
for (var i = 0; i < _lineTouchCellModels.length - 1; i++) {
var currentX = _lineTouchCellModels[i].begainPoint.dx;
var nextX = _lineTouchCellModels[i + 1].begainPoint.dx;
if (i == 0 && localPosition.dx < currentX) {
touchModel = _lineTouchCellModels.first;
break;
}
if (i == _lineTouchCellModels.length - 2 && localPosition.dx >= nextX) {
touchModel = _lineTouchCellModels[i + 1];
break;
}
if (localPosition.dx >= currentX && localPosition.dx < nextX) {
var speaceWidth = nextX - currentX;
if (localPosition.dx <= currentX + speaceWidth / 2) {
touchModel = _lineTouchCellModels[i];
} else {
touchModel = _lineTouchCellModels[i + 1];
}
break;
}
}
if (touchModel == null) {
return LineTouchBackModel(
startOffset: null,
);
} else {
return LineTouchBackModel(
startOffset: touchModel.begainPoint, backParam: touchModel.param);
}
}