use crate::float::overlay::OverlayOptions;
use crate::string::graph::StringGraph;
use crate::string::rule::StringRule;
use i_float::adapter::FloatPointAdapter;
use i_float::float::compatible::FloatPointCompatible;
use i_shape::base::data::Shapes;
use i_shape::float::adapter::ShapesToFloat;
use i_shape::float::despike::DeSpikeContour;
use i_shape::float::simple::SimplifyContour;
pub struct FloatStringGraph<'a, P: FloatPointCompatible> {
pub graph: StringGraph<'a>,
pub adapter: FloatPointAdapter<P>,
}
impl<P: FloatPointCompatible> FloatStringGraph<'_, P> {
#[inline(always)]
pub fn extract_shapes(&self, string_rule: StringRule) -> Shapes<P> {
self.extract_shapes_custom(string_rule, Default::default())
}
#[inline]
pub fn extract_shapes_custom(
&self,
string_rule: StringRule,
options: OverlayOptions<P::Scalar>,
) -> Shapes<P> {
let shapes = self
.graph
.extract_shapes_custom(string_rule, options.int_with_adapter(&self.adapter));
let mut float = shapes.to_float(&self.adapter);
if options.clean_result {
if options.preserve_output_collinear {
float.despike_contour(&self.adapter);
} else {
float.simplify_contour(&self.adapter);
}
}
float
}
}