update
This commit is contained in:
@@ -13,7 +13,9 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::algorithm::connections::BellandeArchError;
|
||||
use crate::algorithm::connections::{
|
||||
euclidean_distance, vector_dot_product, vector_length, vector_subtract, BellandeArchError,
|
||||
};
|
||||
use bellande_limit::make_bellande_limit_request;
|
||||
use futures::future::join_all;
|
||||
use serde::{Deserialize, Serialize};
|
||||
@@ -389,65 +391,3 @@ fn calculate_path_box_size(path: &[Vec<f64>]) -> Result<f64, BellandeArchError>
|
||||
|
||||
Ok(size)
|
||||
}
|
||||
|
||||
/// Subtracts one vector from another
|
||||
fn vector_subtract(a: &[f64], b: &[f64]) -> Result<Vec<f64>, BellandeArchError> {
|
||||
if a.len() != b.len() {
|
||||
return Err(BellandeArchError::DimensionMismatch(format!(
|
||||
"Cannot subtract vectors with different dimensions: {} and {}",
|
||||
a.len(),
|
||||
b.len()
|
||||
)));
|
||||
}
|
||||
|
||||
Ok(a.iter().zip(b.iter()).map(|(x, y)| x - y).collect())
|
||||
}
|
||||
|
||||
/// Calculates the dot product of two vectors
|
||||
fn vector_dot_product(a: &[f64], b: &[f64]) -> Result<f64, BellandeArchError> {
|
||||
if a.len() != b.len() {
|
||||
return Err(BellandeArchError::DimensionMismatch(format!(
|
||||
"Cannot calculate dot product of vectors with different dimensions: {} and {}",
|
||||
a.len(),
|
||||
b.len()
|
||||
)));
|
||||
}
|
||||
|
||||
Ok(a.iter().zip(b.iter()).map(|(x, y)| x * y).sum())
|
||||
}
|
||||
|
||||
/// Calculates the Euclidean length of a vector
|
||||
fn vector_length(v: &[f64]) -> Result<f64, BellandeArchError> {
|
||||
Ok(v.iter().map(|x| x * x).sum::<f64>().sqrt())
|
||||
}
|
||||
|
||||
/// Calculates the Euclidean distance between two points
|
||||
pub fn euclidean_distance(point1: &[f64], point2: &[f64]) -> Result<f64, BellandeArchError> {
|
||||
if point1.len() != point2.len() {
|
||||
return Err(BellandeArchError::DimensionMismatch(format!(
|
||||
"Points have different dimensions: {} and {}",
|
||||
point1.len(),
|
||||
point2.len()
|
||||
)));
|
||||
}
|
||||
|
||||
let sum_squared: f64 = point1
|
||||
.iter()
|
||||
.zip(point2.iter())
|
||||
.map(|(a, b)| (a - b).powi(2))
|
||||
.sum();
|
||||
|
||||
Ok(sum_squared.sqrt())
|
||||
}
|
||||
|
||||
/// Validates if a point is within the bounds of a given space
|
||||
pub fn is_point_valid(point: &[f64], min_bounds: &[f64], max_bounds: &[f64]) -> bool {
|
||||
if point.len() != min_bounds.len() || point.len() != max_bounds.len() {
|
||||
return false;
|
||||
}
|
||||
|
||||
point
|
||||
.iter()
|
||||
.zip(min_bounds.iter().zip(max_bounds.iter()))
|
||||
.all(|(p, (min, max))| p >= min && p <= max)
|
||||
}
|
||||
|
@@ -14,4 +14,4 @@
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::algorithm::connections::BellandeArchError;
|
||||
use bellande_particle::make_bellande_particle_request;
|
||||
// use bellande_particle::make_bellande_particle_request;
|
||||
|
@@ -14,4 +14,4 @@
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::algorithm::connections::BellandeArchError;
|
||||
use bellande_probability::make_bellande_probability_request;
|
||||
// use bellande_probability::make_bellande_probability_request;
|
||||
|
@@ -14,4 +14,4 @@
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::algorithm::connections::BellandeArchError;
|
||||
use bellande_segment::make_bellande_segment_request;
|
||||
// use bellande_segment::make_bellande_segment_request;
|
||||
|
@@ -13,7 +13,10 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::algorithm::connections::BellandeArchError;
|
||||
use crate::algorithm::connections::{
|
||||
euclidean_distance, is_point_valid, vector_dot_product, vector_length, vector_subtract,
|
||||
BellandeArchError,
|
||||
};
|
||||
use bellande_step::make_bellande_step_request;
|
||||
use futures::future::join_all;
|
||||
use serde::{Deserialize, Serialize};
|
||||
@@ -404,68 +407,6 @@ impl SpatialTransformer {
|
||||
}
|
||||
}
|
||||
|
||||
/// Subtracts one vector from another
|
||||
fn vector_subtract(a: &[f64], b: &[f64]) -> Result<Vec<f64>, BellandeArchError> {
|
||||
if a.len() != b.len() {
|
||||
return Err(BellandeArchError::DimensionMismatch(format!(
|
||||
"Cannot subtract vectors with different dimensions: {} and {}",
|
||||
a.len(),
|
||||
b.len()
|
||||
)));
|
||||
}
|
||||
|
||||
Ok(a.iter().zip(b.iter()).map(|(x, y)| x - y).collect())
|
||||
}
|
||||
|
||||
/// Calculates the dot product of two vectors
|
||||
fn vector_dot_product(a: &[f64], b: &[f64]) -> Result<f64, BellandeArchError> {
|
||||
if a.len() != b.len() {
|
||||
return Err(BellandeArchError::DimensionMismatch(format!(
|
||||
"Cannot calculate dot product of vectors with different dimensions: {} and {}",
|
||||
a.len(),
|
||||
b.len()
|
||||
)));
|
||||
}
|
||||
|
||||
Ok(a.iter().zip(b.iter()).map(|(x, y)| x * y).sum())
|
||||
}
|
||||
|
||||
/// Calculates the Euclidean length of a vector
|
||||
fn vector_length(v: &[f64]) -> Result<f64, BellandeArchError> {
|
||||
Ok(v.iter().map(|x| x * x).sum::<f64>().sqrt())
|
||||
}
|
||||
|
||||
/// Calculates the Euclidean distance between two points
|
||||
pub fn euclidean_distance(point1: &[f64], point2: &[f64]) -> Result<f64, BellandeArchError> {
|
||||
if point1.len() != point2.len() {
|
||||
return Err(BellandeArchError::DimensionMismatch(format!(
|
||||
"Points have different dimensions: {} and {}",
|
||||
point1.len(),
|
||||
point2.len()
|
||||
)));
|
||||
}
|
||||
|
||||
let sum_squared: f64 = point1
|
||||
.iter()
|
||||
.zip(point2.iter())
|
||||
.map(|(a, b)| (a - b).powi(2))
|
||||
.sum();
|
||||
|
||||
Ok(sum_squared.sqrt())
|
||||
}
|
||||
|
||||
/// Validates if a point is within the bounds of a given space
|
||||
pub fn is_point_valid(point: &[f64], min_bounds: &[f64], max_bounds: &[f64]) -> bool {
|
||||
if point.len() != min_bounds.len() || point.len() != max_bounds.len() {
|
||||
return false;
|
||||
}
|
||||
|
||||
point
|
||||
.iter()
|
||||
.zip(min_bounds.iter().zip(max_bounds.iter()))
|
||||
.all(|(p, (min, max))| p >= min && p <= max)
|
||||
}
|
||||
|
||||
/// Converts between different coordinate representations
|
||||
pub fn convert_coordinate_system(
|
||||
coordinates: &[f64],
|
||||
|
@@ -14,4 +14,4 @@
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::algorithm::connections::BellandeArchError;
|
||||
use bellande_tree::make_bellande_tree_request;
|
||||
// use bellande_tree::make_bellande_tree_request;
|
||||
|
@@ -34,3 +34,65 @@ impl fmt::Display for BellandeArchError {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Subtracts one vector from another
|
||||
pub fn vector_subtract(a: &[f64], b: &[f64]) -> Result<Vec<f64>, BellandeArchError> {
|
||||
if a.len() != b.len() {
|
||||
return Err(BellandeArchError::DimensionMismatch(format!(
|
||||
"Cannot subtract vectors with different dimensions: {} and {}",
|
||||
a.len(),
|
||||
b.len()
|
||||
)));
|
||||
}
|
||||
|
||||
Ok(a.iter().zip(b.iter()).map(|(x, y)| x - y).collect())
|
||||
}
|
||||
|
||||
/// Calculates the dot product of two vectors
|
||||
pub fn vector_dot_product(a: &[f64], b: &[f64]) -> Result<f64, BellandeArchError> {
|
||||
if a.len() != b.len() {
|
||||
return Err(BellandeArchError::DimensionMismatch(format!(
|
||||
"Cannot calculate dot product of vectors with different dimensions: {} and {}",
|
||||
a.len(),
|
||||
b.len()
|
||||
)));
|
||||
}
|
||||
|
||||
Ok(a.iter().zip(b.iter()).map(|(x, y)| x * y).sum())
|
||||
}
|
||||
|
||||
/// Calculates the Euclidean length of a vector
|
||||
pub fn vector_length(v: &[f64]) -> Result<f64, BellandeArchError> {
|
||||
Ok(v.iter().map(|x| x * x).sum::<f64>().sqrt())
|
||||
}
|
||||
|
||||
/// Calculates the Euclidean distance between two points
|
||||
pub fn euclidean_distance(point1: &[f64], point2: &[f64]) -> Result<f64, BellandeArchError> {
|
||||
if point1.len() != point2.len() {
|
||||
return Err(BellandeArchError::DimensionMismatch(format!(
|
||||
"Points have different dimensions: {} and {}",
|
||||
point1.len(),
|
||||
point2.len()
|
||||
)));
|
||||
}
|
||||
|
||||
let sum_squared: f64 = point1
|
||||
.iter()
|
||||
.zip(point2.iter())
|
||||
.map(|(a, b)| (a - b).powi(2))
|
||||
.sum();
|
||||
|
||||
Ok(sum_squared.sqrt())
|
||||
}
|
||||
|
||||
/// Validates if a point is within the bounds of a given space
|
||||
pub fn is_point_valid(point: &[f64], min_bounds: &[f64], max_bounds: &[f64]) -> bool {
|
||||
if point.len() != min_bounds.len() || point.len() != max_bounds.len() {
|
||||
return false;
|
||||
}
|
||||
|
||||
point
|
||||
.iter()
|
||||
.zip(min_bounds.iter().zip(max_bounds.iter()))
|
||||
.all(|(p, (min, max))| p >= min && p <= max)
|
||||
}
|
||||
|
@@ -17,6 +17,7 @@ use crate::config::config::Config;
|
||||
use crate::data::data::DataChunk;
|
||||
use crate::encryption::encryption::PublicKey;
|
||||
use crate::error::error::BellandeMeshError;
|
||||
use crate::mesh::architecture;
|
||||
pub use crate::metrics::metrics::MetricsManager;
|
||||
use crate::node::node::{Message, Node, NodeId};
|
||||
use hyper::server::conn::AddrStream;
|
||||
|
Reference in New Issue
Block a user