lgeo/gjk/
support.rs

1// uses
2use lmaths::*;
3use crate::Shape;
4
5/// The support point between two shape in a certain direction
6#[derive(Clone, Debug, Copy)]
7pub struct SupportPoint {
8    /// Support coordinate
9    pub v: Vector2,
10    /// Shape A point
11    sup_a: Vector2,
12    /// Shape B point
13    sup_b: Vector2,
14}
15
16#[allow(dead_code)]
17impl SupportPoint {
18    /// Create a new empty Support Point
19    pub fn new() -> Self {
20        Self {
21            v: Vector2::ZERO,
22            sup_a: Vector2::ZERO,
23            sup_b: Vector2::ZERO,
24        }
25    }
26
27    /// Generate the support point between 2 shapes, using the Minkowski difference
28    pub fn from_minkowski (left:&dyn Shape, right:&dyn Shape, direction:Vector2) -> Self {
29        let l = left.support_point(direction);
30        let r = right.support_point(-direction);
31
32        Self {
33            v: (l - r),
34            sup_a: l,
35            sup_b: r,
36        }
37    }
38}
39
40impl std::ops::Sub<Vector2> for SupportPoint {
41    type Output = Self;
42
43    fn sub(self, rhs:Vector2) -> Self {
44        SupportPoint {
45            v: self.v - rhs,
46            sup_a: self.sup_a,
47            sup_b: self.sup_b,
48        }
49    }
50}