Debian Codegraph @

src/com/github/weisj/jsvg/animation/value/AnimatedFloatList.java

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
•1 /*
2 * MIT License
3 *
4 * Copyright (c) 2024-2025 Jannis Weis
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
7 * associated documentation files (the "Software"), to deal in the Software without restriction,
8 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
9 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in all copies or
13 * substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
16 * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 *
21 */
22 package com.github.weisj.jsvg.animation.value;
23
24
25 import org.jetbrains.annotations.NotNull;
26
27 import com.github.weisj.jsvg.animation.Track;
28 import com.github.weisj.jsvg.attributes.value.FloatListValue;
29 import com.github.weisj.jsvg.renderer.MeasureContext;
30
31 public final class AnimatedFloatList implements FloatListValue {
32
33 private final @NotNull Track track;
34
35 private final @NotNull FloatListValue initial;
36 private final float @NotNull [] @NotNull [] values;
37 private float[] cache;
38
39 private long timestamp = 0;
40 private Track.InterpolationProgress progressCacheKey = null;
41
42 public AnimatedFloatList(@NotNull Track track, @NotNull FloatListValue initial,
43 float @NotNull [] @NotNull [] values) {
44 this.track = track;
45 this.initial = initial;
46 this.values = values;
47 }
48
49 public @NotNull FloatListValue initial() {
50 return initial;
51 }
52
53 public boolean isDirty(long timestamp) {
54 return this.timestamp != timestamp;
55 }
56
57 @Override
58 public float @NotNull [] get(@NotNull MeasureContext context) {
59 long ts = context.timestamp();
60 if (ts != this.timestamp) {
61 this.timestamp = ts;
62 Track.InterpolationProgress progress = track.interpolationProgress(ts, values.length);
63
64 if (progress.equals(progressCacheKey)) {
65 return cache;
66 }
67 progressCacheKey = progress;
68
69 if (progress.isInitial()) {
70 cache = initial.get(context);
71 return cache;
72 }
73
74 int index = progress.iterationIndex();
75 float[] start = values[index];
76 float[] end = index == values.length - 1 ? null : values[index + 1];
77
78 float fraction = progress.indexProgress();
79 cache = track.floatListInterpolator().interpolate(initial.get(context), start, end, fraction, cache);
80 }
81 return cache;
82 }
83 }