<commit_before>use util::units::{AsTuple, Direction};

use std::ops::Add;

#[derive(Copy, Debug, PartialEq)]
pub struct Point {
    pub x: i32,
    pub y: i32
}

impl Point {

    pub fn new(x: i32, y: i32) -> Point {
        Point { x: x, y: y }
    }

    pub fn zero() -> Point {
        Point { x: 0, y: 0 }
    }

    pub fn move_dir(&self, dir: Direction) -> Point {
        *self + dir.as_tuple()
    }

}

impl Add for Point {
    type Output = Point;

    fn add(self, other: Point) -> Point {
        let (ox, oy) = other.as_tuple();
        Point { x: self.x + ox, y: self.y + oy }
    }
}

impl Add<(i32, i32)> for Point {
    type Output = Point;

    fn add(self, other: (i32, i32)) -> Point {
        let (ox, oy) = other;
        Point { x: self.x + ox, y: self.y + oy }
    }
}

impl AsTuple<i32> for Point {
    fn as_tuple(&self) -> (i32, i32) {
        (self.x, self.y)
    }
}<commit_msg>Implement extra methods on Point<commit_after>use util::units::{AsTuple, Direction};

use std::ops::{Add, Sub};

#[derive(Copy, Debug, PartialEq)]
pub struct Point {
    pub x: i32,
    pub y: i32
}

impl Point {

    pub fn new(x: i32, y: i32) -> Point {
        Point { x: x, y: y }
    }

    pub fn zero() -> Point {
        Point { x: 0, y: 0 }
    }

    pub fn up(&self, n: i32)    -> Point { *self - (0, n) }
    pub fn down(&self, n: i32)  -> Point { *self + (0, n) }
    pub fn left(&self, n: i32)  -> Point { *self - (n, 0) }
    pub fn right(&self, n: i32) -> Point { *self + (n, 0) }

    pub fn move_dir(&self, dir: Direction) -> Point {
        *self + dir.as_tuple()
    }

}

impl Add for Point {
    type Output = Point;

    fn add(self, other: Point) -> Point {
        let (ox, oy) = other.as_tuple();
        Point { x: self.x + ox, y: self.y + oy }
    }
}

impl Add<(i32, i32)> for Point {
    type Output = Point;

    fn add(self, other: (i32, i32)) -> Point {
        let (ox, oy) = other;
        Point { x: self.x + ox, y: self.y + oy }
    }
}

impl Sub for Point {
    type Output = Point;

    fn sub(self, other: Point) -> Point {
        let (ox, oy) = other.as_tuple();
        Point { x: self.x - ox, y: self.y - oy }
    }
}

impl Sub<(i32, i32)> for Point {
    type Output = Point;

    fn sub(self, other: (i32, i32)) -> Point {
        let (ox, oy) = other;
        Point { x: self.x - ox, y: self.y - oy }
    }
}

impl AsTuple<i32> for Point {
    fn as_tuple(&self) -> (i32, i32) {
        (self.x, self.y)
    }
}
{'fraction_non_alphanumeric': 0.17186866639643292, 'fraction_numerical': 0.027563842723956223, 'mean_word_length': 1.955688622754491, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6504443', 'n_tokens_mistral': 1018, 'n_tokens_neox': 975, 'n_words': 301}