use super::{CorticalAreaDimensions, CorticalAreaType, CorticalID};
use crate::genomic::descriptors::GenomeCoordinate3D;
use crate::FeagiDataError;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CorticalArea {
pub cortical_id: CorticalID,
pub cortical_idx: u32,
pub name: String,
pub dimensions: CorticalAreaDimensions,
pub position: GenomeCoordinate3D,
pub cortical_type: CorticalAreaType,
#[serde(default)]
pub properties: HashMap<String, serde_json::Value>,
}
impl CorticalArea {
pub fn new(
cortical_id: CorticalID,
cortical_idx: u32,
name: String,
dimensions: CorticalAreaDimensions,
position: GenomeCoordinate3D,
cortical_type: CorticalAreaType,
) -> Result<Self, FeagiDataError> {
if name.trim().is_empty() {
return Err(FeagiDataError::BadParameters(
"name cannot be empty".to_string(),
));
}
Ok(Self {
cortical_id,
cortical_idx,
name,
dimensions,
position,
cortical_type,
properties: HashMap::new(),
})
}
pub fn get_property(&self, key: &str) -> Option<&serde_json::Value> {
self.properties.get(key)
}
pub fn total_voxels(&self) -> u32 {
self.dimensions.total_voxels()
}
}