| | |
| | | return (value * 100).toFixed(1) + '%'; |
| | | }, |
| | | /******************setDeviceInfo使用的函数:******************/ |
| | | getAnnulusAwarePoint(trackInfo, x, y, path) { |
| | | return trackInfo.type === 'annulus' |
| | | ? G.snapToAnnulusOuterPath(x, y, path) |
| | | : { x, y }; |
| | | }, |
| | | /** 环穿:把 getPositionAfterMove 的结果压到轨带中线;非环穿原样返回 */ |
| | | applyAnnulusBandCenterToPosition(trackInfo, position) { |
| | | if (!position || trackInfo.type !== 'annulus') { |
| | | return position; |
| | | } |
| | | const c = G.centerAnnulusBandPoint(trackInfo, position.x, position.y, position.path); |
| | | return { ...position, x: c.x, y: c.y }; |
| | | }, |
| | | computeFinalPosition(trackInfo, point, pathList, path, deltaDistance, angle) { |
| | | const position = G.getPositionAfterMove({ point, pathList, path, deltaDistance, angle }); |
| | | return this.applyAnnulusBandCenterToPosition(trackInfo, position); |
| | | }, |
| | | // 环穿条码在总长上的有符号段差 |
| | | calcSignedSegmentDelta(fromBarcode, toBarcode, trackInfo, totalSegmentCount) { |
| | | const from = Number(fromBarcode); |
| | | const to = Number(toBarcode); |
| | |
| | | ) { |
| | | sprite.barcode = device.rgvPos; |
| | | sprite.time = nowMs(); |
| | | let tmpPassedSegmentCount = device.rgvPos - minBarcode; |
| | | const passedSegmentCount = |
| | | tmpPassedSegmentCount < 0 |
| | | ? tmpPassedSegmentCount + totalSegmentCount |
| | | : tmpPassedSegmentCount; |
| | | const passedSegmentCount = this.calcSignedSegmentDelta( |
| | | minBarcode, |
| | | device.rgvPos, |
| | | sprite.trackInfo, |
| | | totalSegmentCount |
| | | ); |
| | | const deltaDistance = (allDistance * passedSegmentCount) / totalSegmentCount; |
| | | const initPath = sprite.path; |
| | | const initMovePoint = this.getAnnulusAwarePoint( |
| | | const initMovePoint = G.snapToAnnulusOuterPath( |
| | | sprite.trackInfo, |
| | | sprite.x, |
| | | sprite.y, |
| | | initPath |
| | | ); |
| | | let mappingInfo = this.computeFinalPosition( |
| | | let mappingInfo = G.computeFinalPosition( |
| | | sprite.trackInfo, |
| | | initMovePoint, |
| | | pathList, |
| | |
| | | sprite.rotation = G.getRotate(mappingInfo, mappingInfo.path) || sprite.rotation; |
| | | sprite.currentAngle = mappingInfo.angle; |
| | | sprite.mappingInfo = mappingInfo; |
| | | const anchorPoint = this.getAnnulusAwarePoint( |
| | | const anchorPoint = G.snapToAnnulusOuterPath( |
| | | sprite.trackInfo, |
| | | mappingInfo.x, |
| | | mappingInfo.y, |
| | |
| | | } else { |
| | | smoothDistance = stepCap; |
| | | } |
| | | const movePointBarcode = this.getAnnulusAwarePoint( |
| | | const movePointBarcode = G.snapToAnnulusOuterPath( |
| | | sprite.trackInfo, |
| | | sprite.x, |
| | | sprite.y, |
| | | path |
| | | ); |
| | | const angle = Math.atan2(sprite.y - path.y, sprite.x - path.x); |
| | | const raw = G.getPositionAfterMove({ |
| | | point: movePointBarcode, |
| | | const p = G.computeFinalPosition( |
| | | sprite.trackInfo, |
| | | movePointBarcode, |
| | | pathList, |
| | | path, |
| | | deltaDistance: smoothDistance, |
| | | smoothDistance, |
| | | angle |
| | | }); |
| | | const p = this.applyAnnulusBandCenterToPosition(sprite.trackInfo, raw); |
| | | ); |
| | | sprite.path = p.path; |
| | | sprite.x = p.x; |
| | | sprite.y = p.y; |
| | | sprite.rotation = G.getRotate(raw, raw.path) || sprite.rotation; |
| | | sprite.rotation = G.getRotate(p, p.path) || sprite.rotation; |
| | | const restDistanceAfter = G.calcDistance({ x: sprite.x, y: sprite.y }, sprite.mappingInfo); |
| | | if (restDistanceAfter <= EPSILON || Math.abs(smoothDistance) >= restDistance - EPSILON) { |
| | | this.finishDeviceMotion(sprite); |
| | |
| | | anchor.totalSegmentCount !== totalSegmentCount; |
| | | if (needResetAnchor) { |
| | | const anchorPath = sprite.path; |
| | | const anchorPoint = this.getAnnulusAwarePoint( |
| | | const anchorPoint = G.snapToAnnulusOuterPath( |
| | | sprite.trackInfo, |
| | | sprite.x, |
| | | sprite.y, |
| | |
| | | const deltaDistance = (allDistance * passedSegmentCount) / totalSegmentCount; |
| | | const path = anchor.path || sprite.path; |
| | | const barcodeMovePoint = { x: anchor.x, y: anchor.y }; |
| | | let finalPosition = this.computeFinalPosition( |
| | | let finalPosition = G.computeFinalPosition( |
| | | sprite.trackInfo, |
| | | barcodeMovePoint, |
| | | pathList, |