<commit_before>extern crate image;
extern crate nalgebra;

use std::f64::consts::FRAC_PI_2;
use std::io::File;
use std::num::FloatMath;
use image::{GenericImage, Pixel};
use nalgebra::{DVec, Mat2, Pnt2, Rot2, Vec1, Vec2, Vec3};

fn draw(v: &DVec<f64>, path: &Path) {
    let width = v.len() as u32;
    let height = 128u32;
    let white = Pixel::from_channels(255, 255, 255, 255);
    let buffer = image::ImageBuffer::from_fn(width, height, |_, _| white);
    let mut img = image::DynamicImage::ImageRgba8(buffer);
    let red = Pixel::from_channels(255, 0, 0, 255);
    for i in range(0u32, width) {
        let half = (height / 2) as f64;
        let y = half * (1.0 + v[i as uint]);
        let y = nalgebra::clamp(y as u32, 0u32, height - 1);
        img.put_pixel(i, y, red);
    }
    let out = File::create(path).unwrap();
    let _ = img.save(out, image::PNG);
}

fn main() {
    println!("24 days of Rust - nalgebra (day 14)");
    let v = Vec2::new(0.0f64, 1.0);
    // 90 degrees clockwise
    //  0, 1
    // -1, 0
    let rot = Mat2::new(0.0f64, -1.0, 1.0, 0.0);
    println!("{}", rot * v);
    let angle = FRAC_PI_2;
    let rot = Rot2::new(Vec1::new(angle));
    println!("{}", rot * v);
    let point = Pnt2::new(4.0f64, 4.0);
    println!("Translate from {} to {}", point, nalgebra::translate(&v, &point));
<commit_msg>Reverse plot.<commit_after>extern crate image;
extern crate nalgebra;

use std::f64::consts::FRAC_PI_2;
use std::io::File;
use std::num::FloatMath;
use image::{GenericImage, Pixel};
use nalgebra::{DVec, Mat2, Pnt2, Rot2, Vec1, Vec2, Vec3};

fn draw(v: &DVec<f64>, path: &Path) {
    let width = v.len() as u32;
    let height = 128u32;
    let white = Pixel::from_channels(255, 255, 255, 255);
    let buffer = image::ImageBuffer::from_fn(width, height, |_, _| white);
    let mut img = image::DynamicImage::ImageRgba8(buffer);
    let red = Pixel::from_channels(255, 0, 0, 255);
    for i in range(0u32, width) {
        let half = (height / 2) as f64;
        let y = half * (1.0 + v[i as uint]);
        let y = nalgebra::clamp(y as u32, 1u32, height);
        img.put_pixel(i, height - y, red);
    }
    let out = File::create(path).unwrap();
    let _ = img.save(out, image::PNG);
}

fn main() {
    println!("24 days of Rust - nalgebra (day 14)");
    let v = Vec2::new(0.0f64, 1.0);
    // 90 degrees clockwise
    //  0, 1
    // -1, 0
    let rot = Mat2::new(0.0f64, -1.0, 1.0, 0.0);
    println!("{}", rot * v);
    let angle = FRAC_PI_2;
    let rot = Rot2::new(Vec1::new(angle));
    println!("{}", rot * v);
    let point = Pnt2::new(4.0f64, 4.0);
    println!("Translate from {} to {}", point, nalgebra::translate(&v, &point));

{'fraction_non_alphanumeric': 0.1876165609847072, 'fraction_numerical': 0.06751212234240955, 'mean_word_length': 3.119815668202765, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '2039486', 'n_tokens_mistral': 1153, 'n_tokens_neox': 1048, 'n_words': 281}