Record pointers to values
This commit is contained in:
parent
909506fab6
commit
6d3d12a239
|
@ -26,7 +26,7 @@ func NewClipTag(clip *shapes.ClipPath, scale int) *ClipTag {
|
|||
shape := clip.GetShape()
|
||||
if len(shape) == 0 { //full clip
|
||||
shape = shapes.Shape{
|
||||
&records.LineRecord{
|
||||
records.LineRecord{
|
||||
//TODO: ??? why TwipFactor here???
|
||||
To: math.NewVector2[float64](0, swftypes.Twip(swftypes.TwipFactor).Float64()),
|
||||
Start: math.NewVector2[float64](0, 0),
|
||||
|
|
|
@ -50,7 +50,7 @@ func (b *BaseDrawingTag) GetCommands(scale, precision int) string {
|
|||
|
||||
commands := make([]byte, 0, len(*b)*2*10)
|
||||
for _, edge := range *b {
|
||||
moveRecord, isMoveRecord := edge.(*records.MoveRecord)
|
||||
moveRecord, isMoveRecord := edge.(records.MoveRecord)
|
||||
if !isMoveRecord {
|
||||
if lastEdge == nil {
|
||||
commands = entryToPrecisionAndScaleTag(commands, "m", scale, precision, edge.GetStart())
|
||||
|
@ -62,23 +62,23 @@ func (b *BaseDrawingTag) GetCommands(scale, precision int) string {
|
|||
|
||||
if isMoveRecord {
|
||||
commands = entryToPrecisionAndScaleTag(commands, "m", scale, precision, moveRecord.To)
|
||||
} else if lineRecord, ok := edge.(*records.LineRecord); ok {
|
||||
if _, ok = lastEdge.(*records.LineRecord); ok {
|
||||
} else if lineRecord, ok := edge.(records.LineRecord); ok {
|
||||
if _, ok = lastEdge.(records.LineRecord); ok {
|
||||
commands = entryToPrecisionAndScaleTag(commands, "", scale, precision, lineRecord.To)
|
||||
} else {
|
||||
commands = entryToPrecisionAndScaleTag(commands, "l", scale, precision, lineRecord.To)
|
||||
}
|
||||
} else if quadraticRecord, ok := edge.(*records.QuadraticCurveRecord); ok {
|
||||
} else if quadraticRecord, ok := edge.(records.QuadraticCurveRecord); ok {
|
||||
edge = records.CubicCurveFromQuadraticRecord(quadraticRecord)
|
||||
}
|
||||
|
||||
if cubicRecord, ok := edge.(*records.CubicCurveRecord); ok {
|
||||
if _, ok = lastEdge.(*records.CubicCurveRecord); ok {
|
||||
if cubicRecord, ok := edge.(records.CubicCurveRecord); ok {
|
||||
if _, ok = lastEdge.(records.CubicCurveRecord); ok {
|
||||
commands = entryToPrecisionAndScaleTag(commands, "", scale, precision, cubicRecord.Control1, cubicRecord.Control2, cubicRecord.Anchor)
|
||||
} else {
|
||||
commands = entryToPrecisionAndScaleTag(commands, "b", scale, precision, cubicRecord.Control1, cubicRecord.Control2, cubicRecord.Anchor)
|
||||
}
|
||||
} else if cubicSplineRecord, ok := edge.(*records.CubicSplineCurveRecord); ok {
|
||||
} else if cubicSplineRecord, ok := edge.(records.CubicSplineCurveRecord); ok {
|
||||
_ = cubicSplineRecord
|
||||
panic("not implemented")
|
||||
}
|
||||
|
|
|
@ -98,11 +98,11 @@ func TestParser(t *testing.T) {
|
|||
for _, object := range rendered {
|
||||
if object.Clip != nil {
|
||||
clipCalls++
|
||||
clipItems += len(object.Clip.GetShape().Edges)
|
||||
clipItems += len(object.Clip.GetShape())
|
||||
}
|
||||
for _, p := range object.DrawPathList {
|
||||
drawCalls++
|
||||
drawItems += len(p.Commands.Edges)
|
||||
drawItems += len(p.Commands)
|
||||
}
|
||||
filteredRendered = append(filteredRendered, object)
|
||||
}
|
||||
|
|
|
@ -11,16 +11,16 @@ type CubicCurveRecord struct {
|
|||
Start math2.Vector2[float64]
|
||||
}
|
||||
|
||||
func (r *CubicCurveRecord) GetStart() math2.Vector2[float64] {
|
||||
func (r CubicCurveRecord) GetStart() math2.Vector2[float64] {
|
||||
return r.Start
|
||||
}
|
||||
|
||||
func (r *CubicCurveRecord) GetEnd() math2.Vector2[float64] {
|
||||
func (r CubicCurveRecord) GetEnd() math2.Vector2[float64] {
|
||||
return r.Anchor
|
||||
}
|
||||
|
||||
func (r *CubicCurveRecord) Reverse() Record {
|
||||
return &CubicCurveRecord{
|
||||
func (r CubicCurveRecord) Reverse() Record {
|
||||
return CubicCurveRecord{
|
||||
Control1: r.Control2,
|
||||
Control2: r.Control1,
|
||||
Anchor: r.Start,
|
||||
|
@ -28,9 +28,9 @@ func (r *CubicCurveRecord) Reverse() Record {
|
|||
}
|
||||
}
|
||||
|
||||
func (r *CubicCurveRecord) ApplyMatrixTransform(transform math2.MatrixTransform, applyTranslation bool) Record {
|
||||
func (r CubicCurveRecord) ApplyMatrixTransform(transform math2.MatrixTransform, applyTranslation bool) Record {
|
||||
//TODO: see how accurate this is
|
||||
return &CubicCurveRecord{
|
||||
return CubicCurveRecord{
|
||||
Control1: math2.MatrixTransformApplyToVector(transform, r.Control1, applyTranslation),
|
||||
Control2: math2.MatrixTransformApplyToVector(transform, r.Control2, applyTranslation),
|
||||
Anchor: math2.MatrixTransformApplyToVector(transform, r.Anchor, applyTranslation),
|
||||
|
@ -38,24 +38,24 @@ func (r *CubicCurveRecord) ApplyMatrixTransform(transform math2.MatrixTransform,
|
|||
}
|
||||
}
|
||||
|
||||
func (r *CubicCurveRecord) Equals(other Record) bool {
|
||||
if o, ok := other.(*CubicCurveRecord); ok {
|
||||
return *o == *r
|
||||
func (r CubicCurveRecord) Equals(other Record) bool {
|
||||
if o, ok := other.(CubicCurveRecord); ok {
|
||||
return o == r
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (r *CubicCurveRecord) SameType(other Record) bool {
|
||||
_, ok := other.(*CubicCurveRecord)
|
||||
func (r CubicCurveRecord) SameType(other Record) bool {
|
||||
_, ok := other.(CubicCurveRecord)
|
||||
return ok
|
||||
}
|
||||
|
||||
func (r *CubicCurveRecord) IsFlat() bool {
|
||||
func (r CubicCurveRecord) IsFlat() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func CubicCurveFromQuadraticRecord(q *QuadraticCurveRecord) *CubicCurveRecord {
|
||||
return &CubicCurveRecord{
|
||||
func CubicCurveFromQuadraticRecord(q QuadraticCurveRecord) CubicCurveRecord {
|
||||
return CubicCurveRecord{
|
||||
Control1: q.Start.AddVector(q.Control.Multiply(2)).Divide(3),
|
||||
Control2: q.Anchor.AddVector(q.Control.Multiply(2)).Divide(3),
|
||||
Anchor: q.Anchor,
|
||||
|
@ -64,20 +64,20 @@ func CubicCurveFromQuadraticRecord(q *QuadraticCurveRecord) *CubicCurveRecord {
|
|||
}
|
||||
|
||||
// ToSingleQuadraticRecord Finds if Cubic curve is a perfect fit of a Quadratic curve (aka, it was upconverted)
|
||||
func (r *CubicCurveRecord) ToSingleQuadraticRecord() *QuadraticCurveRecord {
|
||||
func (r CubicCurveRecord) ToSingleQuadraticRecord() (QuadraticCurveRecord, bool) {
|
||||
control1 := r.Control1.Multiply(3).SubVector(r.Start).Divide(2)
|
||||
control2 := r.Control2.Multiply(3).SubVector(r.Anchor).Divide(2)
|
||||
if control1.Equals(control2) {
|
||||
return &QuadraticCurveRecord{
|
||||
return QuadraticCurveRecord{
|
||||
Control: control1,
|
||||
Anchor: r.Anchor,
|
||||
Start: r.Start,
|
||||
}
|
||||
}, true
|
||||
}
|
||||
return nil
|
||||
return QuadraticCurveRecord{}, false
|
||||
}
|
||||
|
||||
func (r *CubicCurveRecord) ToLineRecords(scale int64) []Record {
|
||||
func (r CubicCurveRecord) ToLineRecords(scale int64) []Record {
|
||||
distanceToleranceSquare := math.Pow(0.5/float64(scale), 2)
|
||||
points := CubicRecursiveBezier(nil, 0.0, BezierCurveAngleTolerance, distanceToleranceSquare, r.Start, r.Control1, r.Control2, r.Anchor, 0)
|
||||
|
||||
|
@ -90,14 +90,14 @@ func (r *CubicCurveRecord) ToLineRecords(scale int64) []Record {
|
|||
if point.Equals(current) {
|
||||
continue
|
||||
}
|
||||
result = append(result, &LineRecord{
|
||||
result = append(result, LineRecord{
|
||||
To: point,
|
||||
Start: current,
|
||||
})
|
||||
current = point
|
||||
}
|
||||
|
||||
result = append(result, &LineRecord{
|
||||
result = append(result, LineRecord{
|
||||
To: r.Anchor,
|
||||
Start: current,
|
||||
})
|
||||
|
|
|
@ -12,49 +12,49 @@ type CubicSplineCurveRecord struct {
|
|||
Start math.Vector2[float64]
|
||||
}
|
||||
|
||||
func (r *CubicSplineCurveRecord) GetStart() math.Vector2[float64] {
|
||||
func (r CubicSplineCurveRecord) GetStart() math.Vector2[float64] {
|
||||
return r.Start
|
||||
}
|
||||
|
||||
func (r *CubicSplineCurveRecord) GetEnd() math.Vector2[float64] {
|
||||
func (r CubicSplineCurveRecord) GetEnd() math.Vector2[float64] {
|
||||
return r.Anchor
|
||||
}
|
||||
|
||||
func (r *CubicSplineCurveRecord) Reverse() Record {
|
||||
func (r CubicSplineCurveRecord) Reverse() Record {
|
||||
controls := slices.Clone(r.Control)
|
||||
slices.Reverse(controls)
|
||||
return &CubicSplineCurveRecord{
|
||||
return CubicSplineCurveRecord{
|
||||
Control: controls,
|
||||
Anchor: r.Start,
|
||||
Start: r.Anchor,
|
||||
}
|
||||
}
|
||||
|
||||
func (r *CubicSplineCurveRecord) ApplyMatrixTransform(transform math.MatrixTransform, applyTranslation bool) Record {
|
||||
func (r CubicSplineCurveRecord) ApplyMatrixTransform(transform math.MatrixTransform, applyTranslation bool) Record {
|
||||
//TODO: see how accurate this is
|
||||
controls := make([]math.Vector2[float64], 0, len(r.Control))
|
||||
for _, c := range r.Control {
|
||||
controls = append(controls, math.MatrixTransformApplyToVector(transform, c, applyTranslation))
|
||||
}
|
||||
return &CubicSplineCurveRecord{
|
||||
return CubicSplineCurveRecord{
|
||||
Control: controls,
|
||||
Anchor: math.MatrixTransformApplyToVector(transform, r.Anchor, applyTranslation),
|
||||
Start: math.MatrixTransformApplyToVector(transform, r.Start, applyTranslation),
|
||||
}
|
||||
}
|
||||
|
||||
func (r *CubicSplineCurveRecord) Equals(other Record) bool {
|
||||
if o, ok := other.(*CubicSplineCurveRecord); ok {
|
||||
func (r CubicSplineCurveRecord) Equals(other Record) bool {
|
||||
if o, ok := other.(CubicSplineCurveRecord); ok {
|
||||
return reflect.DeepEqual(r.Control, o.Control) && r.Start == o.Start && r.Anchor == o.Anchor
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (r *CubicSplineCurveRecord) SameType(other Record) bool {
|
||||
_, ok := other.(*CubicSplineCurveRecord)
|
||||
func (r CubicSplineCurveRecord) SameType(other Record) bool {
|
||||
_, ok := other.(CubicSplineCurveRecord)
|
||||
return ok
|
||||
}
|
||||
|
||||
func (r *CubicSplineCurveRecord) IsFlat() bool {
|
||||
func (r CubicSplineCurveRecord) IsFlat() bool {
|
||||
return false
|
||||
}
|
||||
|
|
|
@ -9,22 +9,22 @@ type LineRecord struct {
|
|||
//TODO: intersections
|
||||
}
|
||||
|
||||
func (r *LineRecord) GetStart() math.Vector2[float64] {
|
||||
func (r LineRecord) GetStart() math.Vector2[float64] {
|
||||
return r.Start
|
||||
}
|
||||
|
||||
func (r *LineRecord) GetEnd() math.Vector2[float64] {
|
||||
func (r LineRecord) GetEnd() math.Vector2[float64] {
|
||||
return r.To
|
||||
}
|
||||
|
||||
func (r *LineRecord) Reverse() Record {
|
||||
return &LineRecord{
|
||||
func (r LineRecord) Reverse() Record {
|
||||
return LineRecord{
|
||||
To: r.Start,
|
||||
Start: r.To,
|
||||
}
|
||||
}
|
||||
|
||||
func (r *LineRecord) Delta() math.Vector2[float64] {
|
||||
func (r LineRecord) Delta() math.Vector2[float64] {
|
||||
return r.To.SubVector(r.Start)
|
||||
}
|
||||
|
||||
|
@ -32,26 +32,26 @@ func fake2DCross(a, b math.Vector2[float64]) float64 {
|
|||
return a.X*b.Y - a.Y + b.X
|
||||
}
|
||||
|
||||
func (r *LineRecord) ApplyMatrixTransform(transform math.MatrixTransform, applyTranslation bool) Record {
|
||||
func (r LineRecord) ApplyMatrixTransform(transform math.MatrixTransform, applyTranslation bool) Record {
|
||||
//TODO: see how accurate this is
|
||||
return &LineRecord{
|
||||
return LineRecord{
|
||||
To: math.MatrixTransformApplyToVector(transform, r.To, applyTranslation),
|
||||
Start: math.MatrixTransformApplyToVector(transform, r.Start, applyTranslation),
|
||||
}
|
||||
}
|
||||
|
||||
func (r *LineRecord) Equals(other Record) bool {
|
||||
if o, ok := other.(*LineRecord); ok {
|
||||
return *o == *r
|
||||
func (r LineRecord) Equals(other Record) bool {
|
||||
if o, ok := other.(LineRecord); ok {
|
||||
return o == r
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (r *LineRecord) SameType(other Record) bool {
|
||||
_, ok := other.(*LineRecord)
|
||||
func (r LineRecord) SameType(other Record) bool {
|
||||
_, ok := other.(LineRecord)
|
||||
return ok
|
||||
}
|
||||
|
||||
func (r *LineRecord) IsFlat() bool {
|
||||
func (r LineRecord) IsFlat() bool {
|
||||
return true
|
||||
}
|
||||
|
|
|
@ -8,41 +8,41 @@ type MoveRecord struct {
|
|||
To, Start math.Vector2[float64]
|
||||
}
|
||||
|
||||
func (r *MoveRecord) GetStart() math.Vector2[float64] {
|
||||
func (r MoveRecord) GetStart() math.Vector2[float64] {
|
||||
return r.Start
|
||||
}
|
||||
|
||||
func (r *MoveRecord) GetEnd() math.Vector2[float64] {
|
||||
func (r MoveRecord) GetEnd() math.Vector2[float64] {
|
||||
return r.To
|
||||
}
|
||||
|
||||
func (r *MoveRecord) Reverse() Record {
|
||||
return &MoveRecord{
|
||||
func (r MoveRecord) Reverse() Record {
|
||||
return MoveRecord{
|
||||
To: r.Start,
|
||||
Start: r.To,
|
||||
}
|
||||
}
|
||||
|
||||
func (r *MoveRecord) ApplyMatrixTransform(transform math.MatrixTransform, applyTranslation bool) Record {
|
||||
func (r MoveRecord) ApplyMatrixTransform(transform math.MatrixTransform, applyTranslation bool) Record {
|
||||
//TODO: see how accurate this is
|
||||
return &MoveRecord{
|
||||
return MoveRecord{
|
||||
To: math.MatrixTransformApplyToVector(transform, r.To, applyTranslation),
|
||||
Start: math.MatrixTransformApplyToVector(transform, r.Start, applyTranslation),
|
||||
}
|
||||
}
|
||||
|
||||
func (r *MoveRecord) Equals(other Record) bool {
|
||||
if o, ok := other.(*MoveRecord); ok {
|
||||
return *o == *r
|
||||
func (r MoveRecord) Equals(other Record) bool {
|
||||
if o, ok := other.(MoveRecord); ok {
|
||||
return o == r
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (r *MoveRecord) SameType(other Record) bool {
|
||||
_, ok := other.(*MoveRecord)
|
||||
func (r MoveRecord) SameType(other Record) bool {
|
||||
_, ok := other.(MoveRecord)
|
||||
return ok
|
||||
}
|
||||
|
||||
func (r *MoveRecord) IsFlat() bool {
|
||||
func (r MoveRecord) IsFlat() bool {
|
||||
return true
|
||||
}
|
||||
|
|
|
@ -11,57 +11,57 @@ type QuadraticCurveRecord struct {
|
|||
Start math2.Vector2[float64]
|
||||
}
|
||||
|
||||
func (r *QuadraticCurveRecord) GetStart() math2.Vector2[float64] {
|
||||
func (r QuadraticCurveRecord) GetStart() math2.Vector2[float64] {
|
||||
return r.Start
|
||||
}
|
||||
|
||||
func (r *QuadraticCurveRecord) GetEnd() math2.Vector2[float64] {
|
||||
func (r QuadraticCurveRecord) GetEnd() math2.Vector2[float64] {
|
||||
return r.Anchor
|
||||
}
|
||||
|
||||
func (r *QuadraticCurveRecord) Reverse() Record {
|
||||
return &QuadraticCurveRecord{
|
||||
func (r QuadraticCurveRecord) Reverse() Record {
|
||||
return QuadraticCurveRecord{
|
||||
Control: r.Control,
|
||||
Anchor: r.Start,
|
||||
Start: r.Anchor,
|
||||
}
|
||||
}
|
||||
|
||||
func (r *QuadraticCurveRecord) ApplyMatrixTransform(transform math2.MatrixTransform, applyTranslation bool) Record {
|
||||
func (r QuadraticCurveRecord) ApplyMatrixTransform(transform math2.MatrixTransform, applyTranslation bool) Record {
|
||||
//TODO: see how accurate this is
|
||||
return &QuadraticCurveRecord{
|
||||
return QuadraticCurveRecord{
|
||||
Control: math2.MatrixTransformApplyToVector(transform, r.Control, applyTranslation),
|
||||
Anchor: math2.MatrixTransformApplyToVector(transform, r.Anchor, applyTranslation),
|
||||
Start: math2.MatrixTransformApplyToVector(transform, r.Start, applyTranslation),
|
||||
}
|
||||
}
|
||||
|
||||
func (r *QuadraticCurveRecord) Equals(other Record) bool {
|
||||
if o, ok := other.(*QuadraticCurveRecord); ok {
|
||||
return *o == *r
|
||||
func (r QuadraticCurveRecord) Equals(other Record) bool {
|
||||
if o, ok := other.(QuadraticCurveRecord); ok {
|
||||
return o == r
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (r *QuadraticCurveRecord) SameType(other Record) bool {
|
||||
_, ok := other.(*QuadraticCurveRecord)
|
||||
func (r QuadraticCurveRecord) SameType(other Record) bool {
|
||||
_, ok := other.(QuadraticCurveRecord)
|
||||
return ok
|
||||
}
|
||||
|
||||
func (r *QuadraticCurveRecord) IsFlat() bool {
|
||||
func (r QuadraticCurveRecord) IsFlat() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func QuadraticCurveFromLineRecord(l *LineRecord) *QuadraticCurveRecord {
|
||||
func QuadraticCurveFromLineRecord(l LineRecord) QuadraticCurveRecord {
|
||||
delta := l.To.SubVector(l.Start)
|
||||
return &QuadraticCurveRecord{
|
||||
return QuadraticCurveRecord{
|
||||
Control: l.Start.AddVector(delta.Divide(2)),
|
||||
Anchor: l.Start.AddVector(delta),
|
||||
Start: l.Start,
|
||||
}
|
||||
}
|
||||
|
||||
func (r *QuadraticCurveRecord) ToLineRecords(scale int64) []Record {
|
||||
func (r QuadraticCurveRecord) ToLineRecords(scale int64) []Record {
|
||||
distanceToleranceSquare := math.Pow(0.5/float64(scale), 2)
|
||||
points := QuadraticRecursiveBezier(nil, BezierCurveAngleTolerance, distanceToleranceSquare, r.Start, r.Control, r.Anchor, 0)
|
||||
|
||||
|
@ -74,14 +74,14 @@ func (r *QuadraticCurveRecord) ToLineRecords(scale int64) []Record {
|
|||
if point.Equals(current) {
|
||||
continue
|
||||
}
|
||||
result = append(result, &LineRecord{
|
||||
result = append(result, LineRecord{
|
||||
To: point,
|
||||
Start: current,
|
||||
})
|
||||
current = point
|
||||
}
|
||||
|
||||
result = append(result, &LineRecord{
|
||||
result = append(result, LineRecord{
|
||||
To: r.Anchor,
|
||||
Start: current,
|
||||
})
|
||||
|
|
|
@ -3,7 +3,7 @@ package records
|
|||
func FlattenRecord(r Record, scale int64) []Record {
|
||||
if cr, ok := r.(CurvedRecord); ok {
|
||||
return cr.ToLineRecords(scale)
|
||||
} else if lr, ok := r.(*LineRecord); ok {
|
||||
} else if lr, ok := r.(LineRecord); ok {
|
||||
return []Record{lr}
|
||||
} else {
|
||||
panic("not supported")
|
||||
|
|
|
@ -5,48 +5,48 @@ import "git.gammaspectra.live/WeebDataHoarder/swf2ass-go/types/math"
|
|||
func LerpRecord(start, end Record, ratio float64) Record {
|
||||
if start.SameType(end) {
|
||||
switch s := start.(type) {
|
||||
case *LineRecord:
|
||||
return &LineRecord{
|
||||
To: math.LerpVector2(s.To, end.(*LineRecord).To, ratio),
|
||||
Start: math.LerpVector2(s.Start, end.(*LineRecord).Start, ratio),
|
||||
case LineRecord:
|
||||
return LineRecord{
|
||||
To: math.LerpVector2(s.To, end.(LineRecord).To, ratio),
|
||||
Start: math.LerpVector2(s.Start, end.(LineRecord).Start, ratio),
|
||||
}
|
||||
case *MoveRecord:
|
||||
return &MoveRecord{
|
||||
To: math.LerpVector2(s.To, end.(*MoveRecord).To, ratio),
|
||||
Start: math.LerpVector2(s.Start, end.(*MoveRecord).Start, ratio),
|
||||
case MoveRecord:
|
||||
return MoveRecord{
|
||||
To: math.LerpVector2(s.To, end.(MoveRecord).To, ratio),
|
||||
Start: math.LerpVector2(s.Start, end.(MoveRecord).Start, ratio),
|
||||
}
|
||||
case *QuadraticCurveRecord:
|
||||
return &QuadraticCurveRecord{
|
||||
Control: math.LerpVector2(s.Control, end.(*QuadraticCurveRecord).Control, ratio),
|
||||
Anchor: math.LerpVector2(s.Anchor, end.(*QuadraticCurveRecord).Anchor, ratio),
|
||||
Start: math.LerpVector2(s.Start, end.(*QuadraticCurveRecord).Start, ratio),
|
||||
case QuadraticCurveRecord:
|
||||
return QuadraticCurveRecord{
|
||||
Control: math.LerpVector2(s.Control, end.(QuadraticCurveRecord).Control, ratio),
|
||||
Anchor: math.LerpVector2(s.Anchor, end.(QuadraticCurveRecord).Anchor, ratio),
|
||||
Start: math.LerpVector2(s.Start, end.(QuadraticCurveRecord).Start, ratio),
|
||||
}
|
||||
case *CubicCurveRecord:
|
||||
return &CubicCurveRecord{
|
||||
Control1: math.LerpVector2(s.Control1, end.(*CubicCurveRecord).Control1, ratio),
|
||||
Control2: math.LerpVector2(s.Control2, end.(*CubicCurveRecord).Control2, ratio),
|
||||
Anchor: math.LerpVector2(s.Anchor, end.(*CubicCurveRecord).Anchor, ratio),
|
||||
Start: math.LerpVector2(s.Start, end.(*CubicCurveRecord).Start, ratio),
|
||||
case CubicCurveRecord:
|
||||
return CubicCurveRecord{
|
||||
Control1: math.LerpVector2(s.Control1, end.(CubicCurveRecord).Control1, ratio),
|
||||
Control2: math.LerpVector2(s.Control2, end.(CubicCurveRecord).Control2, ratio),
|
||||
Anchor: math.LerpVector2(s.Anchor, end.(CubicCurveRecord).Anchor, ratio),
|
||||
Start: math.LerpVector2(s.Start, end.(CubicCurveRecord).Start, ratio),
|
||||
}
|
||||
default:
|
||||
panic("not supported")
|
||||
}
|
||||
} else {
|
||||
startLine, startLineOk := start.(*LineRecord)
|
||||
startQuadratic, startQuadraticOk := start.(*QuadraticCurveRecord)
|
||||
endLine, endLineOk := end.(*LineRecord)
|
||||
endQuadratic, endQuadraticOk := end.(*QuadraticCurveRecord)
|
||||
startLine, startLineOk := start.(LineRecord)
|
||||
startQuadratic, startQuadraticOk := start.(QuadraticCurveRecord)
|
||||
endLine, endLineOk := end.(LineRecord)
|
||||
endQuadratic, endQuadraticOk := end.(QuadraticCurveRecord)
|
||||
|
||||
if startLineOk && endQuadraticOk {
|
||||
startQuadratic = QuadraticCurveFromLineRecord(startLine)
|
||||
return &QuadraticCurveRecord{
|
||||
return QuadraticCurveRecord{
|
||||
Control: math.LerpVector2(startQuadratic.Control, endQuadratic.Control, ratio),
|
||||
Anchor: math.LerpVector2(startQuadratic.Anchor, endQuadratic.Anchor, ratio),
|
||||
Start: math.LerpVector2(startQuadratic.Start, endQuadratic.Start, ratio),
|
||||
}
|
||||
} else if startQuadraticOk && endLineOk {
|
||||
endQuadratic = QuadraticCurveFromLineRecord(endLine)
|
||||
return &QuadraticCurveRecord{
|
||||
return QuadraticCurveRecord{
|
||||
Control: math.LerpVector2(startQuadratic.Control, endQuadratic.Control, ratio),
|
||||
Anchor: math.LerpVector2(startQuadratic.Anchor, endQuadratic.Anchor, ratio),
|
||||
Start: math.LerpVector2(startQuadratic.Start, endQuadratic.Start, ratio),
|
||||
|
|
|
@ -28,12 +28,12 @@ func (p ComplexPolygon) GetShape() (r Shape) {
|
|||
for _, pol := range p.Pol.Polygons() {
|
||||
for _, path := range pol.Simplify(PolygonSimplifyTolerance).(geom.Polygon) {
|
||||
//pol = pol.Simplify(PolygonSimplifyTolerance).(geom.Polygon)
|
||||
r = append(r, &records.LineRecord{
|
||||
r = append(r, records.LineRecord{
|
||||
To: math.NewVector2(path[1].X, path[1].Y),
|
||||
Start: math.NewVector2(path[0].X, path[0].Y),
|
||||
})
|
||||
for _, point := range path[2:] {
|
||||
r = append(r, &records.LineRecord{
|
||||
r = append(r, records.LineRecord{
|
||||
To: math.NewVector2(point.X, point.Y),
|
||||
Start: r[len(r)-1].GetEnd(),
|
||||
})
|
||||
|
@ -46,7 +46,7 @@ func (p ComplexPolygon) GetShape() (r Shape) {
|
|||
func NewPolygonFromShape(shape Shape) (g geom.Polygon) {
|
||||
flat := shape.Flatten()
|
||||
|
||||
var edges []*records.LineRecord
|
||||
var edges []records.LineRecord
|
||||
|
||||
var lastEdge *records.LineRecord
|
||||
|
||||
|
@ -56,9 +56,9 @@ func NewPolygonFromShape(shape Shape) (g geom.Polygon) {
|
|||
edges = edges[:0]
|
||||
}
|
||||
|
||||
if lineRecord, ok := record.(*records.LineRecord); ok {
|
||||
if lineRecord, ok := record.(records.LineRecord); ok {
|
||||
edges = append(edges, lineRecord)
|
||||
lastEdge = lineRecord
|
||||
lastEdge = &lineRecord
|
||||
} else {
|
||||
panic("invalid record")
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ func NewPolygonFromShape(shape Shape) (g geom.Polygon) {
|
|||
return g
|
||||
}
|
||||
|
||||
func NewPathFromEdges(edges []*records.LineRecord) (p geom.Path) {
|
||||
func NewPathFromEdges(edges []records.LineRecord) (p geom.Path) {
|
||||
p = make(geom.Path, 0, len(edges)+1)
|
||||
start := edges[0].Start
|
||||
to := edges[0].To
|
||||
|
|
|
@ -98,7 +98,7 @@ func (s *PathSegment[T]) GetShape() (shape Shape) {
|
|||
point := next()
|
||||
|
||||
if !point.IsBezierControl {
|
||||
shape = append(shape, &records.LineRecord{
|
||||
shape = append(shape, records.LineRecord{
|
||||
To: point.Pos.Float64(),
|
||||
Start: lastPos,
|
||||
})
|
||||
|
@ -109,7 +109,7 @@ func (s *PathSegment[T]) GetShape() (shape Shape) {
|
|||
}
|
||||
end := next()
|
||||
|
||||
shape = append(shape, &records.QuadraticCurveRecord{
|
||||
shape = append(shape, records.QuadraticCurveRecord{
|
||||
Control: point.Pos.Float64(),
|
||||
Anchor: end.Pos.Float64(),
|
||||
Start: lastPos,
|
||||
|
|
|
@ -97,7 +97,7 @@ func IterateMorphShape(start, end Shape) (r []records.RecordPair) {
|
|||
|
||||
if prevStart != nil && !prevStart.GetEnd().Equals(startEdge.GetStart()) {
|
||||
advanceStart = false
|
||||
startEdge = &records.MoveRecord{
|
||||
startEdge = records.MoveRecord{
|
||||
To: startEdge.GetStart(),
|
||||
Start: prevStart.GetEnd(),
|
||||
}
|
||||
|
@ -105,7 +105,7 @@ func IterateMorphShape(start, end Shape) (r []records.RecordPair) {
|
|||
|
||||
if prevEnd != nil && !prevEnd.GetEnd().Equals(endEdge.GetStart()) {
|
||||
advanceEnd = false
|
||||
endEdge = &records.MoveRecord{
|
||||
endEdge = records.MoveRecord{
|
||||
To: endEdge.GetStart(),
|
||||
Start: prevEnd.GetEnd(),
|
||||
}
|
||||
|
@ -114,12 +114,12 @@ func IterateMorphShape(start, end Shape) (r []records.RecordPair) {
|
|||
if startEdge.SameType(endEdge) {
|
||||
r = append(r, records.RecordPair{startEdge, endEdge})
|
||||
} else {
|
||||
aLineRecord, aIsLineRecord := startEdge.(*records.LineRecord)
|
||||
aMoveRecord, aIsMoveRecord := startEdge.(*records.MoveRecord)
|
||||
aQuadraticCurveRecord, aIsQuadraticCurveRecord := startEdge.(*records.QuadraticCurveRecord)
|
||||
bLineRecord, bIsLineRecord := endEdge.(*records.LineRecord)
|
||||
bMoveRecord, bIsMoveRecord := endEdge.(*records.MoveRecord)
|
||||
bQuadraticCurveRecord, bIsQuadraticCurveRecord := endEdge.(*records.QuadraticCurveRecord)
|
||||
aLineRecord, aIsLineRecord := startEdge.(records.LineRecord)
|
||||
aMoveRecord, aIsMoveRecord := startEdge.(records.MoveRecord)
|
||||
aQuadraticCurveRecord, aIsQuadraticCurveRecord := startEdge.(records.QuadraticCurveRecord)
|
||||
bLineRecord, bIsLineRecord := endEdge.(records.LineRecord)
|
||||
bMoveRecord, bIsMoveRecord := endEdge.(records.MoveRecord)
|
||||
bQuadraticCurveRecord, bIsQuadraticCurveRecord := endEdge.(records.QuadraticCurveRecord)
|
||||
|
||||
if aIsLineRecord && bIsQuadraticCurveRecord {
|
||||
startEdge = records.QuadraticCurveFromLineRecord(aLineRecord)
|
||||
|
@ -128,14 +128,14 @@ func IterateMorphShape(start, end Shape) (r []records.RecordPair) {
|
|||
endEdge = records.QuadraticCurveFromLineRecord(bLineRecord)
|
||||
r = append(r, records.RecordPair{aQuadraticCurveRecord, endEdge})
|
||||
} else if aIsMoveRecord && !bIsMoveRecord {
|
||||
endEdge = &records.MoveRecord{
|
||||
endEdge = records.MoveRecord{
|
||||
To: endEdge.GetStart(),
|
||||
Start: endEdge.GetStart(),
|
||||
}
|
||||
r = append(r, records.RecordPair{aMoveRecord, endEdge})
|
||||
advanceEnd = false
|
||||
} else if !aIsMoveRecord && bIsMoveRecord {
|
||||
startEdge = &records.MoveRecord{
|
||||
startEdge = records.MoveRecord{
|
||||
To: startEdge.GetStart(),
|
||||
Start: startEdge.GetStart(),
|
||||
}
|
||||
|
|
|
@ -20,8 +20,8 @@ func NewCircle[T ~float64 | ~int64](center math.Vector2[T], radius T) Ellipse[T]
|
|||
// ellipseC 0.5522847498307935
|
||||
var ellipseC = (4 / float64(3)) * (stdmath.Sqrt(2) - 1)
|
||||
|
||||
func ellipseDrawQuarter(center, size math.Vector2[float64]) *records.CubicCurveRecord {
|
||||
return &records.CubicCurveRecord{
|
||||
func ellipseDrawQuarter(center, size math.Vector2[float64]) records.CubicCurveRecord {
|
||||
return records.CubicCurveRecord{
|
||||
Control1: math.NewVector2(center.X-size.X, center.Y-ellipseC*size.Y),
|
||||
Control2: math.NewVector2(center.X-ellipseC*size.X, center.Y-size.Y),
|
||||
Anchor: math.NewVector2(center.X, center.Y-size.Y),
|
||||
|
|
|
@ -51,19 +51,19 @@ func (r Rectangle[T]) Draw() Shape {
|
|||
tl := r.TopLeft.Float64()
|
||||
br := r.BottomRight.Float64()
|
||||
return Shape{
|
||||
&records.LineRecord{
|
||||
records.LineRecord{
|
||||
To: math.NewVector2(tl.X, br.Y),
|
||||
Start: tl,
|
||||
},
|
||||
&records.LineRecord{
|
||||
records.LineRecord{
|
||||
To: br,
|
||||
Start: math.NewVector2(tl.X, br.Y),
|
||||
},
|
||||
&records.LineRecord{
|
||||
records.LineRecord{
|
||||
To: math.NewVector2(br.X, tl.Y),
|
||||
Start: br,
|
||||
},
|
||||
&records.LineRecord{
|
||||
records.LineRecord{
|
||||
To: tl,
|
||||
Start: math.NewVector2(br.X, tl.Y),
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue