Skip to content

Commit

Permalink
Fix segment repeating + cleanup speed calculation (#4557)
Browse files Browse the repository at this point in the history
  • Loading branch information
NodudeWasTaken authored Feb 15, 2024
1 parent dad4ab6 commit 15aac68
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions internal/manager/generator_interactive_heatmap_speed.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ type Action struct {
// Pos is the place in percent to move to.
Pos int `json:"pos"`

Slope float64
Intensity int64
Speed float64
Speed float64
}

type GradientTable []struct {
Expand Down Expand Up @@ -136,8 +134,7 @@ func (funscript *Script) UpdateIntensityAndSpeed() {

var t1, t2 int64
var p1, p2 int
var slope float64
var intensity int64
var intensity float64
for i := range funscript.Actions {
if i == 0 {
continue
Expand All @@ -147,13 +144,10 @@ func (funscript *Script) UpdateIntensityAndSpeed() {
p1 = funscript.Actions[i].Pos
p2 = funscript.Actions[i-1].Pos

slope = math.Min(math.Max(1/(2*float64(t1-t2)/1000), 0), 20)
intensity = int64(slope * math.Abs((float64)(p1-p2)))
speed := math.Abs(float64(p1-p2)) / float64(t1-t2) * 1000
speed := math.Abs(float64(p1 - p2))
intensity = float64(speed/float64(t1-t2)) * 1000

funscript.Actions[i].Slope = slope
funscript.Actions[i].Intensity = intensity
funscript.Actions[i].Speed = speed
funscript.Actions[i].Speed = intensity
}
}

Expand Down Expand Up @@ -294,7 +288,7 @@ func (funscript Script) getGradientTable(numSegments int, sceneDurationMilli int
}
segments[segment].at = a.At
segments[segment].count++
segments[segment].intensity += int(a.Intensity)
segments[segment].intensity += int(a.Speed)
segments[segment].yRange[0] = averageTop
segments[segment].yRange[1] = averageBottom
}
Expand All @@ -303,7 +297,7 @@ func (funscript Script) getGradientTable(numSegments int, sceneDurationMilli int

// Fill in gaps in segments
for i := 0; i < numSegments; i++ {
segmentTS := int64(float64(i) / float64(numSegments))
segmentTS := (maxts / int64(numSegments)) * int64(i)

// Empty segment - fill it with the previous up to backfillThreshold ms
if segments[i].count == 0 {
Expand Down Expand Up @@ -340,12 +334,12 @@ func getSegmentColor(intensity float64) colorful.Color {
colorBlack, _ := colorful.Hex("#0f001e")
colorBackground, _ := colorful.Hex("#30404d") // Same as GridCard bg

var stepSize = 60.0
var stepSize = 125.0
var f float64
var c colorful.Color

switch {
case intensity <= 0.001:
case intensity <= 25:
c = colorBackground
case intensity <= 1*stepSize:
f = (intensity - 0*stepSize) / stepSize
Expand Down

0 comments on commit 15aac68

Please sign in to comment.