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
use crate;
use crate;
/// Computes the separation distance between a point and a cuboid along a specified normal direction.
///
/// This function is used in SAT (Separating Axis Theorem) implementations for shapes that can be
/// treated as having a single representative point with an associated normal vector. Examples include:
/// - Segments (in 2D, using one endpoint and the segment's normal)
/// - Triangles (in 3D, using one vertex and the triangle's face normal)
///
/// # Why This Works
///
/// For a cuboid centered at the origin with symmetry, we only need to test one direction of the
/// normal (not both +normal and -normal) because the cuboid looks the same from both directions.
/// This optimization makes the function more efficient than the general support map approach.
///
/// # Parameters
///
/// - `point1`: A point in the first shape's local coordinate space
/// - `normal1`: Optional unit normal vector associated with the point (e.g., triangle face normal)
/// - If `None`, the function returns maximum negative separation (indicating overlap)
/// - `shape2`: The cuboid to test against
/// - `pos12`: The position of `shape2` (cuboid) relative to `point1`'s coordinate frame
///
/// # Returns
///
/// A tuple containing:
/// - `Real`: The separation distance along the normal direction
/// - **Positive**: The point and cuboid are separated
/// - **Negative**: The point penetrates the cuboid (or normal is None)
/// - **Zero**: The point exactly touches the cuboid surface
/// - `Vector`: The oriented normal direction used for the test (pointing from point toward cuboid)
///
/// # Example
///
/// ```rust
/// # #[cfg(all(feature = "dim2", feature = "f32"))] {
/// use parry2d::shape::Cuboid;
/// use parry2d::query::sat::point_cuboid_find_local_separating_normal_oneway;
/// use parry2d::math::{Vector, Pose};
///
/// let point = Vector::ZERO;
/// let normal = Some((Vector::X.normalize()));
/// let cuboid = Cuboid::new(Vector::new(1.0, 1.0));
///
/// // Position cuboid 3 units to the right
/// let pos12 = Pose::translation(3.0, 0.0);
///
/// let (separation, _dir) = point_cuboid_find_local_separating_normal_oneway(
/// point,
/// normal,
/// &cuboid,
/// &pos12
/// );
///
/// // Should be separated by 1.0 (distance 3.0 - cuboid extent 1.0 - point distance 0.0)
/// assert!(separation > 0.0);
/// # }
/// ```
///
/// # Implementation Note
///
/// This function only works correctly when the **cuboid is on the right-hand side** (as shape2)
/// because it exploits the cuboid's symmetry around the origin. The cuboid must be centered at
/// its local origin for this optimization to be valid.