<commit_before>use glm;
use moho::errors::*;
use moho::renderer::Renderer;
use moho::resource_manager::{ResourceManager, Texture};
use sdl2::rect;

pub enum Drawable<'a> {
    Asset(&'a Asset),
    Rectangles(&'a [rect::Rect]),
}

impl<'a> Drawable<'a> {
    pub fn draw<R: Renderer>(&self, renderer: &mut ResourceManager<R>) -> Result<()> {
        match *self {
            Drawable::Asset(ref a) => a.draw(renderer),
            Drawable::Rectangles(ref r) => renderer.fill_rects(r),
        }
    }
}

#[derive(Clone)]
pub struct Asset {
    texture_id: usize,
    pub dst_rect: glm::IVec4,
    pub src_rect: Option<glm::DVec4>,
}

impl Asset {
    pub fn from_texture(texture: &Texture) -> Asset {
        let rect = glm::ivec4(0, 0, texture.dims.x as i32, texture.dims.y as i32);
        Asset::new(texture.id, rect)
    }

    pub fn new(texture_id: usize, dst_rect: glm::IVec4) -> Asset {
        Asset {
            texture_id: texture_id,
            dst_rect: dst_rect,
            src_rect: None,
        }
    }

    pub fn set_center(&mut self, center: glm::IVec2) {
        self.dst_rect.x = center.x - self.dst_rect.z / 2;
        self.dst_rect.y = center.y - self.dst_rect.w / 2;
    }

    pub fn center(&self) -> glm::IVec2 {
        glm::ivec2(self.dst_rect.x + self.dst_rect.z / 2,
                   self.dst_rect.y + self.dst_rect.w / 2)
    }

    pub fn draw<R>(&self, renderer: &mut ResourceManager<R>) -> Result<()>
        where R: Renderer
    {
        let max = renderer.output_size()?;
        renderer.draw(self.texture_id,
                      Some(self.dst_rect),
                      self.src_rect,
                      Some(max))
    }
}
<commit_msg>move draw to drawable instead of asset<commit_after>use glm;
use moho::errors::*;
use moho::renderer::Renderer;
use moho::resource_manager::{ResourceManager, Texture};
use sdl2::rect;

pub enum Drawable<'a> {
    Asset(&'a Asset),
    Rectangles(&'a [rect::Rect]),
}

impl<'a> Drawable<'a> {
    pub fn draw<R: Renderer>(&self, renderer: &mut ResourceManager<R>) -> Result<()> {
        match *self {
            Drawable::Asset(ref a) => {
                let max = Some(renderer.output_size()?);
                renderer.draw(a.texture_id, Some(a.dst_rect), a.src_rect, max)
            }
            Drawable::Rectangles(ref r) => renderer.fill_rects(r),
        }
    }
}

#[derive(Clone)]
pub struct Asset {
    pub texture_id: usize,
    pub dst_rect: glm::IVec4,
    pub src_rect: Option<glm::DVec4>,
}

impl Asset {
    pub fn from_texture(texture: &Texture) -> Asset {
        let rect = glm::ivec4(0, 0, texture.dims.x as i32, texture.dims.y as i32);
        Asset::new(texture.id, rect)
    }

    pub fn new(texture_id: usize, dst_rect: glm::IVec4) -> Asset {
        Asset {
            texture_id: texture_id,
            dst_rect: dst_rect,
            src_rect: None,
        }
    }

    pub fn set_center(&mut self, center: glm::IVec2) {
        self.dst_rect.x = center.x - self.dst_rect.z / 2;
        self.dst_rect.y = center.y - self.dst_rect.w / 2;
    }

    pub fn center(&self) -> glm::IVec2 {
        glm::ivec2(self.dst_rect.x + self.dst_rect.z / 2,
                   self.dst_rect.y + self.dst_rect.w / 2)
    }
}

{'fraction_non_alphanumeric': 0.14996907854050712, 'fraction_numerical': 0.011131725417439703, 'mean_word_length': 2.2709807886754296, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 33, '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': '6803620', 'n_tokens_mistral': 1202, 'n_tokens_neox': 1178, 'n_words': 240}