animation/three_point.go

Functions

Functions

func Evaluate

Evaluate returns the easing value for the given normalized time x in [0,1].

func (tc *threePointCubic) Evaluate(x float32) float32 {
	if x <= 0 {
		return 0
	}
	if x >= 1 {
		return 1
	}

	midX := tc.midpoint[0]
	midY := tc.midpoint[1]

	if x < midX {
		// First segment: normalize x to [0,1] within segment range.
		if midX <= 0 {
			return 0
		}
		localT := x / midX
		return tc.seg1.Evaluate(localT) * midY
	}

	// Second segment: normalize x to [0,1] within segment range.
	rangeX := 1 - midX
	rangeY := 1 - midY
	if rangeX <= 0 {
		return 1
	}
	localT := (x - midX) / rangeX
	return midY + tc.seg2.Evaluate(localT)*rangeY
}

func ThreePointCubic

ThreePointCubic creates an Easing function from a two-segment cubic curve.

 

This is used for Material Design 3's Emphasized easing, which requires

two joined cubic bezier segments sharing a midpoint.

 

Parameters:

- a1, b1: control points for first segment (origin to midpoint)

- mid: shared midpoint

- a2, b2: control points for second segment (midpoint to end)

 

Example (M3 Emphasized):

 

emphasized := animation.ThreePointCubic(

[2]float32{0.05, 0},

[2]float32{0.133333, 0.06},

[2]float32{0.166666, 0.4},

[2]float32{0.208333, 0.82},

[2]float32{0.25, 1.0},

)

func ThreePointCubic(a1, b1, mid, a2, b2 [2]float32) Easing {
	tc := newThreePointCubic(a1, b1, mid, a2, b2)
	return tc.Evaluate
}