Fix Vector2 Equals() for float64, fixed position transitions
This commit is contained in:
parent
5cdf3c3d97
commit
108f383eca
|
@ -4,6 +4,7 @@ import (
|
|||
"fmt"
|
||||
"git.gammaspectra.live/WeebDataHoarder/swf2ass-go/ass/time"
|
||||
"git.gammaspectra.live/WeebDataHoarder/swf2ass-go/settings"
|
||||
"git.gammaspectra.live/WeebDataHoarder/swf2ass-go/types"
|
||||
"git.gammaspectra.live/WeebDataHoarder/swf2ass-go/types/math"
|
||||
"git.gammaspectra.live/WeebDataHoarder/swf2ass-go/types/shapes"
|
||||
"golang.org/x/exp/maps"
|
||||
|
@ -15,7 +16,7 @@ type ContainerTag struct {
|
|||
Tags []Tag
|
||||
Transitions map[int64][]Tag
|
||||
|
||||
BakeTransforms *math.MatrixTransform
|
||||
BakedTransform types.Option[math.MatrixTransform]
|
||||
}
|
||||
|
||||
func (t *ContainerTag) HasColor() bool {
|
||||
|
@ -59,9 +60,9 @@ func (t *ContainerTag) TransitionColor(event Event, transform math.ColorTransfor
|
|||
}
|
||||
|
||||
func (t *ContainerTag) TransitionMatrixTransform(event Event, transform math.MatrixTransform) PositioningTag {
|
||||
if t.BakeTransforms != nil {
|
||||
if bakedTransform, ok := t.BakedTransform.Some(); ok {
|
||||
//Do not allow matrix changes, except moves
|
||||
if !transform.EqualsWithoutTranslation(*t.BakeTransforms, math.TransformCompareEpsilon) {
|
||||
if !transform.EqualsWithoutTranslation(bakedTransform, math.TransformCompareEpsilon) {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
@ -159,11 +160,8 @@ func (t *ContainerTag) FromStyleRecord(record shapes.StyleRecord, transform math
|
|||
}
|
||||
|
||||
func (t *ContainerTag) Clone(cloneTags bool) *ContainerTag {
|
||||
var transform *math.MatrixTransform
|
||||
if t.BakeTransforms != nil {
|
||||
t2 := *t.BakeTransforms
|
||||
transform = &t2
|
||||
}
|
||||
bakedTransform := types.SomeWith(t.BakedTransform.Some())
|
||||
|
||||
transitions := make(map[int64][]Tag, len(t.Transitions))
|
||||
for k := range t.Transitions {
|
||||
transitions[k] = slices.Clone(t.Transitions[k])
|
||||
|
@ -172,13 +170,13 @@ func (t *ContainerTag) Clone(cloneTags bool) *ContainerTag {
|
|||
return &ContainerTag{
|
||||
Tags: slices.Clone(t.Tags),
|
||||
Transitions: transitions,
|
||||
BakeTransforms: transform,
|
||||
BakedTransform: bakedTransform,
|
||||
}
|
||||
} else {
|
||||
return &ContainerTag{
|
||||
Tags: t.Tags,
|
||||
Transitions: transitions,
|
||||
BakeTransforms: transform,
|
||||
BakedTransform: bakedTransform,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -264,14 +262,12 @@ func (t *ContainerTag) TryAppend(tag Tag) {
|
|||
panic("tag is nil")
|
||||
}
|
||||
|
||||
var identityMatrixTransform = math.IdentityTransform()
|
||||
|
||||
func ContainerTagFromPathEntry(path shapes.DrawPath, clip *shapes.ClipPath, colorTransform math.ColorTransform, matrixTransform math.MatrixTransform, bakeMatrixTransforms bool) *ContainerTag {
|
||||
container := &ContainerTag{
|
||||
Transitions: make(map[int64][]Tag),
|
||||
}
|
||||
|
||||
if !matrixTransform.EqualsExact(identityMatrixTransform) {
|
||||
if !matrixTransform.IsIdentity() {
|
||||
if bakeMatrixTransforms {
|
||||
path = path.ApplyMatrixTransform(matrixTransform, false)
|
||||
}
|
||||
|
@ -304,7 +300,7 @@ func ContainerTagFromPathEntry(path shapes.DrawPath, clip *shapes.ClipPath, colo
|
|||
}
|
||||
|
||||
if bakeMatrixTransforms {
|
||||
container.BakeTransforms = &matrixTransform
|
||||
container.BakedTransform = types.Some(matrixTransform)
|
||||
container.TryAppend((&PositionTag{}).FromMatrixTransform(matrixTransform))
|
||||
} else {
|
||||
container.TryAppend((&PositionTag{}).FromMatrixTransform(matrixTransform))
|
||||
|
|
|
@ -535,8 +535,8 @@ func (p *SWFTreeProcessor) process(actions ActionList) (tag swftag.Tag, newActio
|
|||
var object shapes.ObjectDefinition
|
||||
if node.Flag.HasCharacter {
|
||||
object = p.Objects.Get(node.CharacterId)
|
||||
} else {
|
||||
object = p.Layout.Get(node.Depth).Object
|
||||
} else if layout := p.Layout.Get(node.Depth); layout != nil {
|
||||
object = layout.Object
|
||||
}
|
||||
|
||||
p.placeObject(object, placeObjectData{
|
||||
|
|
|
@ -40,7 +40,7 @@ func (v Vector2[T]) Equals(b Vector2[T]) bool {
|
|||
}
|
||||
|
||||
func (v Vector2[T]) equalsFloat(b Vector2[T]) bool {
|
||||
return v == b || ((math.Abs(float64(b.Y-v.Y))) <= epsilon && (math.Abs(float64(b.X-v.Y))) <= epsilon)
|
||||
return v == b || ((math.Abs(float64(b.X-v.X))) <= epsilon && (math.Abs(float64(b.Y-v.Y))) <= epsilon)
|
||||
}
|
||||
|
||||
func (v Vector2[T]) equalsInt(b Vector2[T]) bool {
|
||||
|
|
Loading…
Reference in a new issue