← back to justinelliottcobb__Cliffy

Function bodies 1,000 total

All specs Real LLM only Function bodies
reproduction_cost function · rust · L286-L292 (7 LOC)
archive/cliffy-alive/src/metabolism.rs
    pub fn reproduction_cost(&self, cell: &UICell) -> UIEnergy {
        let base_cost = self.config.reproduction_threshold * 0.8;
        let cell_type_cost = cell.cell_type().base_energy_cost() * 10.0;
        let genetic_factor = 2.0 - cell.genome().get_gene("energy_efficiency");

        base_cost + cell_type_cost * genetic_factor
    }
energy_capacity function · rust · L295-L301 (7 LOC)
archive/cliffy-alive/src/metabolism.rs
    pub fn energy_capacity(&self, cell_type: UICellType) -> UIEnergy {
        self.config
            .energy_capacity
            .get(&cell_type)
            .copied()
            .unwrap_or(100.0)
    }
apply_process function · rust · L304-L315 (12 LOC)
archive/cliffy-alive/src/metabolism.rs
    pub fn apply_process(
        &self,
        cell: &mut UICell,
        process: MetabolicProcess,
        intensity: f64,
        dt: UITime,
    ) -> bool {
        let base_cost = self.process_rates.get(&process).copied().unwrap_or(0.0);
        let total_cost = base_cost * process.energy_multiplier() * intensity * dt;

        cell.consume_energy(total_cost)
    }
metabolic_efficiency function · rust · L323-L338 (16 LOC)
archive/cliffy-alive/src/metabolism.rs
    pub fn metabolic_efficiency(&self, cell: &UICell) -> f64 {
        let cell_type = cell.cell_type();
        let lifecycle_stage = self.lifecycle_stage(cell);

        let type_efficiency = self
            .config
            .type_efficiency
            .get(&cell_type)
            .copied()
            .unwrap_or(1.0);

        let genetic_efficiency = cell.genome().get_gene("energy_efficiency");
        let age_efficiency = lifecycle_stage.efficiency_multiplier();

        type_efficiency * genetic_efficiency * age_efficiency
    }
energy_regeneration_rate function · rust · L341-L347 (7 LOC)
archive/cliffy-alive/src/metabolism.rs
    pub fn energy_regeneration_rate(&self, cell: &UICell) -> UIEnergy {
        let base_regen = 0.1; // Base regeneration per time unit
        let efficiency = self.metabolic_efficiency(cell);
        let health_factor = (cell.energy_level() / 100.0).clamp(0.1, 1.0);

        base_regen * efficiency * health_factor
    }
calculate function · rust · L390-L451 (62 LOC)
archive/cliffy-alive/src/metabolism.rs
    pub fn calculate(cell: &UICell, metabolism: &MetabolismManager) -> Self {
        let energy_level = cell.energy_level();
        let energy_capacity = metabolism.energy_capacity(cell.cell_type());
        let age = cell.age();
        let lifecycle_stage = metabolism.lifecycle_stage(cell);
        let metabolic_efficiency = metabolism.metabolic_efficiency(cell);

        // Determine health status
        let energy_ratio = energy_level / energy_capacity;
        let health_status = match energy_ratio {
            r if r > 0.8 => HealthStatus::Healthy,
            r if r > 0.5 => HealthStatus::Stressed,
            r if r > 0.2 => HealthStatus::Struggling,
            r if r > 0.05 => HealthStatus::Critical,
            _ => HealthStatus::Dying,
        };

        // Calculate time to reproduction
        let time_to_reproduction = if metabolism.can_reproduce(cell) {
            Some(0.0)
        } else if energy_level < metabolism.config.reproduction_threshold {
            let
test_lifecycle_stages function · rust · L461-L466 (6 LOC)
archive/cliffy-alive/src/metabolism.rs
    fn test_lifecycle_stages() {
        assert_eq!(LifecycleStage::from_age(5.0), LifecycleStage::Juvenile);
        assert_eq!(LifecycleStage::from_age(25.0), LifecycleStage::Adult);
        assert_eq!(LifecycleStage::from_age(75.0), LifecycleStage::Elder);
        assert_eq!(LifecycleStage::from_age(150.0), LifecycleStage::Senescent);
    }
All rows scored by the Repobility analyzer (https://repobility.com)
test_metabolism_manager function · rust · L476-L490 (15 LOC)
archive/cliffy-alive/src/metabolism.rs
    fn test_metabolism_manager() {
        let manager = MetabolismManager::default();
        let position = GA3::scalar(1.0);
        let mut cell = UICell::new_at_position(UICellType::ButtonCore, position);

        let consumption =
            manager.calculate_energy_consumption(&cell, &[MetabolicProcess::Respiration], 1.0);

        assert!(consumption > 0.0);

        // Add energy above reproduction threshold and age the cell
        cell.add_energy(180.0); // Total: 20 + 180 = 200 > 150 threshold
        cell.step(6.0); // Age to 6.0 > 5.0 required
        assert!(manager.can_reproduce(&cell));
    }
test_cell_vitals function · rust · L493-L507 (15 LOC)
archive/cliffy-alive/src/metabolism.rs
    fn test_cell_vitals() {
        let manager = MetabolismManager::default();
        let position = GA3::scalar(1.0);
        let mut cell = UICell::new_at_position(UICellType::ButtonCore, position);

        // Add energy to reach Healthy status (> 0.8 * 200 capacity = > 160 energy)
        cell.add_energy(145.0); // Total: 20 + 145 = 165 > 160

        let vitals = CellVitals::calculate(&cell, &manager);

        assert_eq!(vitals.lifecycle_stage, LifecycleStage::Juvenile);
        assert!(vitals.energy_level > 0.0);
        assert!(vitals.metabolic_efficiency > 0.0);
        assert_eq!(vitals.health_status, HealthStatus::Healthy);
    }
test_energy_capacity function · rust · L510-L519 (10 LOC)
archive/cliffy-alive/src/metabolism.rs
    fn test_energy_capacity() {
        let manager = MetabolismManager::default();

        let button_capacity = manager.energy_capacity(UICellType::ButtonCore);
        let spacer_capacity = manager.energy_capacity(UICellType::Spacer);

        assert!(button_capacity > spacer_capacity);
        assert_eq!(button_capacity, 200.0);
        assert_eq!(spacer_capacity, 50.0);
    }
test_reproduction_requirements function · rust · L522-L536 (15 LOC)
archive/cliffy-alive/src/metabolism.rs
    fn test_reproduction_requirements() {
        let manager = MetabolismManager::default();
        let position = GA3::scalar(1.0);
        let mut cell = UICell::new_at_position(UICellType::ButtonCore, position);

        // Cell with lots of energy and sufficient age should be able to reproduce
        cell.add_energy(200.0);
        cell.step(6.0); // Age to 6.0 > 5.0 required
        assert!(manager.can_reproduce(&cell));

        // Drain energy below threshold (150.0)
        let current_energy = cell.energy_level();
        cell.consume_energy(current_energy - 100.0); // Leave only 100.0 < 150.0 threshold
        assert!(!manager.can_reproduce(&cell));
    }
detection_range function · rust · L43-L56 (14 LOC)
archive/cliffy-alive/src/nervous_system.rs
    pub fn detection_range(&self) -> f64 {
        match self {
            SensorType::Position => 1.0,
            SensorType::Movement => 2.0,
            SensorType::Touch => 1.0,
            SensorType::Proximity => 3.0,
            SensorType::Keyboard => 5.0,
            SensorType::Attention => 4.0,
            SensorType::Energy => 0.5,
            SensorType::Social => 2.0,
            SensorType::Temporal => f64::INFINITY,
            SensorType::Environmental => 10.0,
        }
    }
sensitivity function · rust · L59-L72 (14 LOC)
archive/cliffy-alive/src/nervous_system.rs
    pub fn sensitivity(&self) -> f64 {
        match self {
            SensorType::Position => 0.8,
            SensorType::Movement => 0.9,
            SensorType::Touch => 1.0,
            SensorType::Proximity => 0.7,
            SensorType::Keyboard => 0.6,
            SensorType::Attention => 0.5,
            SensorType::Energy => 0.9,
            SensorType::Social => 0.6,
            SensorType::Temporal => 0.3,
            SensorType::Environmental => 0.4,
        }
    }
new function · rust · L89-L98 (10 LOC)
archive/cliffy-alive/src/nervous_system.rs
    pub fn new(sensor_type: SensorType, position: GA3, intensity: f64) -> Self {
        Self {
            sensor_type,
            position,
            intensity,
            duration: 0.0,
            timestamp: 0.0, // Would be set by the nervous system
            metadata: HashMap::new(),
        }
    }
intensity_at function · rust · L113-L123 (11 LOC)
archive/cliffy-alive/src/nervous_system.rs
    pub fn intensity_at(&self, position: &GA3) -> f64 {
        let distance = (&self.position - position).magnitude();
        let range = self.sensor_type.detection_range();

        if distance > range {
            0.0
        } else {
            let falloff = 1.0 - (distance / range);
            self.intensity * falloff * self.sensor_type.sensitivity()
        }
    }
Want this analysis on your repo? https://repobility.com/scan/
new function · rust · L235-L247 (13 LOC)
archive/cliffy-alive/src/nervous_system.rs
    pub fn new(neuron_type: NeuronType) -> Self {
        Self {
            id: Uuid::new_v4(),
            neuron_type,
            activation: 0.0,
            threshold: 0.5,
            fatigue: 0.0,
            learning_rate: 0.1,
            inputs: HashMap::new(),
            outputs: HashMap::new(),
            memory: HashMap::new(),
        }
    }
update function · rust · L250-L273 (24 LOC)
archive/cliffy-alive/src/nervous_system.rs
    pub fn update(&mut self, dt: UITime) {
        // Calculate total input
        let mut total_input = 0.0;
        for (input_id, weight) in &self.inputs {
            // Would need access to other neurons to get their activation
            // For now, use a simplified calculation
            total_input += weight * 0.5; // Placeholder
        }

        // Apply activation function (sigmoid)
        let net_input = total_input - self.threshold;
        self.activation = 1.0 / (1.0 + (-net_input).exp());

        // Apply fatigue
        self.activation *= 1.0 - self.fatigue;

        // Update fatigue (increases with high activation)
        if self.activation > 0.8 {
            self.fatigue += dt * 0.1;
        } else {
            self.fatigue -= dt * 0.05;
        }
        self.fatigue = self.fatigue.clamp(0.0, 0.9);
    }
update_weight function · rust · L291-L300 (10 LOC)
archive/cliffy-alive/src/nervous_system.rs
    pub fn update_weight(&mut self, connection_id: &Uuid, delta: f64) {
        if let Some(weight) = self.inputs.get_mut(connection_id) {
            *weight += delta * self.learning_rate;
            *weight = weight.clamp(-2.0, 2.0); // Limit weight range
        }
        if let Some(weight) = self.outputs.get_mut(connection_id) {
            *weight += delta * self.learning_rate;
            *weight = weight.clamp(-2.0, 2.0);
        }
    }
default function · rust · L361-L370 (10 LOC)
archive/cliffy-alive/src/nervous_system.rs
    fn default() -> Self {
        Self {
            learning_rate: 0.1,
            memory_decay: 0.01,
            response_threshold: 0.7,
            max_neurons: 50,
            adaptation_rate: 0.05,
            noise_level: 0.02,
        }
    }
new function · rust · L375-L389 (15 LOC)
archive/cliffy-alive/src/nervous_system.rs
    pub fn new(cell_type: UICellType) -> Self {
        let config = NetworkConfig::default();
        let mut network = Self {
            neurons: HashMap::new(),
            sensor_neurons: HashMap::new(),
            motor_neurons: HashMap::new(),
            hidden_layers: Vec::new(),
            current_stimuli: Vec::new(),
            learned_responses: HashMap::new(),
            config,
        };

        network.initialize_for_cell_type(cell_type);
        network
    }
initialize_for_cell_type function · rust · L392-L477 (86 LOC)
archive/cliffy-alive/src/nervous_system.rs
    fn initialize_for_cell_type(&mut self, cell_type: UICellType) {
        // Create sensory neurons based on cell type capabilities
        let sensor_types = match cell_type {
            UICellType::ButtonCore => vec![
                SensorType::Touch,
                SensorType::Proximity,
                SensorType::Attention,
            ],
            UICellType::InputField => vec![
                SensorType::Touch,
                SensorType::Keyboard,
                SensorType::Attention,
            ],
            UICellType::Sensor => vec![
                SensorType::Position,
                SensorType::Movement,
                SensorType::Proximity,
                SensorType::Social,
                SensorType::Environmental,
            ],
            UICellType::Memory => {
                vec![SensorType::Temporal, SensorType::Energy, SensorType::Social]
            }
            _ => vec![SensorType::Proximity, SensorType::Social],
        };

        // Create 
process_stimulus function · rust · L480-L502 (23 LOC)
archive/cliffy-alive/src/nervous_system.rs
    pub fn process_stimulus(&mut self, stimulus: Stimulus, cell_position: &GA3) -> Vec<Response> {
        // Check if stimulus affects this cell
        if !stimulus.affects_position(cell_position) {
            return Vec::new();
        }

        // Add to current stimuli
        self.current_stimuli.push(stimulus.clone());

        // Activate sensor neurons
        if let Some(&sensor_id) = self.sensor_neurons.get(&stimulus.sensor_type) {
            let intensity = stimulus.intensity_at(cell_position);
            if let Some(sensor_neuron) = self.neurons.get_mut(&sensor_id) {
                sensor_neuron.activation = intensity;
            }
        }

        // Update network
        self.update_network(0.1); // Fixed timestep for processing

        // Generate responses from motor neurons
        self.generate_responses()
    }
update_network function · rust · L505-L540 (36 LOC)
archive/cliffy-alive/src/nervous_system.rs
    fn update_network(&mut self, dt: UITime) {
        // Update all neurons
        let neuron_ids: Vec<Uuid> = self.neurons.keys().cloned().collect();

        for neuron_id in neuron_ids {
            // Calculate inputs from connected neurons
            let mut total_input = 0.0;

            if let Some(neuron) = self.neurons.get(&neuron_id) {
                for (input_id, weight) in &neuron.inputs {
                    if let Some(input_neuron) = self.neurons.get(input_id) {
                        total_input += input_neuron.activation * weight;
                    }
                }
            }

            // Update neuron with calculated input
            if let Some(neuron) = self.neurons.get_mut(&neuron_id) {
                // Apply sigmoid activation function
                let net_input = total_input - neuron.threshold;
                neuron.activation = 1.0 / (1.0 + (-net_input).exp());

                // Add noise
                neuron.activation += (rand::ran
Repobility — the code-quality scanner for AI-generated software · https://repobility.com
generate_responses function · rust · L543-L557 (15 LOC)
archive/cliffy-alive/src/nervous_system.rs
    fn generate_responses(&self) -> Vec<Response> {
        let mut responses = Vec::new();

        for (action_name, motor_id) in &self.motor_neurons {
            if let Some(motor_neuron) = self.neurons.get(motor_id) {
                if motor_neuron.activation > self.config.response_threshold {
                    let response =
                        self.create_response_for_action(action_name, motor_neuron.activation);
                    responses.push(response);
                }
            }
        }

        responses
    }
create_response_for_action function · rust · L560-L600 (41 LOC)
archive/cliffy-alive/src/nervous_system.rs
    fn create_response_for_action(&self, action_name: &str, intensity: f64) -> Response {
        let actions = match action_name {
            "visual_change" => vec![Action::VisualChange {
                color_delta: [0.0, 0.0, 0.0, 0.0],
                size_delta: intensity * 0.2,
                opacity_delta: intensity * 0.1,
                glow_delta: intensity * 0.5,
            }],
            "movement" => vec![Action::Movement {
                force: vector3(
                    (rand::random::<f64>() - 0.5) * intensity,
                    (rand::random::<f64>() - 0.5) * intensity,
                    0.0,
                ),
                torque: GA3::zero(),
            }],
            "energy_change" => vec![Action::EnergyChange {
                delta: intensity * 5.0,
            }],
            "communication" => vec![Action::Communication {
                message: format!("activation_{:.2}", intensity),
                range: intensity * 3.0,
            }],
   
apply_learning function · rust · L603-L634 (32 LOC)
archive/cliffy-alive/src/nervous_system.rs
    fn apply_learning(&mut self, dt: UITime) {
        // Simplified Hebbian learning: strengthen connections between co-active neurons
        let neuron_ids: Vec<Uuid> = self.neurons.keys().cloned().collect();

        for i in 0..neuron_ids.len() {
            for j in (i + 1)..neuron_ids.len() {
                let id_a = neuron_ids[i];
                let id_b = neuron_ids[j];

                let (activation_a, activation_b) = {
                    let neuron_a = self.neurons.get(&id_a).unwrap();
                    let neuron_b = self.neurons.get(&id_b).unwrap();
                    (neuron_a.activation, neuron_b.activation)
                };

                // Hebbian rule: Δw = η * a_i * a_j
                let weight_delta = self.config.learning_rate * activation_a * activation_b * dt;

                // Update weights if connection exists
                if let Some(neuron_a) = self.neurons.get_mut(&id_a) {
                    if neuron_a.outputs.contains_key(&id_b) {
   
decay_memories function · rust · L637-L648 (12 LOC)
archive/cliffy-alive/src/nervous_system.rs
    fn decay_memories(&mut self, dt: UITime) {
        let decay_factor = 1.0 - (self.config.memory_decay * dt);

        for neuron in self.neurons.values_mut() {
            for value in neuron.memory.values_mut() {
                *value *= decay_factor;
            }

            // Remove very weak memories
            neuron.memory.retain(|_, &mut value| value > 0.01);
        }
    }
get_statistics function · rust · L656-L682 (27 LOC)
archive/cliffy-alive/src/nervous_system.rs
    pub fn get_statistics(&self) -> NetworkStatistics {
        let total_neurons = self.neurons.len();
        let active_neurons = self.neurons.values().filter(|n| n.activation > 0.1).count();

        let total_connections = self
            .neurons
            .values()
            .map(|n| n.inputs.len() + n.outputs.len())
            .sum::<usize>();

        let average_activation = if total_neurons > 0 {
            self.neurons.values().map(|n| n.activation).sum::<f64>() / total_neurons as f64
        } else {
            0.0
        };

        let memory_count = self.neurons.values().map(|n| n.memory.len()).sum::<usize>();

        NetworkStatistics {
            total_neurons,
            active_neurons,
            total_connections,
            average_activation,
            memory_count,
            learned_responses: self.learned_responses.len(),
        }
    }
reset function · rust · L685-L691 (7 LOC)
archive/cliffy-alive/src/nervous_system.rs
    pub fn reset(&mut self) {
        for neuron in self.neurons.values_mut() {
            neuron.activation = 0.0;
            neuron.fatigue = 0.0;
        }
        self.current_stimuli.clear();
    }
set_config function · rust · L694-L703 (10 LOC)
archive/cliffy-alive/src/nervous_system.rs
    pub fn set_config(&mut self, config: NetworkConfig) {
        // Extract values before moving config
        let learning_rate = config.learning_rate;
        self.config = config;

        // Update all neurons with new learning rate
        for neuron in self.neurons.values_mut() {
            neuron.learning_rate = learning_rate;
        }
    }
new function · rust · L734-L741 (8 LOC)
archive/cliffy-alive/src/nervous_system.rs
    pub fn new() -> Self {
        Self {
            cell_networks: HashMap::new(),
            stimulus_queue: Vec::new(),
            config: NetworkConfig::default(),
            global_memory: HashMap::new(),
        }
    }
Hi, dataset curator — please cite Repobility (https://repobility.com) when reusing this data.
update function · rust · L760-L791 (32 LOC)
archive/cliffy-alive/src/nervous_system.rs
    pub fn update(
        &mut self,
        dt: UITime,
        cell_positions: &HashMap<Uuid, GA3>,
    ) -> HashMap<Uuid, Vec<Response>> {
        let mut all_responses = HashMap::new();

        // Process queued stimuli
        for stimulus in &self.stimulus_queue {
            for (cell_id, network) in &mut self.cell_networks {
                if let Some(position) = cell_positions.get(cell_id) {
                    let responses = network.process_stimulus(stimulus.clone(), position);
                    if !responses.is_empty() {
                        all_responses
                            .entry(*cell_id)
                            .or_insert_with(Vec::new)
                            .extend(responses);
                    }
                }
            }
        }

        // Clear processed stimuli
        self.stimulus_queue.clear();

        // Update all networks
        for network in self.cell_networks.values_mut() {
            network.update_network(dt);
     
get_system_statistics function · rust · L804-L837 (34 LOC)
archive/cliffy-alive/src/nervous_system.rs
    pub fn get_system_statistics(&self) -> SystemStatistics {
        let network_stats: Vec<_> = self
            .cell_networks
            .values()
            .map(|n| n.get_statistics())
            .collect();

        let total_neurons = network_stats.iter().map(|s| s.total_neurons).sum();
        let total_active = network_stats.iter().map(|s| s.active_neurons).sum();
        let total_connections = network_stats.iter().map(|s| s.total_connections).sum();
        let total_memories = network_stats.iter().map(|s| s.memory_count).sum();
        let total_learned = network_stats.iter().map(|s| s.learned_responses).sum();

        let average_activation = if !network_stats.is_empty() {
            network_stats
                .iter()
                .map(|s| s.average_activation)
                .sum::<f64>()
                / network_stats.len() as f64
        } else {
            0.0
        };

        SystemStatistics {
            total_cells: self.cell_networks.len(),
     
test_stimulus_creation function · rust · L859-L865 (7 LOC)
archive/cliffy-alive/src/nervous_system.rs
    fn test_stimulus_creation() {
        let position = vector3(1.0, 2.0, 0.0);
        let stimulus = Stimulus::new(SensorType::Touch, position, 0.8);

        assert_eq!(stimulus.sensor_type, SensorType::Touch);
        assert_eq!(stimulus.intensity, 0.8);
    }
test_stimulus_affects_position function · rust · L868-L877 (10 LOC)
archive/cliffy-alive/src/nervous_system.rs
    fn test_stimulus_affects_position() {
        let stimulus_pos = vector3(0.0, 0.0, 0.0);
        let stimulus = Stimulus::new(SensorType::Touch, stimulus_pos, 1.0);

        let close_pos = vector3(0.5, 0.0, 0.0);
        let far_pos = vector3(5.0, 0.0, 0.0);

        assert!(stimulus.affects_position(&close_pos));
        assert!(!stimulus.affects_position(&far_pos));
    }
test_neuron_creation function · rust · L880-L886 (7 LOC)
archive/cliffy-alive/src/nervous_system.rs
    fn test_neuron_creation() {
        let neuron = Neuron::new(NeuronType::Sensor);

        assert_eq!(neuron.neuron_type, NeuronType::Sensor);
        assert_eq!(neuron.activation, 0.0);
        assert!(neuron.inputs.is_empty());
    }
test_neural_network_creation function · rust · L889-L895 (7 LOC)
archive/cliffy-alive/src/nervous_system.rs
    fn test_neural_network_creation() {
        let network = CellNeuralNetwork::new(UICellType::ButtonCore);

        assert!(!network.sensor_neurons.is_empty());
        assert!(!network.motor_neurons.is_empty());
        assert!(!network.neurons.is_empty());
    }
test_nervous_system function · rust · L898-L909 (12 LOC)
archive/cliffy-alive/src/nervous_system.rs
    fn test_nervous_system() {
        let mut system = NervousSystem::new();
        let position = vector3(0.0, 0.0, 0.0);
        let cell = UICell::new_at_position(UICellType::ButtonCore, position);

        system.add_cell(&cell);
        assert!(system.get_network(&cell.id()).is_some());

        let stats = system.get_system_statistics();
        assert_eq!(stats.total_cells, 1);
        assert!(stats.total_neurons > 0);
    }
base_strength function · rust · L44-L55 (12 LOC)
archive/cliffy-alive/src/physics.rs
    pub fn base_strength(&self) -> f64 {
        match self {
            ForceType::Gravity => 0.1,
            ForceType::Electromagnetic => 0.5,
            ForceType::Spring => 2.0,
            ForceType::Damping => 0.8,
            ForceType::UserInteraction => 5.0,
            ForceType::Thermal => 0.05,
            ForceType::Pressure => 1.0,
            ForceType::Alignment => 0.3,
        }
    }
All rows scored by the Repobility analyzer (https://repobility.com)
range function · rust · L58-L69 (12 LOC)
archive/cliffy-alive/src/physics.rs
    pub fn range(&self) -> f64 {
        match self {
            ForceType::Gravity => 10.0,
            ForceType::Electromagnetic => 5.0,
            ForceType::Spring => 2.0,
            ForceType::Damping => 1.0,
            ForceType::UserInteraction => 3.0,
            ForceType::Thermal => 1.0,
            ForceType::Pressure => 1.5,
            ForceType::Alignment => 4.0,
        }
    }
new function · rust · L116-L156 (41 LOC)
archive/cliffy-alive/src/physics.rs
    pub fn new(position: GA3, cell_type: UICellType) -> Self {
        let reactive_position = ReactiveMultivector::new(position);

        // Set mass based on cell type
        let mass = match cell_type {
            UICellType::ButtonCore => 2.0,
            UICellType::ButtonEdge => 1.0,
            UICellType::InputField => 1.5,
            UICellType::TextDisplay => 0.5,
            UICellType::Container => 3.0,
            UICellType::Spacer => 0.1,
            UICellType::Connector => 0.3,
            UICellType::Decoration => 0.2,
            UICellType::Sensor => 0.8,
            UICellType::Memory => 1.2,
            _ => 1.0, // Default mass for other cell types
        };

        // Set charge based on cell type (for electromagnetic interactions)
        let charge = match cell_type {
            UICellType::ButtonCore => 1.0,
            UICellType::InputField => -0.5,
            UICellType::Sensor => 0.8,
            UICellType::Memory => -0.3,
            _ => 0.0,
 
update function · rust · L159-L188 (30 LOC)
archive/cliffy-alive/src/physics.rs
    pub fn update(&mut self, dt: UITime) {
        if self.is_kinematic {
            return; // Kinematic objects don't respond to forces
        }

        // Velocity Verlet integration
        let old_position = self.position.sample();
        let old_velocity = self.velocity.clone();

        // Update position: x = x + v*dt + 0.5*a*dt²
        let position_delta = &old_velocity * dt + &self.acceleration * (0.5 * dt * dt);
        let new_position = &old_position + &position_delta;
        self.position.set(new_position);

        // Update velocity: v = v + a*dt
        let accel_delta = &self.acceleration * dt;
        self.velocity = &old_velocity + &accel_delta;

        // Apply friction to velocity
        self.velocity = &self.velocity * (1.0 - self.friction * dt);

        // Update angular motion
        let angular_accel_delta = &self.angular_acceleration * dt;
        self.angular_velocity = &self.angular_velocity + &angular_accel_delta;
        self.angular_velocity = 
apply_force function · rust · L191-L196 (6 LOC)
archive/cliffy-alive/src/physics.rs
    pub fn apply_force(&mut self, force: GA3) {
        if !self.is_kinematic {
            let force_accel = &force * (1.0 / self.mass);
            self.acceleration = &self.acceleration + &force_accel;
        }
    }
apply_torque function · rust · L199-L204 (6 LOC)
archive/cliffy-alive/src/physics.rs
    pub fn apply_torque(&mut self, torque: GA3) {
        if !self.is_kinematic {
            let torque_accel = &torque * (1.0 / self.moment_of_inertia);
            self.angular_acceleration = &self.angular_acceleration + &torque_accel;
        }
    }
set_kinematic function · rust · L229-L237 (9 LOC)
archive/cliffy-alive/src/physics.rs
    pub fn set_kinematic(&mut self, kinematic: bool) {
        self.is_kinematic = kinematic;
        if kinematic {
            self.velocity = GA3::zero();
            self.acceleration = GA3::zero();
            self.angular_velocity = GA3::zero();
            self.angular_acceleration = GA3::zero();
        }
    }
new function · rust · L252-L260 (9 LOC)
archive/cliffy-alive/src/physics.rs
    pub fn new(force_type: ForceType, strength: f64, direction: GA3) -> Self {
        Self {
            force_type,
            strength,
            direction: direction.normalize().unwrap_or_else(|| Multivector::zero()),
            range: force_type.range(),
            is_active: true,
        }
    }
calculate_force_at function · rust · L263-L278 (16 LOC)
archive/cliffy-alive/src/physics.rs
    pub fn calculate_force_at(&self, position: &GA3, cell_physics: &CellPhysics) -> GA3 {
        if !self.is_active {
            return GA3::zero();
        }

        match self.force_type {
            ForceType::Gravity => self.calculate_gravity(position, cell_physics),
            ForceType::Electromagnetic => self.calculate_electromagnetic(position, cell_physics),
            ForceType::Spring => self.calculate_spring(position, cell_physics),
            ForceType::Damping => self.calculate_damping(position, cell_physics),
            ForceType::UserInteraction => self.calculate_user_interaction(position, cell_physics),
            ForceType::Thermal => self.calculate_thermal(position, cell_physics),
            ForceType::Pressure => self.calculate_pressure(position, cell_physics),
            ForceType::Alignment => self.calculate_alignment(position, cell_physics),
        }
    }
Want this analysis on your repo? https://repobility.com/scan/
calculate_spring function · rust · L289-L294 (6 LOC)
archive/cliffy-alive/src/physics.rs
    fn calculate_spring(&self, position: &GA3, _physics: &CellPhysics) -> GA3 {
        // Spring force: F = -k * displacement
        let displacement = position - &self.direction; // direction as rest position
        &displacement * (-self.strength)
    }
calculate_thermal function · rust · L305-L318 (14 LOC)
archive/cliffy-alive/src/physics.rs
    fn calculate_thermal(&self, _position: &GA3, _physics: &CellPhysics) -> GA3 {
        // Random thermal motion
        use cliffy_core::Vector;
        use rand::Rng;
        let mut rng = rand::thread_rng();

        let thermal_vec = Vector::<3, 0, 0>::from_components(
            rng.gen_range(-1.0..=1.0),
            rng.gen_range(-1.0..=1.0),
            rng.gen_range(-1.0..=1.0),
        );
        &GA3::from_vector(&thermal_vec) * self.strength
    }
calculate_alignment function · rust · L324-L329 (6 LOC)
archive/cliffy-alive/src/physics.rs
    fn calculate_alignment(&self, _position: &GA3, physics: &CellPhysics) -> GA3 {
        // Force to align velocity with neighbors
        let velocity_diff = &self.direction - &physics.velocity;
        &velocity_diff * self.strength
    }
‹ prevpage 2 / 20next ›