use crate::{
error::ffi::with_ffi_error,
geom::{BoundingBox, FfiRotation, Location, Rotation},
rpc::Color,
};
use carla_sys::carla_rust::client::{
FfiDebugHelper, FfiDebugHelper_DrawArrow, FfiDebugHelper_DrawBox, FfiDebugHelper_DrawLine,
FfiDebugHelper_DrawPoint, FfiDebugHelper_DrawString,
};
pub struct DebugHelper {
pub(crate) inner: cxx::UniquePtr<FfiDebugHelper>,
}
impl DebugHelper {
pub fn draw_point(
&self,
location: Location,
size: f32,
color: Color,
life_time: f32,
persistent_lines: bool,
) -> crate::Result<()> {
let ffi_color = color.into();
with_ffi_error("draw_point", |e| {
FfiDebugHelper_DrawPoint(
&self.inner,
location.as_ffi(),
size,
&ffi_color,
life_time,
persistent_lines,
e,
);
})
}
pub fn draw_line(
&self,
begin: Location,
end: Location,
thickness: f32,
color: Color,
life_time: f32,
persistent_lines: bool,
) -> crate::Result<()> {
let ffi_color = color.into();
with_ffi_error("draw_line", |e| {
FfiDebugHelper_DrawLine(
&self.inner,
begin.as_ffi(),
end.as_ffi(),
thickness,
&ffi_color,
life_time,
persistent_lines,
e,
);
})
}
#[allow(clippy::too_many_arguments)]
pub fn draw_arrow(
&self,
begin: Location,
end: Location,
thickness: f32,
arrow_size: f32,
color: Color,
life_time: f32,
persistent_lines: bool,
) -> crate::Result<()> {
let ffi_color = color.into();
with_ffi_error("draw_arrow", |e| {
FfiDebugHelper_DrawArrow(
&self.inner,
begin.as_ffi(),
end.as_ffi(),
thickness,
arrow_size,
&ffi_color,
life_time,
persistent_lines,
e,
);
})
}
pub fn draw_box(
&self,
bbox: &BoundingBox,
rotation: Rotation,
thickness: f32,
color: Color,
life_time: f32,
persistent_lines: bool,
) -> crate::Result<()> {
let ffi_color = color.into();
let native_bbox = bbox.to_native();
let cpp_rotation = unsafe {
&*(rotation.as_ffi() as *const FfiRotation as *const carla_sys::carla::geom::Rotation)
};
with_ffi_error("draw_box", |e| {
FfiDebugHelper_DrawBox(
&self.inner,
&native_bbox,
cpp_rotation,
thickness,
&ffi_color,
life_time,
persistent_lines,
e,
);
})
}
pub fn draw_string(
&self,
location: Location,
text: &str,
draw_shadow: bool,
color: Color,
life_time: f32,
persistent_lines: bool,
) -> crate::Result<()> {
let ffi_color = color.into();
cxx::let_cxx_string!(text_cxx = text);
with_ffi_error("draw_string", |e| {
FfiDebugHelper_DrawString(
&self.inner,
location.as_ffi(),
&text_cxx,
draw_shadow,
&ffi_color,
life_time,
persistent_lines,
e,
);
})
}
}
#[cfg(test)]
mod tests {
#[test]
fn test_debug_helper_methods_compile() {
}
}