import type { Point } from '../Vector2' import type { NestFiler } from '../Filer' import { Path } from './Path' import { PathGeneratorSingle } from './PathGenerator' /** * 用于存放零件旋转后的状态 * 记录了用于放置时的轮廓。该轮廓总是首点等于0,便于放置时的计算。 */ export class PartState { Rotation: number OrigionMinPoint: Point// 使用 Rotation(O - OrigionMinPoint) 将零件变换到和排料矩形状态相同的状态,然后使用PlacePoint(O)将零件设置到正确的状态 MinPoint: Point// 这个状态下的最小点 Contour: Path// 轮廓 IsMirror: boolean = false MirrorOriginMinPoint: Point Mirror(): PartState { if (this.Contour.IsRect) return let mpts = this.Contour.Points.map((p) => { return { x: -p.x, y: p.y } }).reverse() let path = new Path(mpts, 0) let partState = new PartState() partState.Contour = PathGeneratorSingle.Allocate(path) PathGeneratorSingle.RegisterId(partState.Contour) partState.Rotation = this.Rotation partState.OrigionMinPoint = this.OrigionMinPoint partState.MinPoint = this.MinPoint partState.IsMirror = true partState.MirrorOriginMinPoint = path.OrigionMinPoint return partState } // #region -------------------------File------------------------- ReadFile(file: NestFiler) { this.Rotation = file.Read() this.OrigionMinPoint = file.Read() this.MinPoint = file.Read() let index = file.Read() as number this.Contour = PathGeneratorSingle.paths[index] if (!this.Contour) console.error('无法得到PartState的轮廓!') } WriteFile(file: NestFiler) { file.Write(this.Rotation) file.Write(this.OrigionMinPoint) file.Write(this.MinPoint) file.Write(this.Contour.Id) } // #endregion }