1 /*
2 * Copyright (c) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 //! Rust utils for cxx
17 #[cxx::bridge]
18 mod ffi{
19 #![allow(dead_code)]
20 extern "Rust"{
generate_value(start_value: f32, end_value: f32, start_time: i32, end_time: i32, current_time: i32) -> f3221 fn generate_value(start_value: f32, end_value: f32, start_time: i32, end_time: i32, current_time: i32) -> f32 ;
22 }
23 }
24
generate_value(start_value: f32, end_value: f32, start_time: i32, end_time: i32, current_time: i32) -> f3225 fn generate_value(start_value: f32, end_value: f32, start_time: i32, end_time: i32, current_time: i32) -> f32 {
26 let t = if end_time - start_time != 0 {
27 (current_time - start_time) as f32 / (end_time - start_time) as f32
28 } else {
29 0.0
30 };
31 let interpolation_value = start_value * (1.0 - t) + end_value * t;
32 interpolation_value
33 }
34