@@ -36,7 +36,7 @@ const props = withDefaults(
36
36
37
37
let animationFrameID: number | null = null ;
38
38
39
- const { domain, size, invScale } = useGraphContext ();
39
+ const { domain, invScale } = useGraphContext ();
40
40
const { parentToWorld } = useMatrices ();
41
41
const { parseColor } = useColors ();
42
42
@@ -48,10 +48,8 @@ const functionDomain = computed(() =>
48
48
);
49
49
50
50
const visiblePoints = computed (() => {
51
- const range = Math .abs (functionDomain .value .x - functionDomain .value .y );
52
- const step = range / size .value .x ;
53
- const i = Math .ceil ((props .end - functionDomain .value .x ) / step );
54
- return points .value .slice (0 , i );
51
+ const i = Math .ceil ((props .end - functionDomain .value .x ) / props .step );
52
+ return points .value .slice (0 , i + 1 );
55
53
});
56
54
57
55
const path = computed (() => {
@@ -72,12 +70,22 @@ const path = computed(() => {
72
70
function updatePoints() {
73
71
const now = Date .now ();
74
72
points .value = [];
75
- const range = Math .abs (functionDomain .value .x - functionDomain .value .y );
76
- const step = range / size .value .x ;
77
- for (let i = 0 ; i <= size .value .x ; i ++ ) {
78
- const x = functionDomain .value .x + i * step ;
73
+ const samples =
74
+ Math .ceil ((functionDomain .value .y - functionDomain .value .x ) / props .step ) +
75
+ 1 ;
76
+ for (let i = 0 ; i < samples ; i ++ ) {
77
+ let x: number ;
78
+
79
+ // special case handling for the last point to account for
80
+ // floating point precision issues
81
+ if (i === samples - 1 ) {
82
+ x = functionDomain .value .y ;
83
+ } else {
84
+ x = functionDomain .value .x + i * props .step ;
85
+ }
86
+
79
87
const y = props .function (x , now );
80
- points .value .push (new Vector2 (x , - y ));
88
+ points .value .push (new Vector2 (x , y ));
81
89
}
82
90
}
83
91
0 commit comments