Skip to content
Snippets Groups Projects
Select Git revision
  • ccbc83d043319244c29cfad3b8265f1ec7f7657d
  • main default protected
  • feature/export-filtering
  • feature/clear-schedule-button
  • fix/responsive-cols-in-polls
  • feature/preference-polling-form
  • feature/json-export-via-rest-framework
  • feature/json-schedule-import-tests
  • fix/add-room-import-only-once
  • ak-import
  • renovate/django-simple-history-3.x
  • renovate/django-debug-toolbar-4.x
  • renovate/django-5.x
  • renovate/mysqlclient-2.x
14 results

manage.py

Blame
  • Forked from KIF / AKPlanning
    Source project has a limited visibility.
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    types.rs 1.21 KiB
    use std::{fs::read_to_string, path::Path};
    
    use regex::Regex;
    
    #[derive(Debug)]
    pub struct SensorData {
        pub position: Point,
        pub beacon: Point,
    }
    
    impl SensorData {
        pub fn new(position: Point, beacon: Point) -> Self {
            Self { position, beacon }
        }
    }
    
    #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
    pub struct Point {
        pub x: i32,
        pub y: i32,
    }
    
    impl Point {
        pub fn new(x: i32, y: i32) -> Self {
            Self { x, y }
        }
    
        pub fn distance(&self, other: Point) -> u32 {
            self.x.abs_diff(other.x) + self.y.abs_diff(other.y)
        }
    }
    
    pub fn parse_input(path: impl AsRef<Path>) -> Vec<SensorData> {
        let data = read_to_string(path).unwrap();
    
        let mut sensors = Vec::new();
        let reg =
            Regex::new(r"x=(?P<s_x>-?\d+), y=(?P<s_y>-?\d+).*x=(?P<b_x>-?\d+), y=(?P<b_y>-?\d+)").unwrap();
        for cap in reg.captures_iter(&data) {
            sensors.push(SensorData::new(
                Point::new(
                    cap["s_x"].parse::<i32>().unwrap(),
                    cap["s_y"].parse::<i32>().unwrap(),
                ),
                Point::new(
                    cap["b_x"].parse::<i32>().unwrap(),
                    cap["b_y"].parse::<i32>().unwrap(),
                ),
            ));
        }
    
        sensors
    }