|
| 1 | +// |
| 2 | +// Copyright (C) 2024 David Cattermole. |
| 3 | +// |
| 4 | +// This file is part of mmSolver. |
| 5 | +// |
| 6 | +// mmSolver is free software: you can redistribute it and/or modify it |
| 7 | +// under the terms of the GNU Lesser General Public License as |
| 8 | +// published by the Free Software Foundation, either version 3 of the |
| 9 | +// License, or (at your option) any later version. |
| 10 | +// |
| 11 | +// mmSolver is distributed in the hope that it will be useful, |
| 12 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | +// GNU Lesser General Public License for more details. |
| 15 | +// |
| 16 | +// You should have received a copy of the GNU Lesser General Public License |
| 17 | +// along with mmSolver. If not, see <https://www.gnu.org/licenses/>. |
| 18 | +// ==================================================================== |
| 19 | +// |
| 20 | + |
| 21 | +use mmscenegraph_rust::constant::Real as CoreReal; |
| 22 | +use mmscenegraph_rust::curve::detect::pops::detect_curve_pops as core_detect_curve_pops; |
| 23 | +use mmscenegraph_rust::curve::detect::pops::filter_curve_pops as core_filter_curve_pops; |
| 24 | + |
| 25 | +pub fn shim_detect_curve_pops( |
| 26 | + // xy_values: &[(CoreReal, CoreReal)], |
| 27 | + x_values: &[CoreReal], |
| 28 | + y_values: &[CoreReal], |
| 29 | + threshold: CoreReal, |
| 30 | + out_x_values: &mut Vec<CoreReal>, |
| 31 | + out_y_values: &mut Vec<CoreReal>, |
| 32 | +) -> bool { |
| 33 | + let result = core_detect_curve_pops(&x_values, &y_values, threshold); |
| 34 | + match result { |
| 35 | + Ok(values) => { |
| 36 | + let new_x_capacity = |
| 37 | + values.len().saturating_sub(out_x_values.capacity()); |
| 38 | + let new_y_capacity = |
| 39 | + values.len().saturating_sub(out_y_values.capacity()); |
| 40 | + out_x_values.reserve_exact(new_x_capacity); |
| 41 | + out_y_values.reserve_exact(new_y_capacity); |
| 42 | + out_x_values.clear(); |
| 43 | + out_y_values.clear(); |
| 44 | + |
| 45 | + for value in values.iter() { |
| 46 | + let x = value.0; |
| 47 | + let y = value.1; |
| 48 | + out_x_values.push(x); |
| 49 | + out_y_values.push(y); |
| 50 | + } |
| 51 | + |
| 52 | + true |
| 53 | + } |
| 54 | + Err(_) => false, |
| 55 | + } |
| 56 | +} |
| 57 | + |
| 58 | +pub fn shim_filter_curve_pops( |
| 59 | + // xy_values: &[(CoreReal, CoreReal)], |
| 60 | + x_values: &[CoreReal], |
| 61 | + y_values: &[CoreReal], |
| 62 | + threshold: CoreReal, |
| 63 | + out_x_values: &mut Vec<CoreReal>, |
| 64 | + out_y_values: &mut Vec<CoreReal>, |
| 65 | +) -> bool { |
| 66 | + let result = core_filter_curve_pops(&x_values, &y_values, threshold); |
| 67 | + match result { |
| 68 | + Ok(values) => { |
| 69 | + let new_x_capacity = |
| 70 | + values.len().saturating_sub(out_x_values.capacity()); |
| 71 | + let new_y_capacity = |
| 72 | + values.len().saturating_sub(out_y_values.capacity()); |
| 73 | + out_x_values.reserve_exact(new_x_capacity); |
| 74 | + out_y_values.reserve_exact(new_y_capacity); |
| 75 | + out_x_values.clear(); |
| 76 | + out_y_values.clear(); |
| 77 | + |
| 78 | + for value in values.iter() { |
| 79 | + let x = value.0; |
| 80 | + let y = value.1; |
| 81 | + out_x_values.push(x); |
| 82 | + out_y_values.push(y); |
| 83 | + } |
| 84 | + |
| 85 | + true |
| 86 | + } |
| 87 | + Err(_) => false, |
| 88 | + } |
| 89 | +} |
0 commit comments