Files
cut-abstractions/tests/dev1/dataHandle/common/core/PartState.ts

62 lines
1.8 KiB
TypeScript
Raw Normal View History

2025-07-22 18:22:31 +08:00
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
}