euv-core 0.52.0

Core cross-platform runtime for euv featuring arena-based fine-grained reactivity, deterministic layout, flat scene graph, multi-mode rendering, and direct OS platform adapters.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
use super::*;

/// Constructors and bounding-box helpers for `RigidBody3D`.
impl RigidBody3D {
    /// Creates a dynamic 3D rigid body with given mass, position, and box half-extents.
    ///
    /// # Arguments
    ///
    /// - `Vec3` - Initial center position.
    /// - `Vec3` - Box half-extents `(hx, hy, hz)`.
    /// - `f32` - Positive mass in kilograms.
    ///
    /// # Returns
    ///
    /// - `Self` - Dynamic rigid body.
    #[must_use]
    pub fn dynamic_box(position: Vec3, half_extents: Vec3, mass: f32) -> Self {
        Self {
            position,
            velocity: Vec3::zero(),
            angular_velocity: Vec3::zero(),
            half_extents,
            inv_mass: 1.0 / mass.max(0.01),
            restitution: 0.35,
            friction: 0.45,
            linear_damping: 0.04,
            sleep_timer: 0.0,
            sleeping: false,
            grounded: false,
        }
    }

    /// Creates a static immovable 3D box collider.
    ///
    /// # Arguments
    ///
    /// - `Vec3` - Center position.
    /// - `Vec3` - Box half-extents `(hx, hy, hz)`.
    ///
    /// # Returns
    ///
    /// - `Self` - Static rigid body (`inv_mass = 0.0`).
    #[must_use]
    pub fn static_box(position: Vec3, half_extents: Vec3) -> Self {
        Self {
            position,
            velocity: Vec3::zero(),
            angular_velocity: Vec3::zero(),
            half_extents,
            inv_mass: 0.0,
            restitution: 0.25,
            friction: 0.55,
            linear_damping: 0.0,
            sleep_timer: 0.0,
            sleeping: true,
            grounded: true,
        }
    }

    /// Computes this body's world-space `AxisAlignedBox3D`.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Body reference.
    ///
    /// # Returns
    ///
    /// - `AxisAlignedBox3D` - World-space bounding box.
    #[must_use]
    pub fn world_bounds(&self) -> AxisAlignedBox3D {
        let vec_value: Vec3 = self.get_position();
        let height_val: Vec3 = self.get_half_extents();
        AxisAlignedBox3D::new(vec_value.sub(height_val), vec_value.add(height_val))
    }

    /// Wakes a sleeping dynamic rigid body so it resumes simulation on the next step.
    pub fn wake(&mut self) {
        if self.get_inv_mass() > 0.0 {
            self.set_sleeping(false);
            self.set_sleep_timer(0.0);
        }
    }

    /// Applies an instantaneous linear impulse to a dynamic rigid body.
    ///
    /// # Arguments
    ///
    /// - `Vec3` - Linear impulse vector in `N*s`.
    pub fn apply_impulse(&mut self, impulse: Vec3) {
        let inv_m: f32 = self.get_inv_mass();
        if inv_m > 0.0 {
            self.wake();
            let next_v: Vec3 = self.get_velocity().add(impulse.scale(inv_m));
            self.set_velocity(next_v);
        }
    }
}

/// Default Earth-gravity 3D physics world.
impl Default for PhysicsWorld3D {
    /// Creates an empty `PhysicsWorld3D` with `-9.81 m/s^2` gravity and ground at `y = 0.0`.
    ///
    /// # Returns
    ///
    /// - `Self` - Ready 3D physics world.
    fn default() -> Self {
        Self {
            gravity: Vec3::new(0.0, -9.81, 0.0),
            ground_y: 0.0,
            bodies: Vec::new(),
            hash_heads: Vec::new(),
            hash_next: Vec::new(),
            hash_body: Vec::new(),
            touched_buckets: Vec::new(),
            pair_scratch: Vec::new(),
        }
    }
}

/// Rigid-body integration, spatial-hash broadphase, axis-aligned bounding box collision resolution, and raycasting for `PhysicsWorld3D`.
impl PhysicsWorld3D {
    /// Computes the bucket index in `0..bucket_count` for integer 3D grid cell `(cx, cy, cz)`.
    ///
    /// # Arguments
    ///
    /// - `i32` - Cell X coordinate.
    /// - `i32` - Cell Y coordinate.
    /// - `i32` - Cell Z coordinate.
    /// - `usize` - Power-of-two bucket mask (`bucket_count - 1`).
    ///
    /// # Returns
    ///
    /// - `usize` - Hash bucket index.
    #[inline(always)]
    #[must_use]
    fn hash_cell(cx: i32, cy: i32, cz: i32, mask: usize) -> usize {
        let height_val: u32 = (cx.wrapping_mul(73_856_093) as u32)
            ^ (cy.wrapping_mul(19_349_663) as u32)
            ^ (cz.wrapping_mul(83_492_791) as u32);
        (height_val as usize) & mask
    }

    /// Resolves a single candidate rigid-body pair `(i, j)` in place and returns `true` if colliding.
    ///
    /// # Arguments
    ///
    /// - `&mut [RigidBody3D]` - Mutable rigid-body slice.
    /// - `usize` - First body index.
    /// - `usize` - Second body index.
    ///
    /// # Returns
    ///
    /// - `bool` - `true` when an overlap was resolved.
    #[inline(always)]
    fn resolve_body_pair(
        bodies: &mut [RigidBody3D],
        item_index: usize,
        inner_index: usize,
    ) -> bool {
        let alpha_val: RigidBody3D = bodies[item_index];
        let blue_val: RigidBody3D = bodies[inner_index];
        let alpha_inactive: bool = alpha_val.get_inv_mass() <= 0.0 || alpha_val.get_sleeping();
        let blue_inactive: bool = blue_val.get_inv_mass() <= 0.0 || blue_val.get_sleeping();
        if alpha_inactive && blue_inactive {
            return false;
        }
        let inv_sum: f32 = alpha_val.get_inv_mass() + blue_val.get_inv_mass();
        if inv_sum <= 0.0 {
            return false;
        }
        let delta: Vec3 = blue_val.get_position().sub(alpha_val.get_position());
        let ox: f32 = alpha_val.get_half_extents().get_x() + blue_val.get_half_extents().get_x()
            - delta.get_x().abs();
        let oy: f32 = alpha_val.get_half_extents().get_y() + blue_val.get_half_extents().get_y()
            - delta.get_y().abs();
        let oz: f32 = alpha_val.get_half_extents().get_z() + blue_val.get_half_extents().get_z()
            - delta.get_z().abs();
        if ox <= 0.0 || oy <= 0.0 || oz <= 0.0 {
            return false;
        }
        let (normal, pen): (Vec3, f32) = if ox <= oy && ox <= oz {
            let source_val: f32 = if delta.get_x() < 0.0 { -1.0 } else { 1.0 };
            (Vec3::new(source_val, 0.0, 0.0), ox)
        } else if oy <= oz {
            let scale_val: f32 = if delta.get_y() < 0.0 { -1.0 } else { 1.0 };
            (Vec3::new(0.0, scale_val, 0.0), oy)
        } else {
            let series_item: f32 = if delta.get_z() < 0.0 { -1.0 } else { 1.0 };
            (Vec3::new(0.0, 0.0, series_item), oz)
        };
        let corr: Vec3 = normal.scale(pen / inv_sum);
        let a_pos: Vec3 = alpha_val
            .get_position()
            .sub(corr.scale(alpha_val.get_inv_mass()));
        let b_pos: Vec3 = blue_val
            .get_position()
            .add(corr.scale(blue_val.get_inv_mass()));
        let rel_v: Vec3 = blue_val.get_velocity().sub(alpha_val.get_velocity());
        let vn: f32 = rel_v.dot(normal);
        let mut a_vel: Vec3 = alpha_val.get_velocity();
        let mut b_vel: Vec3 = blue_val.get_velocity();
        let mut a_ang: Vec3 = alpha_val.get_angular_velocity();
        let mut b_ang: Vec3 = blue_val.get_angular_velocity();
        if vn < 0.0 {
            let rest: f32 = alpha_val.get_restitution().min(blue_val.get_restitution());
            let j_imp: f32 = -(1.0 + rest) * vn / inv_sum;
            let imp: Vec3 = normal.scale(j_imp);
            a_vel = a_vel.sub(imp.scale(alpha_val.get_inv_mass()));
            b_vel = b_vel.add(imp.scale(blue_val.get_inv_mass()));
            let tangent_raw: Vec3 = rel_v.sub(normal.scale(vn));
            let tangent_len_sq: f32 = tangent_raw.length_sq();
            if tangent_len_sq > 1e-8 {
                let tangent: Vec3 = tangent_raw.scale(1.0 / tangent_len_sq.sqrt());
                let vt: f32 = rel_v.dot(tangent);
                let combined_friction: f32 =
                    (alpha_val.get_friction() * blue_val.get_friction()).sqrt();
                let jt: f32 =
                    (-vt / inv_sum).clamp(-j_imp * combined_friction, j_imp * combined_friction);
                let friction_imp: Vec3 = tangent.scale(jt);
                a_vel = a_vel.sub(friction_imp.scale(alpha_val.get_inv_mass()));
                b_vel = b_vel.add(friction_imp.scale(blue_val.get_inv_mass()));
                let spin_axis: Vec3 = normal.cross(friction_imp);
                a_ang = a_ang.sub(spin_axis.scale(alpha_val.get_inv_mass() * 0.25));
                b_ang = b_ang.add(spin_axis.scale(blue_val.get_inv_mass() * 0.25));
            }
        }
        bodies[item_index].set_position(a_pos);
        bodies[item_index].set_velocity(a_vel);
        bodies[item_index].set_angular_velocity(a_ang);
        bodies[inner_index].set_position(b_pos);
        bodies[inner_index].set_velocity(b_vel);
        bodies[inner_index].set_angular_velocity(b_ang);
        if alpha_val.get_inv_mass() > 0.0 {
            bodies[item_index].wake();
        }
        if blue_val.get_inv_mass() > 0.0 {
            bodies[inner_index].wake();
        }
        true
    }

    /// Returns the number of currently awake dynamic rigid bodies active in the simulation.
    ///
    /// # Returns
    ///
    /// - `usize` - Count of dynamic bodies not in the sleeping island state.
    #[must_use]
    pub fn awake_body_count(&self) -> usize {
        self.get_bodies()
            .iter()
            .filter(|body: &&RigidBody3D| body.get_inv_mass() > 0.0 && !body.get_sleeping())
            .count()
    }

    /// Adds a `RigidBody3D` to the simulation and returns its handle index.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Mutable physics world.
    /// - `RigidBody3D` - Body to insert.
    ///
    /// # Returns
    ///
    /// - `usize` - Body index.
    pub fn add_body(&mut self, body: RigidBody3D) -> usize {
        let idx: usize = self.get_bodies().len();
        self.get_mut_bodies().push(body);
        idx
    }

    /// Advances all rigid bodies by `dt` seconds using adaptive CCD substepping, gravity, ground collisions, and an O(N) zero-allocation 3D spatial hash grid broadphase.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Mutable physics world.
    /// - `f32` - Timestep in seconds.
    ///
    /// # Returns
    ///
    /// - `usize` - Number of collisions resolved during this step.
    pub fn step(&mut self, dt: f32) -> usize {
        self.step_internal(dt, None)
    }

    /// Advances all rigid bodies by `dt` seconds with adaptive CCD substepping and real triangle-mesh collision against all solid `World3D` models.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Mutable physics world.
    /// - `f32` - Timestep in seconds.
    /// - `&World3D` - 3D world supplying real static/dynamic mesh colliders.
    ///
    /// # Returns
    ///
    /// - `usize` - Total rigid-body, ground, and real-mesh collisions resolved during this step.
    pub fn step_with_world(&mut self, dt: f32, world: &World3D) -> usize {
        self.step_internal(dt, Some(world))
    }

    /// Executes adaptive CCD substepping for `PhysicsWorld3D`, preventing high-speed tunneling through thin walls and optionally resolving dynamic bodies against real `World3D` mesh triangles.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Mutable physics world.
    /// - `f32` - Frame timestep in seconds.
    /// - `Option<&World3D>` - Optional 3D scene for real triangle-mesh collision resolution.
    ///
    /// # Returns
    ///
    /// - `usize` - Total collisions resolved across all substeps.
    fn step_internal(&mut self, dt: f32, world_opt: Option<&World3D>) -> usize {
        let total_dt: f32 = dt.clamp(0.0, 0.1);
        if total_dt <= 0.0 {
            return 0;
        }
        let gravity: Vec3 = self.get_gravity();
        let mut max_ratio: f32 = 0.0;
        for body in self.get_bodies().iter() {
            if body.get_inv_mass() <= 0.0 || body.get_sleeping() {
                continue;
            }
            let height_val: Vec3 = body.get_half_extents();
            let min_h: f32 = height_val
                .get_x()
                .min(height_val.get_y())
                .min(height_val.get_z())
                .max(0.05);
            let est_vel: Vec3 = body.get_velocity().add(gravity.scale(total_dt));
            let disp: f32 = est_vel.length() * total_dt;
            let ratio: f32 = disp / min_h;
            if ratio > max_ratio {
                max_ratio = ratio;
            }
        }
        let substeps: usize = if max_ratio > 0.45 {
            ((max_ratio / 0.45).ceil() as usize).clamp(2, 16)
        } else {
            1
        };
        let sub_dt: f32 = total_dt / (substeps as f32);
        let mut total_collisions: usize = 0;
        for _ in 0..substeps {
            total_collisions += self.step_single_substep(sub_dt, world_opt);
        }
        total_collisions
    }

    /// Advances a single physics substep including gravity, ground plane, spatial-hash body pairs, and optional real-mesh triangle collisions.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Mutable physics world.
    /// - `f32` - Substep duration in seconds.
    /// - `Option<&World3D>` - Optional 3D world for real mesh collision.
    ///
    /// # Returns
    ///
    /// - `usize` - Collisions resolved during this substep.
    fn step_single_substep(&mut self, step_dt: f32, world_opt: Option<&World3D>) -> usize {
        let gravity: Vec3 = self.get_gravity();
        let ground_y: f32 = self.get_ground_y();
        let mut collisions: usize = 0;
        let mut max_extent: f32 = 0.5;
        let Self {
            bodies,
            hash_heads,
            hash_next,
            hash_body,
            touched_buckets,
            pair_scratch,
            ..
        } = self;
        for body in bodies.iter_mut() {
            let height_val: Vec3 = body.get_half_extents();
            let extent: f32 = height_val
                .get_x()
                .max(height_val.get_y())
                .max(height_val.get_z());
            if extent > max_extent {
                max_extent = extent;
            }
            let inv_m: f32 = body.get_inv_mass();
            if inv_m <= 0.0 || body.get_sleeping() {
                continue;
            }
            let damp: f32 = (1.0 - body.get_linear_damping() * step_dt).clamp(0.0, 1.0);
            let ang_damp: f32 = (1.0 - 0.12 * step_dt).clamp(0.0, 1.0);
            let mut vel: Vec3 = body.get_velocity().add(gravity.scale(step_dt)).scale(damp);
            let mut ang_vel: Vec3 = body.get_angular_velocity().scale(ang_damp);
            let mut pos: Vec3 = body.get_position().add(vel.scale(step_dt));
            let min_y: f32 = ground_y + height_val.get_y();
            let mut grounded: bool = false;
            if pos.get_y() <= min_y {
                pos.set_y(min_y);
                let ground_grip: f32 = (1.0 - body.get_friction() * 0.18).clamp(0.75, 0.99);
                if vel.get_y() < 0.0 {
                    vel.set_y(-vel.get_y() * body.get_restitution());
                    if vel.get_y().abs() < 0.25 {
                        vel.set_y(0.0);
                    }
                    vel.set_x(vel.get_x() * ground_grip);
                    vel.set_z(vel.get_z() * ground_grip);
                    ang_vel = ang_vel.scale(ground_grip);
                    collisions += 1;
                }
                grounded = true;
            }
            if let Some(world) = world_opt {
                for _ in 0..3usize {
                    let oriented_box: OrientedBox3D = OrientedBox3D::from_bounds(
                        AxisAlignedBox3D::new(pos.sub(height_val), pos.add(height_val)),
                    );
                    let Some(hit) = world.mesh_oriented_box_collision(oriented_box, None) else {
                        break;
                    };
                    let vec_value: Vec3 = hit.get_normal();
                    pos = pos.add(vec_value.scale(hit.get_penetration() + 1e-4));
                    let vn: f32 = vel.dot(vec_value);
                    if vn < 0.0 {
                        let rest: f32 = body.get_restitution();
                        vel = vel.sub(vec_value.scale((1.0 + rest) * vn));
                    }
                    if vec_value.get_y() > 0.55 {
                        grounded = true;
                    }
                    collisions += 1;
                }
            }
            let speed_sq: f32 = vel.length_sq();
            let ang_speed_sq: f32 = ang_vel.length_sq();
            if grounded && speed_sq < 0.0025 && ang_speed_sq < 0.0025 {
                let next_sleep_timer: f32 = body.get_sleep_timer() + step_dt;
                body.set_sleep_timer(next_sleep_timer);
                if next_sleep_timer >= 0.45 {
                    vel = Vec3::zero();
                    ang_vel = Vec3::zero();
                    body.set_sleeping(true);
                }
            } else {
                body.set_sleep_timer(0.0);
            }
            body.set_position(pos);
            body.set_velocity(vel);
            body.set_angular_velocity(ang_vel);
            body.set_grounded(grounded);
        }
        let count: usize = bodies.len();
        if count <= 1 {
            return collisions;
        }
        if count <= 16 {
            for item_index in 0..count {
                for inner_index in (item_index + 1)..count {
                    if Self::resolve_body_pair(bodies.as_mut_slice(), item_index, inner_index) {
                        collisions += 1;
                    }
                }
            }
            return collisions;
        }
        let target_buckets: usize = (count * 4).next_power_of_two().clamp(256, 16_384);
        if hash_heads.len() != target_buckets {
            hash_heads.clear();
            hash_heads.resize(target_buckets, u32::MAX);
            touched_buckets.clear();
        } else {
            for &blue_val in touched_buckets.iter() {
                hash_heads[blue_val] = u32::MAX;
            }
            touched_buckets.clear();
        }
        hash_next.clear();
        hash_body.clear();
        pair_scratch.clear();
        let cell_size: f32 = (max_extent * 2.5).max(1.0);
        let inv_cell: f32 = 1.0 / cell_size;
        let mask: usize = target_buckets - 1;
        for (idx, body) in bodies.iter().enumerate() {
            let direction_vec: Vec3 = body.get_position();
            let span_height: Vec3 = body.get_half_extents();
            let min_cx: i32 =
                ((direction_vec.get_x() - span_height.get_x()) * inv_cell).floor() as i32;
            let max_cx: i32 =
                ((direction_vec.get_x() + span_height.get_x()) * inv_cell).floor() as i32;
            let min_cy: i32 =
                ((direction_vec.get_y() - span_height.get_y()) * inv_cell).floor() as i32;
            let max_cy: i32 =
                ((direction_vec.get_y() + span_height.get_y()) * inv_cell).floor() as i32;
            let min_cz: i32 =
                ((direction_vec.get_z() - span_height.get_z()) * inv_cell).floor() as i32;
            let max_cz: i32 =
                ((direction_vec.get_z() + span_height.get_z()) * inv_cell).floor() as i32;
            for cx in min_cx..=max_cx {
                for cy in min_cy..=max_cy {
                    for cz in min_cz..=max_cz {
                        let bucket: usize = Self::hash_cell(cx, cy, cz, mask);
                        let mut cur: u32 = hash_heads[bucket];
                        if cur == u32::MAX {
                            touched_buckets.push(bucket);
                        } else {
                            while cur != u32::MAX {
                                let other: usize = hash_body[cur as usize] as usize;
                                if other != idx {
                                    let pair: (usize, usize) = if other < idx {
                                        (other, idx)
                                    } else {
                                        (idx, other)
                                    };
                                    pair_scratch.push(pair);
                                }
                                cur = hash_next[cur as usize];
                            }
                        }
                        let entry: u32 = hash_body.len() as u32;
                        hash_body.push(idx as u32);
                        hash_next.push(hash_heads[bucket]);
                        hash_heads[bucket] = entry;
                    }
                }
            }
        }
        pair_scratch.sort_unstable();
        pair_scratch.dedup();
        for &(outer_index, col_index) in pair_scratch.iter() {
            if Self::resolve_body_pair(bodies.as_mut_slice(), outer_index, col_index) {
                collisions += 1;
            }
        }
        collisions
    }

    /// Casts a `Ray3D` against all 3D rigid bodies up to `max_distance` and returns the closest hit.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Physics world reference.
    /// - `&Ray3D` - Query ray.
    /// - `f32` - Maximum cast distance in meters.
    ///
    /// # Returns
    ///
    /// - `Option<RayHitPhysics3D>` - Closest hit body and contact position if any.
    #[must_use]
    pub fn raycast(&self, ray: &Ray3D, max_distance: f32) -> Option<RayHitPhysics3D> {
        let mut best: Option<RayHitPhysics3D> = None;
        let mut best_t: f32 = max_distance.max(0.0);
        for (idx, body) in self.get_bodies().iter().enumerate() {
            let bounds_rect: AxisAlignedBox3D = body.world_bounds();
            let blend_factor: f32 = bounds_rect.intersect_ray_near(
                ray.get_origin(),
                ray.get_inv_direction(),
                0.001,
                best_t,
            );
            if blend_factor.is_finite() && blend_factor < best_t {
                best_t = blend_factor;
                let vec_value: Vec3 = ray
                    .get_origin()
                    .add(ray.get_direction().scale(blend_factor));
                best = Some(RayHitPhysics3D::new(idx, blend_factor, vec_value));
            }
        }
        best
    }
}