<commit_before>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use app_units::Au;
use batch::{VertexBuffer, Batch, VertexBufferId, OffsetParams, TileParams};
use device::{TextureId, TextureFilter};
use euclid::{Matrix4D, Point2D, Rect, Size2D};
use fnv::FnvHasher;
use freelist::{FreeListItem, FreeListItemId};
use num_traits::Zero;
use profiler::BackendProfileCounters;
use std::collections::{HashMap, HashSet};
use std::hash::BuildHasherDefault;
use std::ops::{Add, Sub};
use std::path::PathBuf;
use std::sync::Arc;
use texture_cache::BorderType;
use util::{self, RectVaryings};
use webrender_traits::{FontKey, Epoch, ColorF, PipelineId};
use webrender_traits::{ImageFormat, MixBlendMode, NativeFontHandle, DisplayItem, ScrollLayerId};

#[derive(Hash, Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd)]
pub struct DevicePixel(i32);

impl DevicePixel {
    pub fn from_u32(value: u32) -> DevicePixel {
        DevicePixel(value as i32)
    }

    pub fn from_f32(value: f32) -> DevicePixel {
        debug_assert!(value.fract() == 0.0);
        DevicePixel(value as i32)
    }

    pub fn new(value: f32, device_pixel_ratio: f32) -> DevicePixel {
        DevicePixel((value * device_pixel_ratio).round() as i32)
    }

    // TODO(gw): Remove eventually...
    pub fn as_u16(&self) -> u16 {
        let DevicePixel(value) = *self;
        value as u16
    }

    // TODO(gw): Remove eventually...
    pub fn as_u32(&self) -> u32 {
        let DevicePixel(value) = *self;
        value as u32
    }

    // TODO(gw): Remove eventually...
    pub fn as_f32(&self) -> f32 {
        let DevicePixel(value) = *self;
        value as f32
    }
}

impl Add for DevicePixel {
    type Output = DevicePixel;

    #[inline]
    fn add(self, other: DevicePixel) -> DevicePixel {
        DevicePixel(self.0 + other.0)
    }
}

impl Sub for DevicePixel {
    type Output = DevicePixel;

    fn sub(self, other: DevicePixel) -> DevicePixel {
        DevicePixel(self.0 - other.0)
    }
}

impl Zero for DevicePixel {
    fn zero() -> DevicePixel {
        DevicePixel(0)
    }

    fn is_zero(&self) -> bool {
        let DevicePixel(value) = *self;
        value == 0
    }
}

const UV_FLOAT_TO_FIXED: f32 = 65535.0;
const COLOR_FLOAT_TO_FIXED: f32 = 255.0;
pub const ANGLE_FLOAT_TO_FIXED: f32 = 65535.0;

pub const ORTHO_NEAR_PLANE: f32 = -1000000.0;
pub const ORTHO_FAR_PLANE: f32 = 1000000.0;

pub static MAX_RECT: Rect<f32> = Rect {
    origin: Point2D {
        x: -1000.0,
        y: -1000.0,
    },
    size: Size2D {
        width: 10000.0,
        height: 10000.0,
    },<commit_msg>Make `MAX_RECT` much larger.<commit_after>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use app_units::Au;
use batch::{VertexBuffer, Batch, VertexBufferId, OffsetParams, TileParams};
use device::{TextureId, TextureFilter};
use euclid::{Matrix4D, Point2D, Rect, Size2D};
use fnv::FnvHasher;
use freelist::{FreeListItem, FreeListItemId};
use num_traits::Zero;
use profiler::BackendProfileCounters;
use std::collections::{HashMap, HashSet};
use std::f32;
use std::hash::BuildHasherDefault;
use std::ops::{Add, Sub};
use std::path::PathBuf;
use std::sync::Arc;
use texture_cache::BorderType;
use util::{self, RectVaryings};
use webrender_traits::{FontKey, Epoch, ColorF, PipelineId};
use webrender_traits::{ImageFormat, MixBlendMode, NativeFontHandle, DisplayItem, ScrollLayerId};

#[derive(Hash, Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd)]
pub struct DevicePixel(i32);

impl DevicePixel {
    pub fn from_u32(value: u32) -> DevicePixel {
        DevicePixel(value as i32)
    }

    pub fn from_f32(value: f32) -> DevicePixel {
        debug_assert!(value.fract() == 0.0);
        DevicePixel(value as i32)
    }

    pub fn new(value: f32, device_pixel_ratio: f32) -> DevicePixel {
        DevicePixel((value * device_pixel_ratio).round() as i32)
    }

    // TODO(gw): Remove eventually...
    pub fn as_u16(&self) -> u16 {
        let DevicePixel(value) = *self;
        value as u16
    }

    // TODO(gw): Remove eventually...
    pub fn as_u32(&self) -> u32 {
        let DevicePixel(value) = *self;
        value as u32
    }

    // TODO(gw): Remove eventually...
    pub fn as_f32(&self) -> f32 {
        let DevicePixel(value) = *self;
        value as f32
    }
}

impl Add for DevicePixel {
    type Output = DevicePixel;

    #[inline]
    fn add(self, other: DevicePixel) -> DevicePixel {
        DevicePixel(self.0 + other.0)
    }
}

impl Sub for DevicePixel {
    type Output = DevicePixel;

    fn sub(self, other: DevicePixel) -> DevicePixel {
        DevicePixel(self.0 - other.0)
    }
}

impl Zero for DevicePixel {
    fn zero() -> DevicePixel {
        DevicePixel(0)
    }

    fn is_zero(&self) -> bool {
        let DevicePixel(value) = *self;
        value == 0
    }
}

const UV_FLOAT_TO_FIXED: f32 = 65535.0;
const COLOR_FLOAT_TO_FIXED: f32 = 255.0;
pub const ANGLE_FLOAT_TO_FIXED: f32 = 65535.0;

pub const ORTHO_NEAR_PLANE: f32 = -1000000.0;
pub const ORTHO_FAR_PLANE: f32 = 1000000.0;

pub static MAX_RECT: Rect<f32> = Rect {
    origin: Point2D {
        x: f32::MIN,
        y: f32::MIN,
    },
    size: Size2D {
        width: f32::INFINITY,
        height: f32::INFINITY,
    },
{'fraction_non_alphanumeric': 0.1289154445047981, 'fraction_numerical': 0.041644034039471305, 'mean_word_length': 3.131637995512341, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 25, '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': '3910528', 'n_tokens_mistral': 2056, 'n_tokens_neox': 1914, 'n_words': 513}