diff --git a/third_party/rust/euclid-0.11.3/.cargo-checksum.json b/third_party/rust/euclid-0.11.3/.cargo-checksum.json deleted file mode 100644 index becd539a3c86..000000000000 --- a/third_party/rust/euclid-0.11.3/.cargo-checksum.json +++ /dev/null @@ -1 +0,0 @@ -{"files":{".cargo-ok":"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",".gitignore":"118514fd9c4958df0d25584cda4917186c46011569f55ef350530c1ad3fbdb48",".travis.yml":"13d3e5a7bf83b04c8e8cfa14f0297bd8366d68391d977dd547f64707dffc275a","COPYRIGHT":"ec82b96487e9e778ee610c7ab245162464782cfa1f555c2299333f8dbe5c036a","Cargo.toml":"10cfe5580ee83ae883a60d96f504dda8ae7885ae5fd3a3faf95c2a2b8b38fad0","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"62065228e42caebca7e7d7db1204cbb867033de5982ca4009928915e4095f3a3","README.md":"52f974f01c1e15182413e4321c8817d5e66fe4d92c5ec223c857dd0440f5c229","src/approxeq.rs":"2987e046c90d948b6c7d7ddba52d10c8b7520d71dc0a50dbe7665de128d7410e","src/length.rs":"d7c6369f2fe2a17c845b57749bd48c471159f0571a7314d3bf90737d53f697d3","src/lib.rs":"e2e621f05304278d020429d0349acf7a4e7c7a9a72bd23fc0e55680267472ee9","src/macros.rs":"b63dabdb52df84ea170dc1dab5fe8d7a78c054562d1566bab416124708d2d7af","src/matrix2d.rs":"2361338f59813adf4eebaab76e4dd82be0fbfb9ff2461da8dd9ac9d43583b322","src/matrix4d.rs":"b8547bed6108b037192021c97169c00ad456120b849e9b7ac7bec40363edaec1","src/num.rs":"62286aa642ce3afa7ebd950f50bf2197d8722907f2e23a2e2ea6690484d8b250","src/point.rs":"53f3c9018c822e0a6dc5018005e153775479f41fe55c082d0be10f331fda773f","src/rect.rs":"db62b3af8939529509ae21b3bf6ae498d73a95b4ff3a6eba4db614be08e95f8b","src/scale_factor.rs":"df6dbd1f0f9f63210b92809f84a383dad982a74f09789cf22c7d8f9b62199d39","src/side_offsets.rs":"f85526a421ffda63ff01a3478d4162c8717eef68e942acfa2fd9a1adee02ebb2","src/size.rs":"19d1c08f678d793c6eff49a44f69e5b7179e574aa9b81fb4e73210733af38718","src/trig.rs":"6b207980052d13c625272f2a70a22f7741b59513c2a4882385926f497c763a63"},"package":"f5517462c626a893f3b027615e88d7102cc6dd3f7f1bcb90c7220fb1da4970b5"} \ No newline at end of file diff --git a/third_party/rust/euclid-0.11.3/.travis.yml b/third_party/rust/euclid-0.11.3/.travis.yml deleted file mode 100644 index a12141757c47..000000000000 --- a/third_party/rust/euclid-0.11.3/.travis.yml +++ /dev/null @@ -1,19 +0,0 @@ -language: rust - -notifications: - webhooks: http://build.servo.org:54856/travis - -matrix: - include: - - rust: stable - env: FEATURES="" - - rust: beta - env: FEATURES="" - - rust: nightly - env: FEATURES="" - - rust: nightly - env: FEATURES="unstable" - -script: - - cargo build --verbose --features "$FEATURES" - - cargo test --verbose --features "$FEATURES" diff --git a/third_party/rust/euclid-0.11.3/COPYRIGHT b/third_party/rust/euclid-0.11.3/COPYRIGHT deleted file mode 100644 index 8b7291ad281c..000000000000 --- a/third_party/rust/euclid-0.11.3/COPYRIGHT +++ /dev/null @@ -1,5 +0,0 @@ -Licensed under the Apache License, Version 2.0 or the MIT license -, at your -option. All files in the project carrying such notice may not be -copied, modified, or distributed except according to those terms. diff --git a/third_party/rust/euclid-0.11.3/Cargo.toml b/third_party/rust/euclid-0.11.3/Cargo.toml deleted file mode 100644 index f628a082c81f..000000000000 --- a/third_party/rust/euclid-0.11.3/Cargo.toml +++ /dev/null @@ -1,22 +0,0 @@ -[package] -name = "euclid" -version = "0.11.3" -authors = ["The Servo Project Developers"] -description = "Geometry primitives" -documentation = "https://docs.rs/euclid/" -repository = "https://github.com/servo/euclid" -license = "MIT / Apache-2.0" - -[features] -unstable = [] - -[dependencies] -heapsize = "0.3" -rustc-serialize = "0.3.2" -num-traits = {version = "0.1.32", default-features = false} -log = "0.3.1" -serde = "0.9" - -[dev-dependencies] -rand = "0.3.7" -serde_test = "0.9" diff --git a/third_party/rust/euclid-0.11.3/LICENSE-APACHE b/third_party/rust/euclid-0.11.3/LICENSE-APACHE deleted file mode 100644 index 16fe87b06e80..000000000000 --- a/third_party/rust/euclid-0.11.3/LICENSE-APACHE +++ /dev/null @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - -TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - -1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - -2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - -3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - -4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - -5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - -6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - -7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - -8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - -9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - -END OF TERMS AND CONDITIONS - -APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - -Copyright [yyyy] [name of copyright owner] - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. diff --git a/third_party/rust/euclid-0.11.3/LICENSE-MIT b/third_party/rust/euclid-0.11.3/LICENSE-MIT deleted file mode 100644 index 807526f57f3a..000000000000 --- a/third_party/rust/euclid-0.11.3/LICENSE-MIT +++ /dev/null @@ -1,25 +0,0 @@ -Copyright (c) 2012-2013 Mozilla Foundation - -Permission is hereby granted, free of charge, to any -person obtaining a copy of this software and associated -documentation files (the "Software"), to deal in the -Software without restriction, including without -limitation the rights to use, copy, modify, merge, -publish, distribute, sublicense, and/or sell copies of -the Software, and to permit persons to whom the Software -is furnished to do so, subject to the following -conditions: - -The above copyright notice and this permission notice -shall be included in all copies or substantial portions -of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF -ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED -TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A -PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT -SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR -IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS IN THE SOFTWARE. diff --git a/third_party/rust/euclid-0.11.3/README.md b/third_party/rust/euclid-0.11.3/README.md deleted file mode 100644 index 310c514cd405..000000000000 --- a/third_party/rust/euclid-0.11.3/README.md +++ /dev/null @@ -1,5 +0,0 @@ -# euclid - -This is a small library for geometric types. - -[Documentation](https://docs.rs/euclid/) diff --git a/third_party/rust/euclid-0.11.3/src/approxeq.rs b/third_party/rust/euclid-0.11.3/src/approxeq.rs deleted file mode 100644 index 10151110669a..000000000000 --- a/third_party/rust/euclid-0.11.3/src/approxeq.rs +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright 2013 The Servo Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - - -/// Trait for testing approximate equality -pub trait ApproxEq { - fn approx_epsilon() -> Eps; - fn approx_eq(&self, other: &Self) -> bool; - fn approx_eq_eps(&self, other: &Self, approx_epsilon: &Eps) -> bool; -} - -impl ApproxEq for f32 { - #[inline] - fn approx_epsilon() -> f32 { 1.0e-6 } - - #[inline] - fn approx_eq(&self, other: &f32) -> bool { - self.approx_eq_eps(other, &1.0e-6) - } - - #[inline] - fn approx_eq_eps(&self, other: &f32, approx_epsilon: &f32) -> bool { - (*self - *other).abs() < *approx_epsilon - } -} - - -impl ApproxEq for f64 { - #[inline] - fn approx_epsilon() -> f64 { 1.0e-6 } - - #[inline] - fn approx_eq(&self, other: &f64) -> bool { - self.approx_eq_eps(other, &1.0e-6) - } - - #[inline] - fn approx_eq_eps(&self, other: &f64, approx_epsilon: &f64) -> bool { - (*self - *other).abs() < *approx_epsilon - } -} diff --git a/third_party/rust/euclid-0.11.3/src/length.rs b/third_party/rust/euclid-0.11.3/src/length.rs deleted file mode 100644 index 4d20bb93c55b..000000000000 --- a/third_party/rust/euclid-0.11.3/src/length.rs +++ /dev/null @@ -1,449 +0,0 @@ -// Copyright 2014 The Servo Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. -//! A one-dimensional length, tagged with its units. - -use scale_factor::ScaleFactor; -use num::Zero; - -use heapsize::HeapSizeOf; -use num_traits::{NumCast, Saturating}; -use serde::{Deserialize, Deserializer, Serialize, Serializer}; -use std::cmp::Ordering; -use std::ops::{Add, Sub, Mul, Div, Neg}; -use std::ops::{AddAssign, SubAssign}; -use std::marker::PhantomData; -use std::fmt; - -/// A one-dimensional distance, with value represented by `T` and unit of measurement `Unit`. -/// -/// `T` can be any numeric type, for example a primitive type like `u64` or `f32`. -/// -/// `Unit` is not used in the representation of a `Length` value. It is used only at compile time -/// to ensure that a `Length` stored with one unit is converted explicitly before being used in an -/// expression that requires a different unit. It may be a type without values, such as an empty -/// enum. -/// -/// You can multiply a `Length` by a `scale_factor::ScaleFactor` to convert it from one unit to -/// another. See the `ScaleFactor` docs for an example. -// Uncomment the derive, and remove the macro call, once heapsize gets -// PhantomData support. -#[repr(C)] -#[derive(RustcDecodable, RustcEncodable)] -pub struct Length(pub T, PhantomData); - -impl Clone for Length { - fn clone(&self) -> Self { - Length(self.0.clone(), PhantomData) - } -} - -impl Copy for Length {} - -impl HeapSizeOf for Length { - fn heap_size_of_children(&self) -> usize { - self.0.heap_size_of_children() - } -} - -impl Deserialize for Length where T: Deserialize { - fn deserialize(deserializer: D) -> Result,D::Error> - where D: Deserializer { - Ok(Length(try!(Deserialize::deserialize(deserializer)), PhantomData)) - } -} - -impl Serialize for Length where T: Serialize { - fn serialize(&self, serializer: S) -> Result where S: Serializer { - self.0.serialize(serializer) - } -} - -impl Length { - pub fn new(x: T) -> Length { - Length(x, PhantomData) - } -} - -impl Length { - pub fn get(&self) -> T { - self.0.clone() - } -} - -impl fmt::Debug for Length { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - self.get().fmt(f) - } -} - -impl fmt::Display for Length { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - self.get().fmt(f) - } -} - -// length + length -impl> Add for Length { - type Output = Length; - fn add(self, other: Length) -> Length { - Length::new(self.get() + other.get()) - } -} - -// length += length -impl> AddAssign for Length { - fn add_assign(&mut self, other: Length) { - self.0 += other.get(); - } -} - -// length - length -impl> Sub> for Length { - type Output = Length; - fn sub(self, other: Length) -> ::Output { - Length::new(self.get() - other.get()) - } -} - -// length -= length -impl> SubAssign for Length { - fn sub_assign(&mut self, other: Length) { - self.0 -= other.get(); - } -} - -// Saturating length + length and length - length. -impl Saturating for Length { - fn saturating_add(self, other: Length) -> Length { - Length::new(self.get().saturating_add(other.get())) - } - - fn saturating_sub(self, other: Length) -> Length { - Length::new(self.get().saturating_sub(other.get())) - } -} - -// length / length -impl> Div> for Length { - type Output = ScaleFactor; - #[inline] - fn div(self, other: Length) -> ScaleFactor { - ScaleFactor::new(self.get() / other.get()) - } -} - -// length * scaleFactor -impl> Mul> for Length { - type Output = Length; - #[inline] - fn mul(self, scale: ScaleFactor) -> Length { - Length::new(self.get() * scale.get()) - } -} - -// length / scaleFactor -impl> Div> for Length { - type Output = Length; - #[inline] - fn div(self, scale: ScaleFactor) -> Length { - Length::new(self.get() / scale.get()) - } -} - -// -length -impl > Neg for Length { - type Output = Length; - #[inline] - fn neg(self) -> Length { - Length::new(-self.get()) - } -} - -impl Length { - /// Cast from one numeric representation to another, preserving the units. - pub fn cast(&self) -> Option> { - NumCast::from(self.get()).map(Length::new) - } -} - -impl PartialEq for Length { - fn eq(&self, other: &Length) -> bool { self.get().eq(&other.get()) } -} - -impl PartialOrd for Length { - fn partial_cmp(&self, other: &Length) -> Option { - self.get().partial_cmp(&other.get()) - } -} - -impl Eq for Length {} - -impl Ord for Length { - fn cmp(&self, other: &Length) -> Ordering { self.get().cmp(&other.get()) } -} - -impl Zero for Length { - fn zero() -> Length { - Length::new(Zero::zero()) - } -} - -#[cfg(test)] -mod tests { - use super::Length; - use num::Zero; - - use heapsize::HeapSizeOf; - use num_traits::Saturating; - use scale_factor::ScaleFactor; - use std::f32::INFINITY; - - extern crate serde_test; - use self::serde_test::Token; - use self::serde_test::assert_tokens; - - enum Inch {} - enum Mm {} - enum Cm {} - enum Second {} - - #[test] - fn test_clone() { - // A cloned Length is a separate length with the state matching the - // original Length at the point it was cloned. - let mut variable_length: Length = Length::new(12.0); - - let one_foot = variable_length.clone(); - variable_length.0 = 24.0; - - assert_eq!(one_foot.get(), 12.0); - assert_eq!(variable_length.get(), 24.0); - } - - #[test] - fn test_heapsizeof_builtins() { - // Heap size of built-ins is zero by default. - let one_foot: Length = Length::new(12.0); - - let heap_size_length_f32 = one_foot.heap_size_of_children(); - - assert_eq!(heap_size_length_f32, 0); - } - - #[test] - fn test_heapsizeof_length_vector() { - // Heap size of any Length is just the heap size of the length value. - for n in 0..5 { - let length: Length, Inch> = Length::new(Vec::with_capacity(n)); - - assert_eq!(length.heap_size_of_children(), length.0.heap_size_of_children()); - } - } - - #[test] - fn test_length_serde() { - let one_cm: Length = Length::new(10.0); - - assert_tokens(&one_cm, &[Token::F32(10.0)]); - } - - #[test] - fn test_get_clones_length_value() { - // Calling get returns a clone of the Length's value. - // To test this, we need something clone-able - hence a vector. - let mut length: Length, Inch> = Length::new(vec![1, 2, 3]); - - let value = length.get(); - length.0.push(4); - - assert_eq!(value, vec![1, 2, 3]); - assert_eq!(length.get(), vec![1, 2, 3, 4]); - } - - #[test] - fn test_fmt_debug() { - // Debug and display format the value only. - let one_cm: Length = Length::new(10.0); - - let result = format!("{:?}", one_cm); - - assert_eq!(result, "10"); - } - - #[test] - fn test_fmt_display() { - // Debug and display format the value only. - let one_cm: Length = Length::new(10.0); - - let result = format!("{}", one_cm); - - assert_eq!(result, "10"); - } - - #[test] - fn test_add() { - let length1: Length = Length::new(250); - let length2: Length = Length::new(5); - - let result = length1 + length2; - - assert_eq!(result.get(), 255); - } - - #[test] - fn test_addassign() { - let one_cm: Length = Length::new(10.0); - let mut measurement: Length = Length::new(5.0); - - measurement += one_cm; - - assert_eq!(measurement.get(), 15.0); - } - - #[test] - fn test_sub() { - let length1: Length = Length::new(250); - let length2: Length = Length::new(5); - - let result = length1 - length2; - - assert_eq!(result.get(), 245); - } - - #[test] - fn test_subassign() { - let one_cm: Length = Length::new(10.0); - let mut measurement: Length = Length::new(5.0); - - measurement -= one_cm; - - assert_eq!(measurement.get(), -5.0); - } - - #[test] - fn test_saturating_add() { - let length1: Length = Length::new(250); - let length2: Length = Length::new(6); - - let result = length1.saturating_add(length2); - - assert_eq!(result.get(), 255); - } - - #[test] - fn test_saturating_sub() { - let length1: Length = Length::new(5); - let length2: Length = Length::new(10); - - let result = length1.saturating_sub(length2); - - assert_eq!(result.get(), 0); - } - - #[test] - fn test_division_by_length() { - // Division results in a ScaleFactor from denominator units - // to numerator units. - let length: Length = Length::new(5.0); - let duration: Length = Length::new(10.0); - - let result = length / duration; - - let expected: ScaleFactor = ScaleFactor::new(0.5); - assert_eq!(result, expected); - } - - #[test] - fn test_multiplication() { - let length_mm: Length = Length::new(10.0); - let cm_per_mm: ScaleFactor = ScaleFactor::new(0.1); - - let result = length_mm * cm_per_mm; - - let expected: Length = Length::new(1.0); - assert_eq!(result, expected); - } - - #[test] - fn test_division_by_scalefactor() { - let length: Length = Length::new(5.0); - let cm_per_second: ScaleFactor = ScaleFactor::new(10.0); - - let result = length / cm_per_second; - - let expected: Length = Length::new(0.5); - assert_eq!(result, expected); - } - - #[test] - fn test_negation() { - let length: Length = Length::new(5.0); - - let result = -length; - - let expected: Length = Length::new(-5.0); - assert_eq!(result, expected); - } - - #[test] - fn test_cast() { - let length_as_i32: Length = Length::new(5); - - let result: Length = length_as_i32.cast().unwrap(); - - let length_as_f32: Length = Length::new(5.0); - assert_eq!(result, length_as_f32); - } - - #[test] - fn test_equality() { - let length_5_point_0: Length = Length::new(5.0); - let length_5_point_1: Length = Length::new(5.1); - let length_0_point_1: Length = Length::new(0.1); - - assert!(length_5_point_0 == length_5_point_1 - length_0_point_1); - assert!(length_5_point_0 != length_5_point_1); - } - - #[test] - fn test_order() { - let length_5_point_0: Length = Length::new(5.0); - let length_5_point_1: Length = Length::new(5.1); - let length_0_point_1: Length = Length::new(0.1); - - assert!(length_5_point_0 < length_5_point_1); - assert!(length_5_point_0 <= length_5_point_1); - assert!(length_5_point_0 <= length_5_point_1 - length_0_point_1); - assert!(length_5_point_1 > length_5_point_0); - assert!(length_5_point_1 >= length_5_point_0); - assert!(length_5_point_0 >= length_5_point_1 - length_0_point_1); - } - - #[test] - fn test_zero_add() { - type LengthCm = Length; - let length: LengthCm = Length::new(5.0); - - let result = length - LengthCm::zero(); - - assert_eq!(result, length); - } - - #[test] - fn test_zero_division() { - type LengthCm = Length; - let length: LengthCm = Length::new(5.0); - let length_zero: LengthCm = Length::zero(); - - let result = length / length_zero; - - let expected: ScaleFactor = ScaleFactor::new(INFINITY); - assert_eq!(result, expected); - } -} diff --git a/third_party/rust/euclid-0.11.3/src/lib.rs b/third_party/rust/euclid-0.11.3/src/lib.rs deleted file mode 100644 index 2ed3edde9696..000000000000 --- a/third_party/rust/euclid-0.11.3/src/lib.rs +++ /dev/null @@ -1,113 +0,0 @@ -// Copyright 2013 The Servo Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#![cfg_attr(feature = "unstable", feature(asm, repr_simd, test))] - -//! A collection of strongly typed math tools for computer graphics with an inclination -//! towards 2d graphics and layout. -//! -//! All types are generic over the scalar type of their component (`f32`, `i32`, etc.), -//! and tagged with a generic Unit parameter which is useful to prevent mixing -//! values from different spaces. For example it should not be legal to translate -//! a screen-space position by a world-space vector and this can be expressed using -//! the generic Unit parameter. -//! -//! This unit system is not mandatory and all Typed* structures have an alias -//! with the default unit: `UnknownUnit`. -//! for example ```Point2D``` is equivalent to ```TypedPoint2D```. -//! Client code typically creates a set of aliases for each type and doesn't need -//! to deal with the specifics of typed units further. For example: -//! -//! All euclid types are marked `#[repr(C)]` in order to facilitate exposing them to -//! foreign function interfaces (provided the underlying scalar type is also `repr(C)`). -//! -//! ```rust -//! use euclid::*; -//! pub struct ScreenSpace; -//! pub type ScreenPoint = TypedPoint2D; -//! pub type ScreenSize = TypedSize2D; -//! pub struct WorldSpace; -//! pub type WorldPoint = TypedPoint3D; -//! pub type ProjectionMatrix = TypedMatrix4D; -//! // etc... -//! ``` -//! -//! Components are accessed in their scalar form by default for convenience, and most -//! types additionally implement strongly typed accessors which return typed ```Length``` wrappers. -//! For example: -//! -//! ```rust -//! # use euclid::*; -//! # pub struct WorldSpace; -//! # pub type WorldPoint = TypedPoint3D; -//! let p = WorldPoint::new(0.0, 1.0, 1.0); -//! // p.x is an f32. -//! println!("p.x = {:?} ", p.x); -//! // p.x is a Length. -//! println!("p.x_typed() = {:?} ", p.x_typed()); -//! // Length::get returns the scalar value (f32). -//! assert_eq!(p.x, p.x_typed().get()); -//! ``` - -extern crate heapsize; - -#[cfg_attr(test, macro_use)] -extern crate log; -extern crate rustc_serialize; -extern crate serde; - -#[cfg(test)] -extern crate rand; -#[cfg(feature = "unstable")] -extern crate test; -extern crate num_traits; - -pub use length::Length; -pub use scale_factor::ScaleFactor; -pub use matrix2d::{Matrix2D, TypedMatrix2D}; -pub use matrix4d::{Matrix4D, TypedMatrix4D}; -pub use point::{ - Point2D, TypedPoint2D, - Point3D, TypedPoint3D, - Point4D, TypedPoint4D, -}; -pub use rect::{Rect, TypedRect}; -pub use side_offsets::{SideOffsets2D, TypedSideOffsets2D}; -#[cfg(feature = "unstable")] pub use side_offsets::SideOffsets2DSimdI32; -pub use size::{Size2D, TypedSize2D}; - -pub mod approxeq; -pub mod length; -#[macro_use] -mod macros; -pub mod matrix2d; -pub mod matrix4d; -pub mod num; -pub mod point; -pub mod rect; -pub mod scale_factor; -pub mod side_offsets; -pub mod size; -pub mod trig; - -/// The default unit. -#[derive(Clone, Copy, RustcDecodable, RustcEncodable)] -pub struct UnknownUnit; - -/// Unit for angles in radians. -pub struct Rad; - -/// Unit for angles in degrees. -pub struct Deg; - -/// A value in radians. -pub type Radians = Length; - -/// A value in Degrees. -pub type Degrees = Length; diff --git a/third_party/rust/euclid-0.11.3/src/macros.rs b/third_party/rust/euclid-0.11.3/src/macros.rs deleted file mode 100644 index 2f597cb08190..000000000000 --- a/third_party/rust/euclid-0.11.3/src/macros.rs +++ /dev/null @@ -1,87 +0,0 @@ -// Copyright 2013 The Servo Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -macro_rules! define_matrix { - ( - $(#[$attr:meta])* - pub struct $name:ident { - $(pub $field:ident: T,)+ - } - ) => ( - #[repr(C)] - $(#[$attr])* - pub struct $name { - $(pub $field: T,)+ - _unit: PhantomData<($($phantom),+)> - } - - impl Clone for $name { - fn clone(&self) -> Self { - $name { - $($field: self.$field.clone(),)+ - _unit: PhantomData, - } - } - } - - impl Copy for $name {} - - impl ::heapsize::HeapSizeOf for $name - where T: ::heapsize::HeapSizeOf - { - fn heap_size_of_children(&self) -> usize { - $(self.$field.heap_size_of_children() +)+ 0 - } - } - - impl ::serde::Deserialize for $name - where T: ::serde::Deserialize - { - fn deserialize(deserializer: D) -> Result - where D: ::serde::Deserializer - { - let ($($field,)+) = - try!(::serde::Deserialize::deserialize(deserializer)); - Ok($name { - $($field: $field,)+ - _unit: PhantomData, - }) - } - } - - impl ::serde::Serialize for $name - where T: ::serde::Serialize - { - fn serialize(&self, serializer: S) -> Result - where S: ::serde::Serializer - { - ($(&self.$field,)+).serialize(serializer) - } - } - - impl ::std::cmp::Eq for $name - where T: ::std::cmp::Eq {} - - impl ::std::cmp::PartialEq for $name - where T: ::std::cmp::PartialEq - { - fn eq(&self, other: &Self) -> bool { - true $(&& self.$field == other.$field)+ - } - } - - impl ::std::hash::Hash for $name - where T: ::std::hash::Hash - { - fn hash(&self, h: &mut H) { - $(self.$field.hash(h);)+ - } - } - ) -} diff --git a/third_party/rust/euclid-0.11.3/src/matrix2d.rs b/third_party/rust/euclid-0.11.3/src/matrix2d.rs deleted file mode 100644 index 5c86a7ee36e7..000000000000 --- a/third_party/rust/euclid-0.11.3/src/matrix2d.rs +++ /dev/null @@ -1,431 +0,0 @@ -// Copyright 2013 The Servo Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -use super::{UnknownUnit, Radians}; -use num::{One, Zero}; -use point::TypedPoint2D; -use rect::TypedRect; -use std::ops::{Add, Mul, Div, Sub}; -use std::marker::PhantomData; -use approxeq::ApproxEq; -use trig::Trig; -use std::fmt; - -define_matrix! { - /// A 2d transform stored as a 2 by 3 matrix in row-major order in memory, - /// useful to represent 2d transformations. - /// - /// Matrices can be parametrized over the source and destination units, to describe a - /// transformation from a space to another. - /// For example, `TypedMatrix2D::transform_point4d` - /// takes a `TypedPoint2D` and returns a `TypedPoint2D`. - /// - /// Matrices expose a set of convenience methods for pre- and post-transformations. - /// A pre-transformation corresponds to adding an operation that is applied before - /// the rest of the transformation, while a post-transformation adds an operation - /// that is applied after. - pub struct TypedMatrix2D { - pub m11: T, pub m12: T, - pub m21: T, pub m22: T, - pub m31: T, pub m32: T, - } -} - -/// The default 2d matrix type with no units. -pub type Matrix2D = TypedMatrix2D; - -impl TypedMatrix2D { - /// Create a matrix specifying its components in row-major order. - pub fn row_major(m11: T, m12: T, m21: T, m22: T, m31: T, m32: T) -> TypedMatrix2D { - TypedMatrix2D { - m11: m11, m12: m12, - m21: m21, m22: m22, - m31: m31, m32: m32, - _unit: PhantomData, - } - } - - /// Create a matrix specifying its components in column-major order. - pub fn column_major(m11: T, m21: T, m31: T, m12: T, m22: T, m32: T) -> TypedMatrix2D { - TypedMatrix2D { - m11: m11, m12: m12, - m21: m21, m22: m22, - m31: m31, m32: m32, - _unit: PhantomData, - } - } - - /// Returns an array containing this matrix's terms in row-major order (the order - /// in which the matrix is actually laid out in memory). - pub fn to_row_major_array(&self) -> [T; 6] { - [ - self.m11, self.m12, - self.m21, self.m22, - self.m31, self.m32 - ] - } - - /// Returns an array containing this matrix's terms in column-major order. - pub fn to_column_major_array(&self) -> [T; 6] { - [ - self.m11, self.m21, self.m31, - self.m12, self.m22, self.m32 - ] - } - - /// Drop the units, preserving only the numeric value. - pub fn to_untyped(&self) -> Matrix2D { - Matrix2D::row_major( - self.m11, self.m12, - self.m21, self.m22, - self.m31, self.m32 - ) - } - - /// Tag a unitless value with units. - pub fn from_untyped(p: &Matrix2D) -> TypedMatrix2D { - TypedMatrix2D::row_major( - p.m11, p.m12, - p.m21, p.m22, - p.m31, p.m32 - ) - } -} - -impl TypedMatrix2D -where T: Copy + - PartialEq + - One + Zero { - pub fn identity() -> TypedMatrix2D { - let (_0, _1) = (Zero::zero(), One::one()); - TypedMatrix2D::row_major( - _1, _0, - _0, _1, - _0, _0 - ) - } - - // Intentional not public, because it checks for exact equivalence - // while most consumers will probably want some sort of approximate - // equivalence to deal with floating-point errors. - fn is_identity(&self) -> bool { - *self == TypedMatrix2D::identity() - } -} - -impl TypedMatrix2D -where T: Copy + Clone + - Add + - Mul + - Div + - Sub + - Trig + - PartialOrd + - One + Zero { - - /// Returns the multiplication of the two matrices such that mat's transformation - /// applies after self's transformation. - pub fn post_mul(&self, mat: &TypedMatrix2D) -> TypedMatrix2D { - TypedMatrix2D::row_major( - self.m11 * mat.m11 + self.m12 * mat.m21, - self.m11 * mat.m12 + self.m12 * mat.m22, - self.m21 * mat.m11 + self.m22 * mat.m21, - self.m21 * mat.m12 + self.m22 * mat.m22, - self.m31 * mat.m11 + self.m32 * mat.m21 + mat.m31, - self.m31 * mat.m12 + self.m32 * mat.m22 + mat.m32, - ) - } - - /// Returns the multiplication of the two matrices such that mat's transformation - /// applies before self's transformation. - pub fn pre_mul(&self, mat: &TypedMatrix2D) -> TypedMatrix2D { - mat.post_mul(self) - } - - /// Returns a translation matrix. - pub fn create_translation(x: T, y: T) -> TypedMatrix2D { - let (_0, _1): (T, T) = (Zero::zero(), One::one()); - TypedMatrix2D::row_major( - _1, _0, - _0, _1, - x, y - ) - } - - /// Applies a translation after self's transformation and returns the resulting matrix. - pub fn post_translated(&self, x: T, y: T) -> TypedMatrix2D { - self.post_mul(&TypedMatrix2D::create_translation(x, y)) - } - - /// Applies a translation before self's transformation and returns the resulting matrix. - pub fn pre_translated(&self, x: T, y: T) -> TypedMatrix2D { - self.pre_mul(&TypedMatrix2D::create_translation(x, y)) - } - - /// Returns a scale matrix. - pub fn create_scale(x: T, y: T) -> TypedMatrix2D { - let _0 = Zero::zero(); - TypedMatrix2D::row_major( - x, _0, - _0, y, - _0, _0 - ) - } - - /// Applies a scale after self's transformation and returns the resulting matrix. - pub fn post_scaled(&self, x: T, y: T) -> TypedMatrix2D { - self.post_mul(&TypedMatrix2D::create_scale(x, y)) - } - - /// Applies a scale before self's transformation and returns the resulting matrix. - pub fn pre_scaled(&self, x: T, y: T) -> TypedMatrix2D { - TypedMatrix2D::row_major( - self.m11 * x, self.m12, - self.m21, self.m22 * y, - self.m31, self.m32 - ) - } - - /// Returns a rotation matrix. - pub fn create_rotation(theta: Radians) -> TypedMatrix2D { - let _0 = Zero::zero(); - let cos = theta.get().cos(); - let sin = theta.get().sin(); - TypedMatrix2D::row_major( - cos, _0 - sin, - sin, cos, - _0, _0 - ) - } - - /// Applies a rotation after self's transformation and returns the resulting matrix. - pub fn post_rotated(&self, theta: Radians) -> TypedMatrix2D { - self.post_mul(&TypedMatrix2D::create_rotation(theta)) - } - - /// Applies a rotation after self's transformation and returns the resulting matrix. - pub fn pre_rotated(&self, theta: Radians) -> TypedMatrix2D { - self.pre_mul(&TypedMatrix2D::create_rotation(theta)) - } - - /// Returns the given point transformed by this matrix. - #[inline] - pub fn transform_point(&self, point: &TypedPoint2D) -> TypedPoint2D { - TypedPoint2D::new(point.x * self.m11 + point.y * self.m21 + self.m31, - point.x * self.m12 + point.y * self.m22 + self.m32) - } - - /// Returns a rectangle that encompasses the result of transforming the given rectangle by this - /// matrix. - #[inline] - pub fn transform_rect(&self, rect: &TypedRect) -> TypedRect { - TypedRect::from_points(&[ - self.transform_point(&rect.origin), - self.transform_point(&rect.top_right()), - self.transform_point(&rect.bottom_left()), - self.transform_point(&rect.bottom_right()), - ]) - } - - /// Computes and returns the determinant of this matrix. - pub fn determinant(&self) -> T { - self.m11 * self.m22 - self.m12 * self.m21 - } - - /// Returns the inverse matrix if possible. - pub fn inverse(&self) -> Option> { - let det = self.determinant(); - - let _0: T = Zero::zero(); - let _1: T = One::one(); - - if det == _0 { - return None; - } - - let inv_det = _1 / det; - Some(TypedMatrix2D::row_major( - inv_det * self.m22, - inv_det * (_0 - self.m12), - inv_det * (_0 - self.m21), - inv_det * self.m11, - inv_det * (self.m21 * self.m32 - self.m22 * self.m31), - inv_det * (self.m31 * self.m12 - self.m11 * self.m32), - )) - } - - /// Returns the same matrix with a different destination unit. - #[inline] - pub fn with_destination(&self) -> TypedMatrix2D { - TypedMatrix2D::row_major( - self.m11, self.m12, - self.m21, self.m22, - self.m31, self.m32, - ) - } - - /// Returns the same matrix with a different source unit. - #[inline] - pub fn with_source(&self) -> TypedMatrix2D { - TypedMatrix2D::row_major( - self.m11, self.m12, - self.m21, self.m22, - self.m31, self.m32, - ) - } -} - -impl, Src, Dst> TypedMatrix2D { - pub fn approx_eq(&self, other: &Self) -> bool { - self.m11.approx_eq(&other.m11) && self.m12.approx_eq(&other.m12) && - self.m21.approx_eq(&other.m21) && self.m22.approx_eq(&other.m22) && - self.m31.approx_eq(&other.m31) && self.m32.approx_eq(&other.m32) - } -} - -impl fmt::Debug for TypedMatrix2D -where T: Copy + fmt::Debug + - PartialEq + - One + Zero { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - if self.is_identity() { - write!(f, "[I]") - } else { - self.to_row_major_array().fmt(f) - } - } -} - -#[cfg(test)] -mod test { - use super::*; - use approxeq::ApproxEq; - use point::Point2D; - use Radians; - - use std::f32::consts::FRAC_PI_2; - - type Mat = Matrix2D; - - fn rad(v: f32) -> Radians { Radians::new(v) } - - #[test] - pub fn test_translation() { - let t1 = Mat::create_translation(1.0, 2.0); - let t2 = Mat::identity().pre_translated(1.0, 2.0); - let t3 = Mat::identity().post_translated(1.0, 2.0); - assert_eq!(t1, t2); - assert_eq!(t1, t3); - - assert_eq!(t1.transform_point(&Point2D::new(1.0, 1.0)), Point2D::new(2.0, 3.0)); - - assert_eq!(t1.post_mul(&t1), Mat::create_translation(2.0, 4.0)); - } - - #[test] - pub fn test_rotation() { - let r1 = Mat::create_rotation(rad(FRAC_PI_2)); - let r2 = Mat::identity().pre_rotated(rad(FRAC_PI_2)); - let r3 = Mat::identity().post_rotated(rad(FRAC_PI_2)); - assert_eq!(r1, r2); - assert_eq!(r1, r3); - - assert!(r1.transform_point(&Point2D::new(1.0, 2.0)).approx_eq(&Point2D::new(2.0, -1.0))); - - assert!(r1.post_mul(&r1).approx_eq(&Mat::create_rotation(rad(FRAC_PI_2*2.0)))); - } - - #[test] - pub fn test_scale() { - let s1 = Mat::create_scale(2.0, 3.0); - let s2 = Mat::identity().pre_scaled(2.0, 3.0); - let s3 = Mat::identity().post_scaled(2.0, 3.0); - assert_eq!(s1, s2); - assert_eq!(s1, s3); - - assert!(s1.transform_point(&Point2D::new(2.0, 2.0)).approx_eq(&Point2D::new(4.0, 6.0))); - } - - #[test] - fn test_column_major() { - assert_eq!( - Mat::row_major( - 1.0, 2.0, - 3.0, 4.0, - 5.0, 6.0 - ), - Mat::column_major( - 1.0, 3.0, 5.0, - 2.0, 4.0, 6.0, - ) - ); - } - - #[test] - pub fn test_inverse_simple() { - let m1 = Mat::identity(); - let m2 = m1.inverse().unwrap(); - assert!(m1.approx_eq(&m2)); - } - - #[test] - pub fn test_inverse_scale() { - let m1 = Mat::create_scale(1.5, 0.3); - let m2 = m1.inverse().unwrap(); - assert!(m1.pre_mul(&m2).approx_eq(&Mat::identity())); - } - - #[test] - pub fn test_inverse_translate() { - let m1 = Mat::create_translation(-132.0, 0.3); - let m2 = m1.inverse().unwrap(); - assert!(m1.pre_mul(&m2).approx_eq(&Mat::identity())); - } - - #[test] - fn test_inverse_none() { - assert!(Mat::create_scale(2.0, 0.0).inverse().is_none()); - assert!(Mat::create_scale(2.0, 2.0).inverse().is_some()); - } - - #[test] - pub fn test_pre_post() { - let m1 = Matrix2D::identity().post_scaled(1.0, 2.0).post_translated(1.0, 2.0); - let m2 = Matrix2D::identity().pre_translated(1.0, 2.0).pre_scaled(1.0, 2.0); - assert!(m1.approx_eq(&m2)); - - let r = Mat::create_rotation(rad(FRAC_PI_2)); - let t = Mat::create_translation(2.0, 3.0); - - let a = Point2D::new(1.0, 1.0); - - assert!(r.post_mul(&t).transform_point(&a).approx_eq(&Point2D::new(3.0, 2.0))); - assert!(t.post_mul(&r).transform_point(&a).approx_eq(&Point2D::new(4.0, -3.0))); - assert!(t.post_mul(&r).transform_point(&a).approx_eq(&r.transform_point(&t.transform_point(&a)))); - - assert!(r.pre_mul(&t).transform_point(&a).approx_eq(&Point2D::new(4.0, -3.0))); - assert!(t.pre_mul(&r).transform_point(&a).approx_eq(&Point2D::new(3.0, 2.0))); - assert!(t.pre_mul(&r).transform_point(&a).approx_eq(&t.transform_point(&r.transform_point(&a)))); - } - - #[test] - fn test_size_of() { - use std::mem::size_of; - assert_eq!(size_of::>(), 6*size_of::()); - assert_eq!(size_of::>(), 6*size_of::()); - } - - #[test] - pub fn test_is_identity() { - let m1 = Matrix2D::identity(); - assert!(m1.is_identity()); - let m2 = m1.post_translated(0.1, 0.0); - assert!(!m2.is_identity()); - } -} diff --git a/third_party/rust/euclid-0.11.3/src/matrix4d.rs b/third_party/rust/euclid-0.11.3/src/matrix4d.rs deleted file mode 100644 index 2bccf8de3f95..000000000000 --- a/third_party/rust/euclid-0.11.3/src/matrix4d.rs +++ /dev/null @@ -1,825 +0,0 @@ -// Copyright 2013 The Servo Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -use super::{UnknownUnit, Radians}; -use approxeq::ApproxEq; -use trig::Trig; -use point::{TypedPoint2D, TypedPoint3D, TypedPoint4D}; -use rect::TypedRect; -use matrix2d::TypedMatrix2D; -use scale_factor::ScaleFactor; -use num::{One, Zero}; -use std::ops::{Add, Mul, Sub, Div, Neg}; -use std::marker::PhantomData; -use std::fmt; - -define_matrix! { - /// A 4 by 4 matrix stored in row-major order in memory, useful to represent - /// 3d transformations. - /// - /// Matrices can be parametrized over the source and destination units, to describe a - /// transformation from a space to another. - /// For example, `TypedMatrix4D::transform_point4d` - /// takes a `TypedPoint4D` and returns a `TypedPoint4D`. - /// - /// Matrices expose a set of convenience methods for pre- and post-transformations. - /// A pre-transformation corresponds to adding an operation that is applied before - /// the rest of the transformation, while a post-transformation adds an operation - /// that is applied after. - pub struct TypedMatrix4D { - pub m11: T, pub m12: T, pub m13: T, pub m14: T, - pub m21: T, pub m22: T, pub m23: T, pub m24: T, - pub m31: T, pub m32: T, pub m33: T, pub m34: T, - pub m41: T, pub m42: T, pub m43: T, pub m44: T, - } -} - -/// The default 4d matrix type with no units. -pub type Matrix4D = TypedMatrix4D; - -impl TypedMatrix4D { - /// Create a matrix specifying its components in row-major order. - /// - /// For example, the translation terms m41, m42, m43 on the last row with the - /// row-major convention) are the 13rd, 14th and 15th parameters. - #[inline] - pub fn row_major( - m11: T, m12: T, m13: T, m14: T, - m21: T, m22: T, m23: T, m24: T, - m31: T, m32: T, m33: T, m34: T, - m41: T, m42: T, m43: T, m44: T) - -> TypedMatrix4D { - TypedMatrix4D { - m11: m11, m12: m12, m13: m13, m14: m14, - m21: m21, m22: m22, m23: m23, m24: m24, - m31: m31, m32: m32, m33: m33, m34: m34, - m41: m41, m42: m42, m43: m43, m44: m44, - _unit: PhantomData, - } - } - - /// Create a matrix specifying its components in column-major order. - /// - /// For example, the translation terms m41, m42, m43 on the last column with the - /// column-major convention) are the 4th, 8th and 12nd parameters. - #[inline] - pub fn column_major( - m11: T, m21: T, m31: T, m41: T, - m12: T, m22: T, m32: T, m42: T, - m13: T, m23: T, m33: T, m43: T, - m14: T, m24: T, m34: T, m44: T) - -> TypedMatrix4D { - TypedMatrix4D { - m11: m11, m12: m12, m13: m13, m14: m14, - m21: m21, m22: m22, m23: m23, m24: m24, - m31: m31, m32: m32, m33: m33, m34: m34, - m41: m41, m42: m42, m43: m43, m44: m44, - _unit: PhantomData, - } - } -} - -impl TypedMatrix4D -where T: Copy + Clone + - PartialEq + - One + Zero { - #[inline] - pub fn identity() -> TypedMatrix4D { - let (_0, _1): (T, T) = (Zero::zero(), One::one()); - TypedMatrix4D::row_major( - _1, _0, _0, _0, - _0, _1, _0, _0, - _0, _0, _1, _0, - _0, _0, _0, _1 - ) - } - - // Intentional not public, because it checks for exact equivalence - // while most consumers will probably want some sort of approximate - // equivalence to deal with floating-point errors. - #[inline] - fn is_identity(&self) -> bool { - *self == TypedMatrix4D::identity() - } -} - -impl TypedMatrix4D -where T: Copy + Clone + - Add + - Sub + - Mul + - Div + - Neg + - ApproxEq + - PartialOrd + - Trig + - One + Zero { - - /// Create a 4 by 4 matrix representing a 2d transformation, specifying its components - /// in row-major order. - #[inline] - pub fn row_major_2d(m11: T, m12: T, m21: T, m22: T, m41: T, m42: T) -> TypedMatrix4D { - let (_0, _1): (T, T) = (Zero::zero(), One::one()); - TypedMatrix4D::row_major( - m11, m12, _0, _0, - m21, m22, _0, _0, - _0, _0, _1, _0, - m41, m42, _0, _1 - ) - } - - /// Create an orthogonal projection matrix. - pub fn ortho(left: T, right: T, - bottom: T, top: T, - near: T, far: T) -> TypedMatrix4D { - let tx = -((right + left) / (right - left)); - let ty = -((top + bottom) / (top - bottom)); - let tz = -((far + near) / (far - near)); - - let (_0, _1): (T, T) = (Zero::zero(), One::one()); - let _2 = _1 + _1; - TypedMatrix4D::row_major( - _2 / (right - left), _0 , _0 , _0, - _0 , _2 / (top - bottom), _0 , _0, - _0 , _0 , -_2 / (far - near), _0, - tx , ty , tz , _1 - ) - } - - /// Returns true if this matrix can be represented with a TypedMatrix2D. - /// - /// See https://drafts.csswg.org/css-transforms/#2d-matrix - #[inline] - pub fn is_2d(&self) -> bool { - let (_0, _1): (T, T) = (Zero::zero(), One::one()); - self.m31 == _0 && self.m32 == _0 && - self.m13 == _0 && self.m23 == _0 && - self.m43 == _0 && self.m14 == _0 && - self.m24 == _0 && self.m34 == _0 && - self.m33 == _1 && self.m44 == _1 - } - - /// Create a 2D matrix picking the relevent terms from this matrix. - /// - /// This method assumes that self represents a 2d transformation, callers - /// should check that self.is_2d() returns true beforehand. - pub fn to_2d(&self) -> TypedMatrix2D { - TypedMatrix2D::row_major( - self.m11, self.m12, - self.m21, self.m22, - self.m41, self.m42 - ) - } - - pub fn approx_eq(&self, other: &TypedMatrix4D) -> bool { - self.m11.approx_eq(&other.m11) && self.m12.approx_eq(&other.m12) && - self.m13.approx_eq(&other.m13) && self.m14.approx_eq(&other.m14) && - self.m21.approx_eq(&other.m21) && self.m22.approx_eq(&other.m22) && - self.m23.approx_eq(&other.m23) && self.m24.approx_eq(&other.m24) && - self.m31.approx_eq(&other.m31) && self.m32.approx_eq(&other.m32) && - self.m33.approx_eq(&other.m33) && self.m34.approx_eq(&other.m34) && - self.m41.approx_eq(&other.m41) && self.m42.approx_eq(&other.m42) && - self.m43.approx_eq(&other.m43) && self.m44.approx_eq(&other.m44) - } - - /// Returns the same matrix with a different destination unit. - #[inline] - pub fn with_destination(&self) -> TypedMatrix4D { - TypedMatrix4D::row_major( - self.m11, self.m12, self.m13, self.m14, - self.m21, self.m22, self.m23, self.m24, - self.m31, self.m32, self.m33, self.m34, - self.m41, self.m42, self.m43, self.m44, - ) - } - - /// Returns the same matrix with a different source unit. - #[inline] - pub fn with_source(&self) -> TypedMatrix4D { - TypedMatrix4D::row_major( - self.m11, self.m12, self.m13, self.m14, - self.m21, self.m22, self.m23, self.m24, - self.m31, self.m32, self.m33, self.m34, - self.m41, self.m42, self.m43, self.m44, - ) - } - - /// Drop the units, preserving only the numeric value. - #[inline] - pub fn to_untyped(&self) -> Matrix4D { - Matrix4D::row_major( - self.m11, self.m12, self.m13, self.m14, - self.m21, self.m22, self.m23, self.m24, - self.m31, self.m32, self.m33, self.m34, - self.m41, self.m42, self.m43, self.m44, - ) - } - - /// Tag a unitless value with units. - #[inline] - pub fn from_untyped(m: &Matrix4D) -> Self { - TypedMatrix4D::row_major( - m.m11, m.m12, m.m13, m.m14, - m.m21, m.m22, m.m23, m.m24, - m.m31, m.m32, m.m33, m.m34, - m.m41, m.m42, m.m43, m.m44, - ) - } - - /// Returns the multiplication of the two matrices such that mat's transformation - /// applies after self's transformation. - pub fn post_mul(&self, mat: &TypedMatrix4D) -> TypedMatrix4D { - TypedMatrix4D::row_major( - self.m11 * mat.m11 + self.m12 * mat.m21 + self.m13 * mat.m31 + self.m14 * mat.m41, - self.m11 * mat.m12 + self.m12 * mat.m22 + self.m13 * mat.m32 + self.m14 * mat.m42, - self.m11 * mat.m13 + self.m12 * mat.m23 + self.m13 * mat.m33 + self.m14 * mat.m43, - self.m11 * mat.m14 + self.m12 * mat.m24 + self.m13 * mat.m34 + self.m14 * mat.m44, - self.m21 * mat.m11 + self.m22 * mat.m21 + self.m23 * mat.m31 + self.m24 * mat.m41, - self.m21 * mat.m12 + self.m22 * mat.m22 + self.m23 * mat.m32 + self.m24 * mat.m42, - self.m21 * mat.m13 + self.m22 * mat.m23 + self.m23 * mat.m33 + self.m24 * mat.m43, - self.m21 * mat.m14 + self.m22 * mat.m24 + self.m23 * mat.m34 + self.m24 * mat.m44, - self.m31 * mat.m11 + self.m32 * mat.m21 + self.m33 * mat.m31 + self.m34 * mat.m41, - self.m31 * mat.m12 + self.m32 * mat.m22 + self.m33 * mat.m32 + self.m34 * mat.m42, - self.m31 * mat.m13 + self.m32 * mat.m23 + self.m33 * mat.m33 + self.m34 * mat.m43, - self.m31 * mat.m14 + self.m32 * mat.m24 + self.m33 * mat.m34 + self.m34 * mat.m44, - self.m41 * mat.m11 + self.m42 * mat.m21 + self.m43 * mat.m31 + self.m44 * mat.m41, - self.m41 * mat.m12 + self.m42 * mat.m22 + self.m43 * mat.m32 + self.m44 * mat.m42, - self.m41 * mat.m13 + self.m42 * mat.m23 + self.m43 * mat.m33 + self.m44 * mat.m43, - self.m41 * mat.m14 + self.m42 * mat.m24 + self.m43 * mat.m34 + self.m44 * mat.m44, - ) - } - - /// Returns the multiplication of the two matrices such that mat's transformation - /// applies before self's transformation. - pub fn pre_mul(&self, mat: &TypedMatrix4D) -> TypedMatrix4D { - mat.post_mul(self) - } - - /// Returns the inverse matrix if possible. - pub fn inverse(&self) -> Option> { - let det = self.determinant(); - - if det == Zero::zero() { - return None; - } - - // todo(gw): this could be made faster by special casing - // for simpler matrix types. - let m = TypedMatrix4D::row_major( - self.m23*self.m34*self.m42 - self.m24*self.m33*self.m42 + - self.m24*self.m32*self.m43 - self.m22*self.m34*self.m43 - - self.m23*self.m32*self.m44 + self.m22*self.m33*self.m44, - - self.m14*self.m33*self.m42 - self.m13*self.m34*self.m42 - - self.m14*self.m32*self.m43 + self.m12*self.m34*self.m43 + - self.m13*self.m32*self.m44 - self.m12*self.m33*self.m44, - - self.m13*self.m24*self.m42 - self.m14*self.m23*self.m42 + - self.m14*self.m22*self.m43 - self.m12*self.m24*self.m43 - - self.m13*self.m22*self.m44 + self.m12*self.m23*self.m44, - - self.m14*self.m23*self.m32 - self.m13*self.m24*self.m32 - - self.m14*self.m22*self.m33 + self.m12*self.m24*self.m33 + - self.m13*self.m22*self.m34 - self.m12*self.m23*self.m34, - - self.m24*self.m33*self.m41 - self.m23*self.m34*self.m41 - - self.m24*self.m31*self.m43 + self.m21*self.m34*self.m43 + - self.m23*self.m31*self.m44 - self.m21*self.m33*self.m44, - - self.m13*self.m34*self.m41 - self.m14*self.m33*self.m41 + - self.m14*self.m31*self.m43 - self.m11*self.m34*self.m43 - - self.m13*self.m31*self.m44 + self.m11*self.m33*self.m44, - - self.m14*self.m23*self.m41 - self.m13*self.m24*self.m41 - - self.m14*self.m21*self.m43 + self.m11*self.m24*self.m43 + - self.m13*self.m21*self.m44 - self.m11*self.m23*self.m44, - - self.m13*self.m24*self.m31 - self.m14*self.m23*self.m31 + - self.m14*self.m21*self.m33 - self.m11*self.m24*self.m33 - - self.m13*self.m21*self.m34 + self.m11*self.m23*self.m34, - - self.m22*self.m34*self.m41 - self.m24*self.m32*self.m41 + - self.m24*self.m31*self.m42 - self.m21*self.m34*self.m42 - - self.m22*self.m31*self.m44 + self.m21*self.m32*self.m44, - - self.m14*self.m32*self.m41 - self.m12*self.m34*self.m41 - - self.m14*self.m31*self.m42 + self.m11*self.m34*self.m42 + - self.m12*self.m31*self.m44 - self.m11*self.m32*self.m44, - - self.m12*self.m24*self.m41 - self.m14*self.m22*self.m41 + - self.m14*self.m21*self.m42 - self.m11*self.m24*self.m42 - - self.m12*self.m21*self.m44 + self.m11*self.m22*self.m44, - - self.m14*self.m22*self.m31 - self.m12*self.m24*self.m31 - - self.m14*self.m21*self.m32 + self.m11*self.m24*self.m32 + - self.m12*self.m21*self.m34 - self.m11*self.m22*self.m34, - - self.m23*self.m32*self.m41 - self.m22*self.m33*self.m41 - - self.m23*self.m31*self.m42 + self.m21*self.m33*self.m42 + - self.m22*self.m31*self.m43 - self.m21*self.m32*self.m43, - - self.m12*self.m33*self.m41 - self.m13*self.m32*self.m41 + - self.m13*self.m31*self.m42 - self.m11*self.m33*self.m42 - - self.m12*self.m31*self.m43 + self.m11*self.m32*self.m43, - - self.m13*self.m22*self.m41 - self.m12*self.m23*self.m41 - - self.m13*self.m21*self.m42 + self.m11*self.m23*self.m42 + - self.m12*self.m21*self.m43 - self.m11*self.m22*self.m43, - - self.m12*self.m23*self.m31 - self.m13*self.m22*self.m31 + - self.m13*self.m21*self.m32 - self.m11*self.m23*self.m32 - - self.m12*self.m21*self.m33 + self.m11*self.m22*self.m33 - ); - - let _1: T = One::one(); - Some(m.mul_s(_1 / det)) - } - - /// Compute the determinant of the matrix. - pub fn determinant(&self) -> T { - self.m14 * self.m23 * self.m32 * self.m41 - - self.m13 * self.m24 * self.m32 * self.m41 - - self.m14 * self.m22 * self.m33 * self.m41 + - self.m12 * self.m24 * self.m33 * self.m41 + - self.m13 * self.m22 * self.m34 * self.m41 - - self.m12 * self.m23 * self.m34 * self.m41 - - self.m14 * self.m23 * self.m31 * self.m42 + - self.m13 * self.m24 * self.m31 * self.m42 + - self.m14 * self.m21 * self.m33 * self.m42 - - self.m11 * self.m24 * self.m33 * self.m42 - - self.m13 * self.m21 * self.m34 * self.m42 + - self.m11 * self.m23 * self.m34 * self.m42 + - self.m14 * self.m22 * self.m31 * self.m43 - - self.m12 * self.m24 * self.m31 * self.m43 - - self.m14 * self.m21 * self.m32 * self.m43 + - self.m11 * self.m24 * self.m32 * self.m43 + - self.m12 * self.m21 * self.m34 * self.m43 - - self.m11 * self.m22 * self.m34 * self.m43 - - self.m13 * self.m22 * self.m31 * self.m44 + - self.m12 * self.m23 * self.m31 * self.m44 + - self.m13 * self.m21 * self.m32 * self.m44 - - self.m11 * self.m23 * self.m32 * self.m44 - - self.m12 * self.m21 * self.m33 * self.m44 + - self.m11 * self.m22 * self.m33 * self.m44 - } - - /// Multiplies all of the matrix's component by a scalar and returns the result. - pub fn mul_s(&self, x: T) -> TypedMatrix4D { - TypedMatrix4D::row_major( - self.m11 * x, self.m12 * x, self.m13 * x, self.m14 * x, - self.m21 * x, self.m22 * x, self.m23 * x, self.m24 * x, - self.m31 * x, self.m32 * x, self.m33 * x, self.m34 * x, - self.m41 * x, self.m42 * x, self.m43 * x, self.m44 * x - ) - } - - /// Convenience function to create a scale matrix from a ScaleFactor. - pub fn from_scale_factor(scale: ScaleFactor) -> TypedMatrix4D { - TypedMatrix4D::create_scale(scale.get(), scale.get(), scale.get()) - } - - /// Returns the given 2d point transformed by this matrix. - /// - /// The input point must be use the unit Src, and the returned point has the unit Dst. - #[inline] - pub fn transform_point(&self, p: &TypedPoint2D) -> TypedPoint2D { - self.transform_point4d(&TypedPoint4D::new(p.x, p.y, Zero::zero(), One::one())).to_2d() - } - - /// Returns the given 3d point transformed by this matrix. - /// - /// The input point must be use the unit Src, and the returned point has the unit Dst. - #[inline] - pub fn transform_point3d(&self, p: &TypedPoint3D) -> TypedPoint3D { - self.transform_point4d(&TypedPoint4D::new(p.x, p.y, p.z, One::one())).to_3d() - } - - /// Returns the given 4d point transformed by this matrix. - /// - /// The input point must be use the unit Src, and the returned point has the unit Dst. - #[inline] - pub fn transform_point4d(&self, p: &TypedPoint4D) -> TypedPoint4D { - let x = p.x * self.m11 + p.y * self.m21 + p.z * self.m31 + p.w * self.m41; - let y = p.x * self.m12 + p.y * self.m22 + p.z * self.m32 + p.w * self.m42; - let z = p.x * self.m13 + p.y * self.m23 + p.z * self.m33 + p.w * self.m43; - let w = p.x * self.m14 + p.y * self.m24 + p.z * self.m34 + p.w * self.m44; - TypedPoint4D::new(x, y, z, w) - } - - /// Returns a rectangle that encompasses the result of transforming the given rectangle by this - /// matrix. - pub fn transform_rect(&self, rect: &TypedRect) -> TypedRect { - TypedRect::from_points(&[ - self.transform_point(&rect.origin), - self.transform_point(&rect.top_right()), - self.transform_point(&rect.bottom_left()), - self.transform_point(&rect.bottom_right()), - ]) - } - - /// Create a 3d translation matrix - pub fn create_translation(x: T, y: T, z: T) -> TypedMatrix4D { - let (_0, _1): (T, T) = (Zero::zero(), One::one()); - TypedMatrix4D::row_major( - _1, _0, _0, _0, - _0, _1, _0, _0, - _0, _0, _1, _0, - x, y, z, _1 - ) - } - - /// Returns a matrix with a translation applied before self's transformation. - pub fn pre_translated(&self, x: T, y: T, z: T) -> TypedMatrix4D { - self.pre_mul(&TypedMatrix4D::create_translation(x, y, z)) - } - - /// Returns a matrix with a translation applied after self's transformation. - pub fn post_translated(&self, x: T, y: T, z: T) -> TypedMatrix4D { - self.post_mul(&TypedMatrix4D::create_translation(x, y, z)) - } - - /// Create a 3d scale matrix - pub fn create_scale(x: T, y: T, z: T) -> TypedMatrix4D { - let (_0, _1): (T, T) = (Zero::zero(), One::one()); - TypedMatrix4D::row_major( - x, _0, _0, _0, - _0, y, _0, _0, - _0, _0, z, _0, - _0, _0, _0, _1 - ) - } - - /// Returns a matrix with a scale applied before self's transformation. - pub fn pre_scaled(&self, x: T, y: T, z: T) -> TypedMatrix4D { - TypedMatrix4D::row_major( - self.m11 * x, self.m12, self.m13, self.m14, - self.m21 , self.m22 * y, self.m23, self.m24, - self.m31 , self.m32, self.m33 * z, self.m34, - self.m41 , self.m42, self.m43, self.m44 - ) - } - - /// Returns a matrix with a scale applied after self's transformation. - pub fn post_scaled(&self, x: T, y: T, z: T) -> TypedMatrix4D { - self.post_mul(&TypedMatrix4D::create_scale(x, y, z)) - } - - /// Create a 3d rotation matrix from an angle / axis. - /// The supplied axis must be normalized. - pub fn create_rotation(x: T, y: T, z: T, theta: Radians) -> TypedMatrix4D { - let (_0, _1): (T, T) = (Zero::zero(), One::one()); - let _2 = _1 + _1; - - let xx = x * x; - let yy = y * y; - let zz = z * z; - - let half_theta = theta.get() / _2; - let sc = half_theta.sin() * half_theta.cos(); - let sq = half_theta.sin() * half_theta.sin(); - - TypedMatrix4D::row_major( - _1 - _2 * (yy + zz) * sq, - _2 * (x * y * sq - z * sc), - _2 * (x * z * sq + y * sc), - _0, - - _2 * (x * y * sq + z * sc), - _1 - _2 * (xx + zz) * sq, - _2 * (y * z * sq - x * sc), - _0, - - _2 * (x * z * sq - y * sc), - _2 * (y * z * sq + x * sc), - _1 - _2 * (xx + yy) * sq, - _0, - - _0, - _0, - _0, - _1 - ) - } - - /// Returns a matrix with a rotation applied after self's transformation. - pub fn post_rotated(&self, x: T, y: T, z: T, theta: Radians) -> TypedMatrix4D { - self.post_mul(&TypedMatrix4D::create_rotation(x, y, z, theta)) - } - - /// Returns a matrix with a rotation applied before self's transformation. - pub fn pre_rotated(&self, x: T, y: T, z: T, theta: Radians) -> TypedMatrix4D { - self.pre_mul(&TypedMatrix4D::create_rotation(x, y, z, theta)) - } - - /// Create a 2d skew matrix. - /// - /// See https://drafts.csswg.org/css-transforms/#funcdef-skew - pub fn create_skew(alpha: Radians, beta: Radians) -> TypedMatrix4D { - let (_0, _1): (T, T) = (Zero::zero(), One::one()); - let (sx, sy) = (beta.get().tan(), alpha.get().tan()); - TypedMatrix4D::row_major( - _1, sx, _0, _0, - sy, _1, _0, _0, - _0, _0, _1, _0, - _0, _0, _0, _1 - ) - } - - /// Create a simple perspective projection matrix - pub fn create_perspective(d: T) -> TypedMatrix4D { - let (_0, _1): (T, T) = (Zero::zero(), One::one()); - TypedMatrix4D::row_major( - _1, _0, _0, _0, - _0, _1, _0, _0, - _0, _0, _1, -_1 / d, - _0, _0, _0, _1 - ) - } -} - -impl TypedMatrix4D { - /// Returns an array containing this matrix's terms in row-major order (the order - /// in which the matrix is actually laid out in memory). - pub fn to_row_major_array(&self) -> [T; 16] { - [ - self.m11, self.m12, self.m13, self.m14, - self.m21, self.m22, self.m23, self.m24, - self.m31, self.m32, self.m33, self.m34, - self.m41, self.m42, self.m43, self.m44 - ] - } - - /// Returns an array containing this matrix's terms in column-major order. - pub fn to_column_major_array(&self) -> [T; 16] { - [ - self.m11, self.m21, self.m31, self.m41, - self.m12, self.m22, self.m32, self.m42, - self.m13, self.m23, self.m33, self.m43, - self.m14, self.m24, self.m34, self.m44 - ] - } - - /// Returns an array containing this matrix's 4 rows in (in row-major order) - /// as arrays. - /// - /// This is a convenience method to interface with other libraries like glium. - pub fn to_row_arrays(&self) -> [[T; 4];4] { - [ - [self.m11, self.m12, self.m13, self.m14], - [self.m21, self.m22, self.m23, self.m24], - [self.m31, self.m32, self.m33, self.m34], - [self.m41, self.m42, self.m43, self.m44] - ] - } - - /// Returns an array containing this matrix's 4 columns in (in row-major order, - /// or 4 rows in column-major order) as arrays. - /// - /// This is a convenience method to interface with other libraries like glium. - pub fn to_column_arrays(&self) -> [[T; 4]; 4] { - [ - [self.m11, self.m21, self.m31, self.m41], - [self.m12, self.m22, self.m32, self.m42], - [self.m13, self.m23, self.m33, self.m43], - [self.m14, self.m24, self.m34, self.m44] - ] - } -} - -impl fmt::Debug for TypedMatrix4D -where T: Copy + fmt::Debug + - PartialEq + - One + Zero { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - if self.is_identity() { - write!(f, "[I]") - } else { - self.to_row_major_array().fmt(f) - } - } -} - -#[cfg(test)] -mod tests { - use approxeq::ApproxEq; - use matrix2d::Matrix2D; - use point::{Point2D, Point3D, Point4D}; - use Radians; - use super::*; - - use std::f32::consts::FRAC_PI_2; - - type Mf32 = Matrix4D; - - // For convenience. - fn rad(v: f32) -> Radians { Radians::new(v) } - - #[test] - pub fn test_translation() { - let t1 = Mf32::create_translation(1.0, 2.0, 3.0); - let t2 = Mf32::identity().pre_translated(1.0, 2.0, 3.0); - let t3 = Mf32::identity().post_translated(1.0, 2.0, 3.0); - assert_eq!(t1, t2); - assert_eq!(t1, t3); - - assert_eq!(t1.transform_point3d(&Point3D::new(1.0, 1.0, 1.0)), Point3D::new(2.0, 3.0, 4.0)); - assert_eq!(t1.transform_point(&Point2D::new(1.0, 1.0)), Point2D::new(2.0, 3.0)); - - assert_eq!(t1.post_mul(&t1), Mf32::create_translation(2.0, 4.0, 6.0)); - - assert!(!t1.is_2d()); - assert_eq!(Mf32::create_translation(1.0, 2.0, 3.0).to_2d(), Matrix2D::create_translation(1.0, 2.0)); - } - - #[test] - pub fn test_rotation() { - let r1 = Mf32::create_rotation(0.0, 0.0, 1.0, rad(FRAC_PI_2)); - let r2 = Mf32::identity().pre_rotated(0.0, 0.0, 1.0, rad(FRAC_PI_2)); - let r3 = Mf32::identity().post_rotated(0.0, 0.0, 1.0, rad(FRAC_PI_2)); - assert_eq!(r1, r2); - assert_eq!(r1, r3); - - assert!(r1.transform_point3d(&Point3D::new(1.0, 2.0, 3.0)).approx_eq(&Point3D::new(2.0, -1.0, 3.0))); - assert!(r1.transform_point(&Point2D::new(1.0, 2.0)).approx_eq(&Point2D::new(2.0, -1.0))); - - assert!(r1.post_mul(&r1).approx_eq(&Mf32::create_rotation(0.0, 0.0, 1.0, rad(FRAC_PI_2*2.0)))); - - assert!(r1.is_2d()); - assert!(r1.to_2d().approx_eq(&Matrix2D::create_rotation(rad(FRAC_PI_2)))); - } - - #[test] - pub fn test_scale() { - let s1 = Mf32::create_scale(2.0, 3.0, 4.0); - let s2 = Mf32::identity().pre_scaled(2.0, 3.0, 4.0); - let s3 = Mf32::identity().post_scaled(2.0, 3.0, 4.0); - assert_eq!(s1, s2); - assert_eq!(s1, s3); - - assert!(s1.transform_point3d(&Point3D::new(2.0, 2.0, 2.0)).approx_eq(&Point3D::new(4.0, 6.0, 8.0))); - assert!(s1.transform_point(&Point2D::new(2.0, 2.0)).approx_eq(&Point2D::new(4.0, 6.0))); - - assert_eq!(s1.post_mul(&s1), Mf32::create_scale(4.0, 9.0, 16.0)); - - assert!(!s1.is_2d()); - assert_eq!(Mf32::create_scale(2.0, 3.0, 0.0).to_2d(), Matrix2D::create_scale(2.0, 3.0)); - } - - #[test] - pub fn test_ortho() { - let (left, right, bottom, top) = (0.0f32, 1.0f32, 0.1f32, 1.0f32); - let (near, far) = (-1.0f32, 1.0f32); - let result = Mf32::ortho(left, right, bottom, top, near, far); - let expected = Mf32::row_major( - 2.0, 0.0, 0.0, 0.0, - 0.0, 2.22222222, 0.0, 0.0, - 0.0, 0.0, -1.0, 0.0, - -1.0, -1.22222222, -0.0, 1.0 - ); - debug!("result={:?} expected={:?}", result, expected); - assert!(result.approx_eq(&expected)); - } - - #[test] - pub fn test_is_2d() { - assert!(Mf32::identity().is_2d()); - assert!(Mf32::create_rotation(0.0, 0.0, 1.0, rad(0.7854)).is_2d()); - assert!(!Mf32::create_rotation(0.0, 1.0, 0.0, rad(0.7854)).is_2d()); - } - - #[test] - pub fn test_row_major_2d() { - let m1 = Mf32::row_major_2d(1.0, 2.0, 3.0, 4.0, 5.0, 6.0); - let m2 = Mf32::row_major( - 1.0, 2.0, 0.0, 0.0, - 3.0, 4.0, 0.0, 0.0, - 0.0, 0.0, 1.0, 0.0, - 5.0, 6.0, 0.0, 1.0 - ); - assert_eq!(m1, m2); - } - - #[test] - fn test_column_major() { - assert_eq!( - Mf32::row_major( - 1.0, 2.0, 3.0, 4.0, - 5.0, 6.0, 7.0, 8.0, - 9.0, 10.0, 11.0, 12.0, - 13.0, 14.0, 15.0, 16.0, - ), - Mf32::column_major( - 1.0, 5.0, 9.0, 13.0, - 2.0, 6.0, 10.0, 14.0, - 3.0, 7.0, 11.0, 15.0, - 4.0, 8.0, 12.0, 16.0, - ) - ); - } - - #[test] - pub fn test_inverse_simple() { - let m1 = Mf32::identity(); - let m2 = m1.inverse().unwrap(); - assert!(m1.approx_eq(&m2)); - } - - #[test] - pub fn test_inverse_scale() { - let m1 = Mf32::create_scale(1.5, 0.3, 2.1); - let m2 = m1.inverse().unwrap(); - assert!(m1.pre_mul(&m2).approx_eq(&Mf32::identity())); - } - - #[test] - pub fn test_inverse_translate() { - let m1 = Mf32::create_translation(-132.0, 0.3, 493.0); - let m2 = m1.inverse().unwrap(); - assert!(m1.pre_mul(&m2).approx_eq(&Mf32::identity())); - } - - #[test] - pub fn test_inverse_rotate() { - let m1 = Mf32::create_rotation(0.0, 1.0, 0.0, rad(1.57)); - let m2 = m1.inverse().unwrap(); - assert!(m1.pre_mul(&m2).approx_eq(&Mf32::identity())); - } - - #[test] - pub fn test_inverse_transform_point_2d() { - let m1 = Mf32::create_translation(100.0, 200.0, 0.0); - let m2 = m1.inverse().unwrap(); - assert!(m1.pre_mul(&m2).approx_eq(&Mf32::identity())); - - let p1 = Point2D::new(1000.0, 2000.0); - let p2 = m1.transform_point(&p1); - assert!(p2.eq(&Point2D::new(1100.0, 2200.0))); - - let p3 = m2.transform_point(&p2); - assert!(p3.eq(&p1)); - } - - #[test] - fn test_inverse_none() { - assert!(Mf32::create_scale(2.0, 0.0, 2.0).inverse().is_none()); - assert!(Mf32::create_scale(2.0, 2.0, 2.0).inverse().is_some()); - } - - #[test] - pub fn test_pre_post() { - let m1 = Matrix4D::identity().post_scaled(1.0, 2.0, 3.0).post_translated(1.0, 2.0, 3.0); - let m2 = Matrix4D::identity().pre_translated(1.0, 2.0, 3.0).pre_scaled(1.0, 2.0, 3.0); - assert!(m1.approx_eq(&m2)); - - let r = Mf32::create_rotation(0.0, 0.0, 1.0, rad(FRAC_PI_2)); - let t = Mf32::create_translation(2.0, 3.0, 0.0); - - let a = Point3D::new(1.0, 1.0, 1.0); - - assert!(r.post_mul(&t).transform_point3d(&a).approx_eq(&Point3D::new(3.0, 2.0, 1.0))); - assert!(t.post_mul(&r).transform_point3d(&a).approx_eq(&Point3D::new(4.0, -3.0, 1.0))); - assert!(t.post_mul(&r).transform_point3d(&a).approx_eq(&r.transform_point3d(&t.transform_point3d(&a)))); - - assert!(r.pre_mul(&t).transform_point3d(&a).approx_eq(&Point3D::new(4.0, -3.0, 1.0))); - assert!(t.pre_mul(&r).transform_point3d(&a).approx_eq(&Point3D::new(3.0, 2.0, 1.0))); - assert!(t.pre_mul(&r).transform_point3d(&a).approx_eq(&t.transform_point3d(&r.transform_point3d(&a)))); - } - - #[test] - fn test_size_of() { - use std::mem::size_of; - assert_eq!(size_of::>(), 16*size_of::()); - assert_eq!(size_of::>(), 16*size_of::()); - } - - #[test] - pub fn test_transform_associativity() { - let m1 = Mf32::row_major(3.0, 2.0, 1.5, 1.0, - 0.0, 4.5, -1.0, -4.0, - 0.0, 3.5, 2.5, 40.0, - 0.0, 3.0, 0.0, 1.0); - let m2 = Mf32::row_major(1.0, -1.0, 3.0, 0.0, - -1.0, 0.5, 0.0, 2.0, - 1.5, -2.0, 6.0, 0.0, - -2.5, 6.0, 1.0, 1.0); - - let p = Point4D::new(1.0, 3.0, 5.0, 1.0); - let p1 = m2.pre_mul(&m1).transform_point4d(&p); - let p2 = m2.transform_point4d(&m1.transform_point4d(&p)); - assert!(p1.approx_eq(&p2)); - } - - #[test] - pub fn test_is_identity() { - let m1 = Matrix4D::identity(); - assert!(m1.is_identity()); - let m2 = m1.post_translated(0.1, 0.0, 0.0); - assert!(!m2.is_identity()); - } -} diff --git a/third_party/rust/euclid-0.11.3/src/num.rs b/third_party/rust/euclid-0.11.3/src/num.rs deleted file mode 100644 index b612624273ed..000000000000 --- a/third_party/rust/euclid-0.11.3/src/num.rs +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright 2014 The Servo Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. -//! A one-dimensional length, tagged with its units. - -use num_traits; - - -pub trait Zero { - fn zero() -> Self; -} - -impl Zero for T { - fn zero() -> T { num_traits::Zero::zero() } -} - -pub trait One { - fn one() -> Self; -} - -impl One for T { - fn one() -> T { num_traits::One::one() } -} - -pub trait Round : Copy { fn round(self) -> Self; } -pub trait Floor : Copy { fn floor(self) -> Self; } -pub trait Ceil : Copy { fn ceil(self) -> Self; } - -impl Round for f32 { fn round(self) -> Self { self.round() } } -impl Round for f64 { fn round(self) -> Self { self.round() } } -impl Round for i16 { fn round(self) -> Self { self } } -impl Round for u16 { fn round(self) -> Self { self } } -impl Round for i32 { fn round(self) -> Self { self } } -impl Round for i64 { fn round(self) -> Self { self } } -impl Round for u32 { fn round(self) -> Self { self } } -impl Round for u64 { fn round(self) -> Self { self } } -impl Round for usize { fn round(self) -> Self { self } } -impl Round for isize { fn round(self) -> Self { self } } - -impl Floor for f32 { fn floor(self) -> Self { self.floor() } } -impl Floor for f64 { fn floor(self) -> Self { self.floor() } } -impl Floor for i16 { fn floor(self) -> Self { self } } -impl Floor for u16 { fn floor(self) -> Self { self } } -impl Floor for i32 { fn floor(self) -> Self { self } } -impl Floor for i64 { fn floor(self) -> Self { self } } -impl Floor for u32 { fn floor(self) -> Self { self } } -impl Floor for u64 { fn floor(self) -> Self { self } } -impl Floor for usize { fn floor(self) -> Self { self } } -impl Floor for isize { fn floor(self) -> Self { self } } - -impl Ceil for f32 { fn ceil(self) -> Self { self.ceil() } } -impl Ceil for f64 { fn ceil(self) -> Self { self.ceil() } } -impl Ceil for i16 { fn ceil(self) -> Self { self } } -impl Ceil for u16 { fn ceil(self) -> Self { self } } -impl Ceil for i32 { fn ceil(self) -> Self { self } } -impl Ceil for i64 { fn ceil(self) -> Self { self } } -impl Ceil for u32 { fn ceil(self) -> Self { self } } -impl Ceil for u64 { fn ceil(self) -> Self { self } } -impl Ceil for usize { fn ceil(self) -> Self { self } } -impl Ceil for isize { fn ceil(self) -> Self { self } } - diff --git a/third_party/rust/euclid-0.11.3/src/point.rs b/third_party/rust/euclid-0.11.3/src/point.rs deleted file mode 100644 index 6239fbe5181a..000000000000 --- a/third_party/rust/euclid-0.11.3/src/point.rs +++ /dev/null @@ -1,995 +0,0 @@ -// Copyright 2013 The Servo Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -use super::UnknownUnit; -use approxeq::ApproxEq; -use length::Length; -use scale_factor::ScaleFactor; -use size::TypedSize2D; -use num::*; -use num_traits::{Float, NumCast}; -use std::fmt; -use std::ops::{Add, Neg, Mul, Sub, Div}; -use std::marker::PhantomData; - -define_matrix! { - /// A 2d Point tagged with a unit. - #[derive(RustcDecodable, RustcEncodable)] - pub struct TypedPoint2D { - pub x: T, - pub y: T, - } -} - -/// Default 2d point type with no unit. -/// -/// `Point2D` provides the same methods as `TypedPoint2D`. -pub type Point2D = TypedPoint2D; - -impl TypedPoint2D { - /// Constructor, setting all components to zero. - #[inline] - pub fn zero() -> TypedPoint2D { - TypedPoint2D::new(Zero::zero(), Zero::zero()) - } - - /// Convert into a 3d point. - #[inline] - pub fn to_3d(&self) -> TypedPoint3D { - TypedPoint3D::new(self.x, self.y, Zero::zero()) - } -} - -impl fmt::Debug for TypedPoint2D { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "({:?},{:?})", self.x, self.y) - } -} - -impl fmt::Display for TypedPoint2D { - fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { - write!(formatter, "({},{})", self.x, self.y) - } -} - -impl TypedPoint2D { - /// Constructor taking scalar values directly. - #[inline] - pub fn new(x: T, y: T) -> TypedPoint2D { - TypedPoint2D { x: x, y: y, _unit: PhantomData } - } - - /// Constructor taking properly typed Lengths instead of scalar values. - #[inline] - pub fn from_lengths(x: Length, y: Length) -> TypedPoint2D { - TypedPoint2D::new(x.0, y.0) - } - - /// Returns self.x as a Length carrying the unit. - #[inline] - pub fn x_typed(&self) -> Length { Length::new(self.x) } - - /// Returns self.y as a Length carrying the unit. - #[inline] - pub fn y_typed(&self) -> Length { Length::new(self.y) } - - /// Drop the units, preserving only the numeric value. - #[inline] - pub fn to_untyped(&self) -> Point2D { - TypedPoint2D::new(self.x, self.y) - } - - /// Tag a unitless value with units. - #[inline] - pub fn from_untyped(p: &Point2D) -> TypedPoint2D { - TypedPoint2D::new(p.x, p.y) - } - - #[inline] - pub fn to_array(&self) -> [T; 2] { - [self.x, self.y] - } -} - -impl TypedPoint2D -where T: Copy + Mul + Add + Sub { - /// Dot product. - #[inline] - pub fn dot(self, other: TypedPoint2D) -> T { - self.x * other.x + self.y * other.y - } - - /// Returns the norm of the cross product [self.x, self.y, 0] x [other.x, other.y, 0].. - #[inline] - pub fn cross(self, other: TypedPoint2D) -> T { - self.x * other.y - self.y * other.x - } - - #[inline] - pub fn normalize(self) -> Self where T: Float + ApproxEq { - let dot = self.dot(self); - if dot.approx_eq(&T::zero()) { - self - } else { - self / dot.sqrt() - } - } -} - -impl, U> Add for TypedPoint2D { - type Output = TypedPoint2D; - fn add(self, other: TypedPoint2D) -> TypedPoint2D { - TypedPoint2D::new(self.x + other.x, self.y + other.y) - } -} - -impl, U> Add> for TypedPoint2D { - type Output = TypedPoint2D; - fn add(self, other: TypedSize2D) -> TypedPoint2D { - TypedPoint2D::new(self.x + other.width, self.y + other.height) - } -} - -impl, U> TypedPoint2D { - pub fn add_size(&self, other: &TypedSize2D) -> TypedPoint2D { - TypedPoint2D::new(self.x + other.width, self.y + other.height) - } -} - -impl, U> Sub for TypedPoint2D { - type Output = TypedPoint2D; - fn sub(self, other: TypedPoint2D) -> TypedPoint2D { - TypedPoint2D::new(self.x - other.x, self.y - other.y) - } -} - -impl , U> Neg for TypedPoint2D { - type Output = TypedPoint2D; - #[inline] - fn neg(self) -> TypedPoint2D { - TypedPoint2D::new(-self.x, -self.y) - } -} - -impl TypedPoint2D { - pub fn min(self, other: TypedPoint2D) -> TypedPoint2D { - TypedPoint2D::new(self.x.min(other.x), self.y.min(other.y)) - } - - pub fn max(self, other: TypedPoint2D) -> TypedPoint2D { - TypedPoint2D::new(self.x.max(other.x), self.y.max(other.y)) - } -} - -impl, U> Mul for TypedPoint2D { - type Output = TypedPoint2D; - #[inline] - fn mul(self, scale: T) -> TypedPoint2D { - TypedPoint2D::new(self.x * scale, self.y * scale) - } -} - -impl, U> Div for TypedPoint2D { - type Output = TypedPoint2D; - #[inline] - fn div(self, scale: T) -> TypedPoint2D { - TypedPoint2D::new(self.x / scale, self.y / scale) - } -} - -impl, U1, U2> Mul> for TypedPoint2D { - type Output = TypedPoint2D; - #[inline] - fn mul(self, scale: ScaleFactor) -> TypedPoint2D { - TypedPoint2D::new(self.x * scale.get(), self.y * scale.get()) - } -} - -impl, U1, U2> Div> for TypedPoint2D { - type Output = TypedPoint2D; - #[inline] - fn div(self, scale: ScaleFactor) -> TypedPoint2D { - TypedPoint2D::new(self.x / scale.get(), self.y / scale.get()) - } -} - -impl TypedPoint2D { - /// Rounds each component to the nearest integer value. - /// - /// This behavior is preserved for negative values (unlike the basic cast). - /// For example `{ -0.1, -0.8 }.round() == { 0.0, -1.0 }`. - pub fn round(&self) -> Self { - TypedPoint2D::new(self.x.round(), self.y.round()) - } -} - -impl TypedPoint2D { - /// Rounds each component to the smallest integer equal or greater than the original value. - /// - /// This behavior is preserved for negative values (unlike the basic cast). - /// For example `{ -0.1, -0.8 }.ceil() == { 0.0, 0.0 }`. - pub fn ceil(&self) -> Self { - TypedPoint2D::new(self.x.ceil(), self.y.ceil()) - } -} - -impl TypedPoint2D { - /// Rounds each component to the biggest integer equal or lower than the original value. - /// - /// This behavior is preserved for negative values (unlike the basic cast). - /// For example `{ -0.1, -0.8 }.floor() == { -1.0, -1.0 }`. - pub fn floor(&self) -> Self { - TypedPoint2D::new(self.x.floor(), self.y.floor()) - } -} - -impl TypedPoint2D { - /// Cast from one numeric representation to another, preserving the units. - /// - /// When casting from floating point to integer coordinates, the decimals are truncated - /// as one would expect from a simple cast, but this behavior does not always make sense - /// geometrically. Consider using `round()`, `ceil()` or `floor()` before casting. - pub fn cast(&self) -> Option> { - match (NumCast::from(self.x), NumCast::from(self.y)) { - (Some(x), Some(y)) => Some(TypedPoint2D::new(x, y)), - _ => None - } - } - - // Convenience functions for common casts - - /// Cast into an `f32` point. - pub fn to_f32(&self) -> TypedPoint2D { - self.cast().unwrap() - } - - /// Cast into an `usize` point, truncating decimals if any. - /// - /// When casting from floating point points, it is worth considering whether - /// to `round()`, `ceil()` or `floor()` before the cast in order to obtain - /// the desired conversion behavior. - pub fn to_uint(&self) -> TypedPoint2D { - self.cast().unwrap() - } - - /// Cast into an i32 point, truncating decimals if any. - /// - /// When casting from floating point points, it is worth considering whether - /// to `round()`, `ceil()` or `floor()` before the cast in order to obtain - /// the desired conversion behavior. - pub fn to_i32(&self) -> TypedPoint2D { - self.cast().unwrap() - } - - /// Cast into an i64 point, truncating decimals if any. - /// - /// When casting from floating point points, it is worth considering whether - /// to `round()`, `ceil()` or `floor()` before the cast in order to obtain - /// the desired conversion behavior. - pub fn to_i64(&self) -> TypedPoint2D { - self.cast().unwrap() - } -} - -impl, U> ApproxEq> for TypedPoint2D { - #[inline] - fn approx_epsilon() -> Self { - TypedPoint2D::new(T::approx_epsilon(), T::approx_epsilon()) - } - - #[inline] - fn approx_eq(&self, other: &Self) -> bool { - self.x.approx_eq(&other.x) && self.y.approx_eq(&other.y) - } - - #[inline] - fn approx_eq_eps(&self, other: &Self, eps: &Self) -> bool { - self.x.approx_eq_eps(&other.x, &eps.x) && self.y.approx_eq_eps(&other.y, &eps.y) - } -} - -define_matrix! { - /// A 3d Point tagged with a unit. - #[derive(RustcDecodable, RustcEncodable)] - pub struct TypedPoint3D { - pub x: T, - pub y: T, - pub z: T, - } -} - -/// Default 3d point type with no unit. -/// -/// `Point3D` provides the same methods as `TypedPoint3D`. -pub type Point3D = TypedPoint3D; - -impl TypedPoint3D { - /// Constructor, setting all copmonents to zero. - #[inline] - pub fn zero() -> TypedPoint3D { - TypedPoint3D::new(Zero::zero(), Zero::zero(), Zero::zero()) - } -} - -impl fmt::Debug for TypedPoint3D { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "({:?},{:?},{:?})", self.x, self.y, self.z) - } -} - -impl fmt::Display for TypedPoint3D { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "({},{},{})", self.x, self.y, self.z) - } -} - -impl TypedPoint3D { - /// Constructor taking scalar values directly. - #[inline] - pub fn new(x: T, y: T, z: T) -> TypedPoint3D { - TypedPoint3D { x: x, y: y, z: z, _unit: PhantomData } - } - - /// Constructor taking properly typed Lengths instead of scalar values. - #[inline] - pub fn from_lengths(x: Length, y: Length, z: Length) -> TypedPoint3D { - TypedPoint3D::new(x.0, y.0, z.0) - } - - /// Returns self.x as a Length carrying the unit. - #[inline] - pub fn x_typed(&self) -> Length { Length::new(self.x) } - - /// Returns self.y as a Length carrying the unit. - #[inline] - pub fn y_typed(&self) -> Length { Length::new(self.y) } - - /// Returns self.z as a Length carrying the unit. - #[inline] - pub fn z_typed(&self) -> Length { Length::new(self.z) } - - #[inline] - pub fn to_array(&self) -> [T; 3] { [self.x, self.y, self.z] } - - /// Drop the units, preserving only the numeric value. - #[inline] - pub fn to_untyped(&self) -> Point3D { - TypedPoint3D::new(self.x, self.y, self.z) - } - - /// Tag a unitless value with units. - #[inline] - pub fn from_untyped(p: &Point3D) -> TypedPoint3D { - TypedPoint3D::new(p.x, p.y, p.z) - } - - /// Convert into a 2d point. - #[inline] - pub fn to_2d(&self) -> TypedPoint2D { - TypedPoint2D::new(self.x, self.y) - } -} - -impl + - Add + - Sub + - Copy, U> TypedPoint3D { - - // Dot product. - #[inline] - pub fn dot(self, other: TypedPoint3D) -> T { - self.x * other.x + - self.y * other.y + - self.z * other.z - } - - // Cross product. - #[inline] - pub fn cross(self, other: TypedPoint3D) -> TypedPoint3D { - TypedPoint3D::new(self.y * other.z - self.z * other.y, - self.z * other.x - self.x * other.z, - self.x * other.y - self.y * other.x) - } - - #[inline] - pub fn normalize(self) -> Self where T: Float + ApproxEq { - let dot = self.dot(self); - if dot.approx_eq(&T::zero()) { - self - } else { - self / dot.sqrt() - } - } -} - -impl, U> Add for TypedPoint3D { - type Output = TypedPoint3D; - fn add(self, other: TypedPoint3D) -> TypedPoint3D { - TypedPoint3D::new(self.x + other.x, - self.y + other.y, - self.z + other.z) - } -} - -impl, U> Sub for TypedPoint3D { - type Output = TypedPoint3D; - fn sub(self, other: TypedPoint3D) -> TypedPoint3D { - TypedPoint3D::new(self.x - other.x, - self.y - other.y, - self.z - other.z) - } -} - -impl , U> Neg for TypedPoint3D { - type Output = TypedPoint3D; - #[inline] - fn neg(self) -> TypedPoint3D { - TypedPoint3D::new(-self.x, -self.y, -self.z) - } -} - -impl, U> Mul for TypedPoint3D { - type Output = Self; - #[inline] - fn mul(self, scale: T) -> Self { - Self::new(self.x * scale, self.y * scale, self.z * scale) - } -} - -impl, U> Div for TypedPoint3D { - type Output = Self; - #[inline] - fn div(self, scale: T) -> Self { - Self::new(self.x / scale, self.y / scale, self.z / scale) - } -} - -impl TypedPoint3D { - pub fn min(self, other: TypedPoint3D) -> TypedPoint3D { - TypedPoint3D::new(self.x.min(other.x), - self.y.min(other.y), - self.z.min(other.z)) - } - - pub fn max(self, other: TypedPoint3D) -> TypedPoint3D { - TypedPoint3D::new(self.x.max(other.x), self.y.max(other.y), - self.z.max(other.z)) - } -} - -impl TypedPoint3D { - /// Rounds each component to the nearest integer value. - /// - /// This behavior is preserved for negative values (unlike the basic cast). - pub fn round(&self) -> Self { - TypedPoint3D::new(self.x.round(), self.y.round(), self.z.round()) - } -} - -impl TypedPoint3D { - /// Rounds each component to the smallest integer equal or greater than the original value. - /// - /// This behavior is preserved for negative values (unlike the basic cast). - pub fn ceil(&self) -> Self { - TypedPoint3D::new(self.x.ceil(), self.y.ceil(), self.z.ceil()) - } -} - -impl TypedPoint3D { - /// Rounds each component to the biggest integer equal or lower than the original value. - /// - /// This behavior is preserved for negative values (unlike the basic cast). - pub fn floor(&self) -> Self { - TypedPoint3D::new(self.x.floor(), self.y.floor(), self.z.floor()) - } -} - -impl TypedPoint3D { - /// Cast from one numeric representation to another, preserving the units. - /// - /// When casting from floating point to integer coordinates, the decimals are truncated - /// as one would expect from a simple cast, but this behavior does not always make sense - /// geometrically. Consider using round(), ceil or floor() before casting. - pub fn cast(&self) -> Option> { - match (NumCast::from(self.x), - NumCast::from(self.y), - NumCast::from(self.z)) { - (Some(x), Some(y), Some(z)) => Some(TypedPoint3D::new(x, y, z)), - _ => None - } - } - - // Convenience functions for common casts - - /// Cast into an `f32` point. - pub fn to_f32(&self) -> TypedPoint3D { - self.cast().unwrap() - } - - /// Cast into an `usize` point, truncating decimals if any. - /// - /// When casting from floating point points, it is worth considering whether - /// to `round()`, `ceil()` or `floor()` before the cast in order to obtain - /// the desired conversion behavior. - pub fn to_uint(&self) -> TypedPoint3D { - self.cast().unwrap() - } - - /// Cast into an `i32` point, truncating decimals if any. - /// - /// When casting from floating point points, it is worth considering whether - /// to `round()`, `ceil()` or `floor()` before the cast in order to obtain - /// the desired conversion behavior. - pub fn to_i32(&self) -> TypedPoint3D { - self.cast().unwrap() - } - - /// Cast into an `i64` point, truncating decimals if any. - /// - /// When casting from floating point points, it is worth considering whether - /// to `round()`, `ceil()` or `floor()` before the cast in order to obtain - /// the desired conversion behavior. - pub fn to_i64(&self) -> TypedPoint3D { - self.cast().unwrap() - } -} - -impl, U> ApproxEq> for TypedPoint3D { - #[inline] - fn approx_epsilon() -> Self { - TypedPoint3D::new(T::approx_epsilon(), T::approx_epsilon(), T::approx_epsilon()) - } - - #[inline] - fn approx_eq(&self, other: &Self) -> bool { - self.x.approx_eq(&other.x) - && self.y.approx_eq(&other.y) - && self.z.approx_eq(&other.z) - } - - #[inline] - fn approx_eq_eps(&self, other: &Self, eps: &Self) -> bool { - self.x.approx_eq_eps(&other.x, &eps.x) - && self.y.approx_eq_eps(&other.y, &eps.y) - && self.z.approx_eq_eps(&other.z, &eps.z) - } -} - -define_matrix! { - /// A 4d Point tagged with a unit. - #[derive(RustcDecodable, RustcEncodable)] - pub struct TypedPoint4D { - pub x: T, - pub y: T, - pub z: T, - pub w: T, - } -} - -/// Default 4d point with no unit. -/// -/// `Point4D` provides the same methods as `TypedPoint4D`. -pub type Point4D = TypedPoint4D; - -impl TypedPoint4D { - /// Constructor, setting all copmonents to zero. - #[inline] - pub fn zero() -> TypedPoint4D { - TypedPoint4D::new(Zero::zero(), Zero::zero(), Zero::zero(), Zero::zero()) - } -} - -impl fmt::Debug for TypedPoint4D { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "({:?},{:?},{:?},{:?})", self.x, self.y, self.z, self.w) - } -} - -impl fmt::Display for TypedPoint4D { - fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { - write!(formatter, "({},{},{},{})", self.x, self.y, self.z, self.w) - } -} - -impl TypedPoint4D { - /// Constructor taking scalar values directly. - #[inline] - pub fn new(x: T, y: T, z: T, w: T) -> TypedPoint4D { - TypedPoint4D { x: x, y: y, z: z, w: w, _unit: PhantomData } - } - - /// Constructor taking properly typed Lengths instead of scalar values. - #[inline] - pub fn from_lengths(x: Length, - y: Length, - z: Length, - w: Length) -> TypedPoint4D { - TypedPoint4D::new(x.0, y.0, z.0, w.0) - } - - /// Returns self.x as a Length carrying the unit. - #[inline] - pub fn x_typed(&self) -> Length { Length::new(self.x) } - - /// Returns self.y as a Length carrying the unit. - #[inline] - pub fn y_typed(&self) -> Length { Length::new(self.y) } - - /// Returns self.z as a Length carrying the unit. - #[inline] - pub fn z_typed(&self) -> Length { Length::new(self.z) } - - /// Returns self.w as a Length carrying the unit. - #[inline] - pub fn w_typed(&self) -> Length { Length::new(self.w) } - - /// Drop the units, preserving only the numeric value. - #[inline] - pub fn to_untyped(&self) -> Point4D { - TypedPoint4D::new(self.x, self.y, self.z, self.w) - } - - /// Tag a unitless value with units. - #[inline] - pub fn from_untyped(p: &Point4D) -> TypedPoint4D { - TypedPoint4D::new(p.x, p.y, p.z, p.w) - } - - #[inline] - pub fn to_array(&self) -> [T; 4] { - [self.x, self.y, self.z, self.w] - } -} - -impl, U> TypedPoint4D { - /// Convert into a 2d point. - #[inline] - pub fn to_2d(self) -> TypedPoint2D { - TypedPoint2D::new(self.x / self.w, self.y / self.w) - } - - /// Convert into a 3d point. - #[inline] - pub fn to_3d(self) -> TypedPoint3D { - TypedPoint3D::new(self.x / self.w, self.y / self.w, self.z / self.w) - } -} - -impl, U> Add for TypedPoint4D { - type Output = TypedPoint4D; - fn add(self, other: TypedPoint4D) -> TypedPoint4D { - TypedPoint4D::new(self.x + other.x, - self.y + other.y, - self.z + other.z, - self.w + other.w) - } -} - -impl, U> Sub for TypedPoint4D { - type Output = TypedPoint4D; - fn sub(self, other: TypedPoint4D) -> TypedPoint4D { - TypedPoint4D::new(self.x - other.x, - self.y - other.y, - self.z - other.z, - self.w - other.w) - } -} - -impl , U> Neg for TypedPoint4D { - type Output = TypedPoint4D; - #[inline] - fn neg(self) -> TypedPoint4D { - TypedPoint4D::new(-self.x, -self.y, -self.z, -self.w) - } -} - -impl TypedPoint4D { - pub fn min(self, other: TypedPoint4D) -> TypedPoint4D { - TypedPoint4D::new(self.x.min(other.x), self.y.min(other.y), - self.z.min(other.z), self.w.min(other.w)) - } - - pub fn max(self, other: TypedPoint4D) -> TypedPoint4D { - TypedPoint4D::new(self.x.max(other.x), self.y.max(other.y), - self.z.max(other.z), self.w.max(other.w)) - } -} - -impl TypedPoint4D { - /// Rounds each component to the nearest integer value. - /// - /// This behavior is preserved for negative values (unlike the basic cast). - pub fn round(&self) -> Self { - TypedPoint4D::new(self.x.round(), self.y.round(), self.z.round(), self.w.round()) - } -} - -impl TypedPoint4D { - /// Rounds each component to the smallest integer equal or greater than the original value. - /// - /// This behavior is preserved for negative values (unlike the basic cast). - pub fn ceil(&self) -> Self { - TypedPoint4D::new(self.x.ceil(), self.y.ceil(), self.z.ceil(), self.w.ceil()) - } -} - -impl TypedPoint4D { - /// Rounds each component to the biggest integer equal or lower than the original value. - /// - /// This behavior is preserved for negative values (unlike the basic cast). - pub fn floor(&self) -> Self { - TypedPoint4D::new(self.x.floor(), self.y.floor(), self.z.floor(), self.w.floor()) - } -} - -impl TypedPoint4D { - /// Cast from one numeric representation to another, preserving the units. - /// - /// When casting from floating point to integer coordinates, the decimals are truncated - /// as one would expect from a simple cast, but this behavior does not always make sense - /// geometrically. Consider using `round()`, `ceil()` or `floor()` before casting. - pub fn cast(&self) -> Option> { - match (NumCast::from(self.x), - NumCast::from(self.y), - NumCast::from(self.z), - NumCast::from(self.w)) { - (Some(x), Some(y), Some(z), Some(w)) => Some(TypedPoint4D::new(x, y, z, w)), - _ => None - } - } - - // Convenience functions for common casts - - /// Cast into an `f32` point. - pub fn to_f32(&self) -> TypedPoint4D { - self.cast().unwrap() - } - - /// Cast into an `usize` point, truncating decimals if any. - /// - /// When casting from floating point points, it is worth considering whether - /// to `round()`, `ceil()` or `floor()` before the cast in order to obtain - /// the desired conversion behavior. - pub fn to_uint(&self) -> TypedPoint4D { - self.cast().unwrap() - } - - /// Cast into an `i32` point, truncating decimals if any. - /// - /// When casting from floating point points, it is worth considering whether - /// to `round()`, `ceil()` or `floor()` before the cast in order to obtain - /// the desired conversion behavior. - pub fn to_i32(&self) -> TypedPoint4D { - self.cast().unwrap() - } - - /// Cast into an `i64` point, truncating decimals if any. - /// - /// When casting from floating point points, it is worth considering whether - /// to `round()`, `ceil()` or `floor()` before the cast in order to obtain - /// the desired conversion behavior. - pub fn to_i64(&self) -> TypedPoint4D { - self.cast().unwrap() - } -} - -impl, U> ApproxEq for TypedPoint4D { - fn approx_epsilon() -> T { - T::approx_epsilon() - } - - fn approx_eq_eps(&self, other: &Self, approx_epsilon: &T) -> bool { - self.x.approx_eq_eps(&other.x, approx_epsilon) - && self.y.approx_eq_eps(&other.y, approx_epsilon) - && self.z.approx_eq_eps(&other.z, approx_epsilon) - && self.w.approx_eq_eps(&other.w, approx_epsilon) - } - - fn approx_eq(&self, other: &Self) -> bool { - self.approx_eq_eps(&other, &Self::approx_epsilon()) - } -} - -pub fn point2(x: T, y: T) -> TypedPoint2D { - TypedPoint2D::new(x, y) -} - -pub fn point3(x: T, y: T, z: T) -> TypedPoint3D { - TypedPoint3D::new(x, y, z) -} - -pub fn point4(x: T, y: T, z: T, w: T) -> TypedPoint4D { - TypedPoint4D::new(x, y, z, w) -} - -#[cfg(test)] -mod point2d { - use super::Point2D; - - #[test] - pub fn test_scalar_mul() { - let p1: Point2D = Point2D::new(3.0, 5.0); - - let result = p1 * 5.0; - - assert_eq!(result, Point2D::new(15.0, 25.0)); - } - - #[test] - pub fn test_dot() { - let p1: Point2D = Point2D::new(2.0, 7.0); - let p2: Point2D = Point2D::new(13.0, 11.0); - assert_eq!(p1.dot(p2), 103.0); - } - - #[test] - pub fn test_cross() { - let p1: Point2D = Point2D::new(4.0, 7.0); - let p2: Point2D = Point2D::new(13.0, 8.0); - let r = p1.cross(p2); - assert_eq!(r, -59.0); - } - - #[test] - pub fn test_normalize() { - let p0: Point2D = Point2D::zero(); - let p1: Point2D = Point2D::new(4.0, 0.0); - let p2: Point2D = Point2D::new(3.0, -4.0); - assert_eq!(p0.normalize(), p0); - assert_eq!(p1.normalize(), Point2D::new(1.0, 0.0)); - assert_eq!(p2.normalize(), Point2D::new(0.6, -0.8)); - } - - #[test] - pub fn test_min() { - let p1 = Point2D::new(1.0, 3.0); - let p2 = Point2D::new(2.0, 2.0); - - let result = p1.min(p2); - - assert_eq!(result, Point2D::new(1.0, 2.0)); - } - - #[test] - pub fn test_max() { - let p1 = Point2D::new(1.0, 3.0); - let p2 = Point2D::new(2.0, 2.0); - - let result = p1.max(p2); - - assert_eq!(result, Point2D::new(2.0, 3.0)); - } -} - -#[cfg(test)] -mod typedpoint2d { - use super::TypedPoint2D; - use scale_factor::ScaleFactor; - - pub enum Mm {} - pub enum Cm {} - - pub type Point2DMm = TypedPoint2D; - pub type Point2DCm = TypedPoint2D; - - #[test] - pub fn test_add() { - let p1 = Point2DMm::new(1.0, 2.0); - let p2 = Point2DMm::new(3.0, 4.0); - - let result = p1 + p2; - - assert_eq!(result, Point2DMm::new(4.0, 6.0)); - } - - #[test] - pub fn test_scalar_mul() { - let p1 = Point2DMm::new(1.0, 2.0); - let cm_per_mm: ScaleFactor = ScaleFactor::new(0.1); - - let result = p1 * cm_per_mm; - - assert_eq!(result, Point2DCm::new(0.1, 0.2)); - } -} - -#[cfg(test)] -mod point3d { - use super::Point3D; - - #[test] - pub fn test_dot() { - let p1 = Point3D::new(7.0, 21.0, 32.0); - let p2 = Point3D::new(43.0, 5.0, 16.0); - assert_eq!(p1.dot(p2), 918.0); - } - - #[test] - pub fn test_cross() { - let p1 = Point3D::new(4.0, 7.0, 9.0); - let p2 = Point3D::new(13.0, 8.0, 3.0); - let p3 = p1.cross(p2); - assert_eq!(p3, Point3D::new(-51.0, 105.0, -59.0)); - } - - #[test] - pub fn test_normalize() { - let p0: Point3D = Point3D::zero(); - let p1: Point3D = Point3D::new(0.0, -6.0, 0.0); - let p2: Point3D = Point3D::new(1.0, 2.0, -2.0); - assert_eq!(p0.normalize(), p0); - assert_eq!(p1.normalize(), Point3D::new(0.0, -1.0, 0.0)); - assert_eq!(p2.normalize(), Point3D::new(1.0/3.0, 2.0/3.0, -2.0/3.0)); - } - - #[test] - pub fn test_min() { - let p1 = Point3D::new(1.0, 3.0, 5.0); - let p2 = Point3D::new(2.0, 2.0, -1.0); - - let result = p1.min(p2); - - assert_eq!(result, Point3D::new(1.0, 2.0, -1.0)); - } - - #[test] - pub fn test_max() { - let p1 = Point3D::new(1.0, 3.0, 5.0); - let p2 = Point3D::new(2.0, 2.0, -1.0); - - let result = p1.max(p2); - - assert_eq!(result, Point3D::new(2.0, 3.0, 5.0)); - } -} - -#[cfg(test)] -mod point4d { - use super::Point4D; - - #[test] - pub fn test_add() { - let p1 = Point4D::new(7.0, 21.0, 32.0, 1.0); - let p2 = Point4D::new(43.0, 5.0, 16.0, 2.0); - - let result = p1 + p2; - - assert_eq!(result, Point4D::new(50.0, 26.0, 48.0, 3.0)); - } - - #[test] - pub fn test_sub() { - let p1 = Point4D::new(7.0, 21.0, 32.0, 1.0); - let p2 = Point4D::new(43.0, 5.0, 16.0, 2.0); - - let result = p1 - p2; - - assert_eq!(result, Point4D::new(-36.0, 16.0, 16.0, -1.0)); - } - - #[test] - pub fn test_min() { - let p1 = Point4D::new(1.0, 3.0, 5.0, 7.0); - let p2 = Point4D::new(2.0, 2.0, -1.0, 10.0); - - let result = p1.min(p2); - - assert_eq!(result, Point4D::new(1.0, 2.0, -1.0, 7.0)); - } - - #[test] - pub fn test_max() { - let p1 = Point4D::new(1.0, 3.0, 5.0, 7.0); - let p2 = Point4D::new(2.0, 2.0, -1.0, 10.0); - - let result = p1.max(p2); - - assert_eq!(result, Point4D::new(2.0, 3.0, 5.0, 10.0)); - } -} diff --git a/third_party/rust/euclid-0.11.3/src/rect.rs b/third_party/rust/euclid-0.11.3/src/rect.rs deleted file mode 100644 index 835c1b50c911..000000000000 --- a/third_party/rust/euclid-0.11.3/src/rect.rs +++ /dev/null @@ -1,671 +0,0 @@ -// Copyright 2013 The Servo Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -use super::UnknownUnit; -use length::Length; -use scale_factor::ScaleFactor; -use num::*; -use point::TypedPoint2D; -use size::TypedSize2D; - -use heapsize::HeapSizeOf; -use num_traits::NumCast; -use serde::{Deserialize, Deserializer, Serialize, Serializer}; -use std::cmp::PartialOrd; -use std::fmt; -use std::ops::{Add, Sub, Mul, Div}; - -/// A 2d Rectangle optionally tagged with a unit. -#[derive(RustcDecodable, RustcEncodable)] -pub struct TypedRect { - pub origin: TypedPoint2D, - pub size: TypedSize2D, -} - -/// The default rectangle type with no unit. -pub type Rect = TypedRect; - -impl HeapSizeOf for TypedRect { - fn heap_size_of_children(&self) -> usize { - self.origin.heap_size_of_children() + self.size.heap_size_of_children() - } -} - -impl Deserialize for TypedRect { - fn deserialize(deserializer: D) -> Result - where D: Deserializer - { - let (origin, size) = try!(Deserialize::deserialize(deserializer)); - Ok(TypedRect::new(origin, size)) - } -} - -impl Serialize for TypedRect { - fn serialize(&self, serializer: S) -> Result - where S: Serializer - { - (&self.origin, &self.size).serialize(serializer) - } -} - -impl Copy for TypedRect {} - -impl Clone for TypedRect { - fn clone(&self) -> TypedRect { *self } -} - -impl PartialEq> for TypedRect { - fn eq(&self, other: &TypedRect) -> bool { - self.origin.eq(&other.origin) && self.size.eq(&other.size) - } -} - -impl Eq for TypedRect {} - -impl fmt::Debug for TypedRect { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "TypedRect({:?} at {:?})", self.size, self.origin) - } -} - -impl fmt::Display for TypedRect { - fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { - write!(formatter, "Rect({} at {})", self.size, self.origin) - } -} - -impl TypedRect { - /// Constructor. - pub fn new(origin: TypedPoint2D, size: TypedSize2D) -> TypedRect { - TypedRect { - origin: origin, - size: size, - } - } -} - -impl TypedRect -where T: Copy + Clone + Zero + PartialOrd + PartialEq + Add + Sub { - #[inline] - pub fn intersects(&self, other: &TypedRect) -> bool { - self.origin.x < other.origin.x + other.size.width && - other.origin.x < self.origin.x + self.size.width && - self.origin.y < other.origin.y + other.size.height && - other.origin.y < self.origin.y + self.size.height - } - - #[inline] - pub fn max_x(&self) -> T { - self.origin.x + self.size.width - } - - #[inline] - pub fn min_x(&self) -> T { - self.origin.x - } - - #[inline] - pub fn max_y(&self) -> T { - self.origin.y + self.size.height - } - - #[inline] - pub fn min_y(&self) -> T { - self.origin.y - } - - #[inline] - pub fn max_x_typed(&self) -> Length { - Length::new(self.max_x()) - } - - #[inline] - pub fn min_x_typed(&self) -> Length { - Length::new(self.min_x()) - } - - #[inline] - pub fn max_y_typed(&self) -> Length { - Length::new(self.max_y()) - } - - #[inline] - pub fn min_y_typed(&self) -> Length { - Length::new(self.min_y()) - } - - #[inline] - pub fn intersection(&self, other: &TypedRect) -> Option> { - if !self.intersects(other) { - return None; - } - - let upper_left = TypedPoint2D::new(max(self.min_x(), other.min_x()), - max(self.min_y(), other.min_y())); - let lower_right_x = min(self.max_x(), other.max_x()); - let lower_right_y = min(self.max_y(), other.max_y()); - - Some(TypedRect::new(upper_left, TypedSize2D::new(lower_right_x - upper_left.x, - lower_right_y - upper_left.y))) - } - - /// Translates the rect by a vector. - #[inline] - pub fn translate(&self, other: &TypedPoint2D) -> TypedRect { - TypedRect::new( - TypedPoint2D::new(self.origin.x + other.x, self.origin.y + other.y), - self.size - ) - } - - /// Returns true if this rectangle contains the point. Points are considered - /// in the rectangle if they are on the left or top edge, but outside if they - /// are on the right or bottom edge. - #[inline] - pub fn contains(&self, other: &TypedPoint2D) -> bool { - self.origin.x <= other.x && other.x < self.origin.x + self.size.width && - self.origin.y <= other.y && other.y < self.origin.y + self.size.height - } - - /// Returns true if this rectangle contains the interior of rect. Always - /// returns true if rect is empty, and always returns false if rect is - /// nonempty but this rectangle is empty. - #[inline] - pub fn contains_rect(&self, rect: &TypedRect) -> bool { - rect.is_empty() || - (self.min_x() <= rect.min_x() && rect.max_x() <= self.max_x() && - self.min_y() <= rect.min_y() && rect.max_y() <= self.max_y()) - } - - #[inline] - pub fn inflate(&self, width: T, height: T) -> TypedRect { - TypedRect::new( - TypedPoint2D::new(self.origin.x - width, self.origin.y - height), - TypedSize2D::new(self.size.width + width + width, self.size.height + height + height), - ) - } - - #[inline] - pub fn inflate_typed(&self, width: Length, height: Length) -> TypedRect { - self.inflate(width.get(), height.get()) - } - - #[inline] - pub fn top_right(&self) -> TypedPoint2D { - TypedPoint2D::new(self.max_x(), self.origin.y) - } - - #[inline] - pub fn bottom_left(&self) -> TypedPoint2D { - TypedPoint2D::new(self.origin.x, self.max_y()) - } - - #[inline] - pub fn bottom_right(&self) -> TypedPoint2D { - TypedPoint2D::new(self.max_x(), self.max_y()) - } - - #[inline] - pub fn translate_by_size(&self, size: &TypedSize2D) -> TypedRect { - self.translate(&TypedPoint2D::new(size.width, size.height)) - } - - /// Returns the smallest rectangle containing the four points. - pub fn from_points(points: &[TypedPoint2D]) -> Self { - if points.len() == 0 { - return TypedRect::zero(); - } - let (mut min_x, mut min_y) = (points[0].x, points[0].y); - let (mut max_x, mut max_y) = (min_x, min_y); - for point in &points[1..] { - if point.x < min_x { - min_x = point.x - } - if point.x > max_x { - max_x = point.x - } - if point.y < min_y { - min_y = point.y - } - if point.y > max_y { - max_y = point.y - } - } - TypedRect::new(TypedPoint2D::new(min_x, min_y), - TypedSize2D::new(max_x - min_x, max_y - min_y)) - } -} - -impl TypedRect -where T: Copy + Clone + PartialOrd + Add + Sub + Zero { - #[inline] - pub fn union(&self, other: &TypedRect) -> TypedRect { - if self.size == Zero::zero() { - return *other; - } - if other.size == Zero::zero() { - return *self; - } - - let upper_left = TypedPoint2D::new(min(self.min_x(), other.min_x()), - min(self.min_y(), other.min_y())); - - let lower_right_x = max(self.max_x(), other.max_x()); - let lower_right_y = max(self.max_y(), other.max_y()); - - TypedRect::new( - upper_left, - TypedSize2D::new(lower_right_x - upper_left.x, lower_right_y - upper_left.y) - ) - } -} - -impl TypedRect { - #[inline] - pub fn scale(&self, x: Scale, y: Scale) -> TypedRect - where T: Copy + Clone + Mul { - TypedRect::new( - TypedPoint2D::new(self.origin.x * x, self.origin.y * y), - TypedSize2D::new(self.size.width * x, self.size.height * y) - ) - } -} - -impl TypedRect { - /// Constructor, setting all sides to zero. - pub fn zero() -> TypedRect { - TypedRect::new( - TypedPoint2D::zero(), - TypedSize2D::zero(), - ) - } - - /// Returns true if the size is zero, regardless of the origin's value. - pub fn is_empty(&self) -> bool { - self.size.width == Zero::zero() || self.size.height == Zero::zero() - } -} - - -pub fn min(x: T, y: T) -> T { - if x <= y { x } else { y } -} - -pub fn max(x: T, y: T) -> T { - if x >= y { x } else { y } -} - -impl, U> Mul for TypedRect { - type Output = TypedRect; - #[inline] - fn mul(self, scale: T) -> TypedRect { - TypedRect::new(self.origin * scale, self.size * scale) - } -} - -impl, U> Div for TypedRect { - type Output = TypedRect; - #[inline] - fn div(self, scale: T) -> TypedRect { - TypedRect::new(self.origin / scale, self.size / scale) - } -} - -impl, U1, U2> Mul> for TypedRect { - type Output = TypedRect; - #[inline] - fn mul(self, scale: ScaleFactor) -> TypedRect { - TypedRect::new(self.origin * scale, self.size * scale) - } -} - -impl, U1, U2> Div> for TypedRect { - type Output = TypedRect; - #[inline] - fn div(self, scale: ScaleFactor) -> TypedRect { - TypedRect::new(self.origin / scale, self.size / scale) - } -} - -impl TypedRect { - /// Drop the units, preserving only the numeric value. - pub fn to_untyped(&self) -> Rect { - TypedRect::new(self.origin.to_untyped(), self.size.to_untyped()) - } - - /// Tag a unitless value with units. - pub fn from_untyped(r: &Rect) -> TypedRect { - TypedRect::new(TypedPoint2D::from_untyped(&r.origin), TypedSize2D::from_untyped(&r.size)) - } -} - -impl TypedRect { - /// Cast from one numeric representation to another, preserving the units. - /// - /// When casting from floating point to integer coordinates, the decimals are truncated - /// as one would expect from a simple cast, but this behavior does not always make sense - /// geometrically. Consider using round(), round_in or round_out() before casting. - pub fn cast(&self) -> Option> { - match (self.origin.cast(), self.size.cast()) { - (Some(origin), Some(size)) => Some(TypedRect::new(origin, size)), - _ => None - } - } -} - -impl + Sub, U> TypedRect { - /// Return a rectangle with edges rounded to integer coordinates, such that - /// the returned rectangle has the same set of pixel centers as the original - /// one. - /// Edges at offset 0.5 round up. - /// Suitable for most places where integral device coordinates - /// are needed, but note that any translation should be applied first to - /// avoid pixel rounding errors. - /// Note that this is *not* rounding to nearest integer if the values are negative. - /// They are always rounding as floor(n + 0.5). - pub fn round(&self) -> Self { - let origin = self.origin.round(); - let size = self.origin.add_size(&self.size).round() - origin; - TypedRect::new(origin, TypedSize2D::new(size.x, size.y)) - } - - /// Return a rectangle with edges rounded to integer coordinates, such that - /// the original rectangle contains the resulting rectangle. - pub fn round_in(&self) -> Self { - let origin = self.origin.ceil(); - let size = self.origin.add_size(&self.size).floor() - origin; - TypedRect::new(origin, TypedSize2D::new(size.x, size.y)) - } - - /// Return a rectangle with edges rounded to integer coordinates, such that - /// the original rectangle is contained in the resulting rectangle. - pub fn round_out(&self) -> Self { - let origin = self.origin.floor(); - let size = self.origin.add_size(&self.size).ceil() - origin; - TypedRect::new(origin, TypedSize2D::new(size.x, size.y)) - } -} - -// Convenience functions for common casts -impl TypedRect { - /// Cast into an `f32` rectangle. - pub fn to_f32(&self) -> TypedRect { - self.cast().unwrap() - } - - /// Cast into an `usize` rectangle, truncating decimals if any. - /// - /// When casting from floating point rectangles, it is worth considering whether - /// to `round()`, `round_in()` or `round_out()` before the cast in order to - /// obtain the desired conversion behavior. - pub fn to_uint(&self) -> TypedRect { - self.cast().unwrap() - } - - /// Cast into an `i32` rectangle, truncating decimals if any. - /// - /// When casting from floating point rectangles, it is worth considering whether - /// to `round()`, `round_in()` or `round_out()` before the cast in order to - /// obtain the desired conversion behavior. - pub fn to_i32(&self) -> TypedRect { - self.cast().unwrap() - } - - /// Cast into an `i64` rectangle, truncating decimals if any. - /// - /// When casting from floating point rectangles, it is worth considering whether - /// to `round()`, `round_in()` or `round_out()` before the cast in order to - /// obtain the desired conversion behavior. - pub fn to_i64(&self) -> TypedRect { - self.cast().unwrap() - } -} - -/// Shorthand for `TypedRect::new(TypedPoint2D::new(x, y), TypedSize2D::new(w, h))`. -pub fn rect(x: T, y: T, w: T, h: T) -> TypedRect { - TypedRect::new(TypedPoint2D::new(x, y), TypedSize2D::new(w, h)) -} - -#[cfg(test)] -mod tests { - use point::Point2D; - use size::Size2D; - use super::*; - - #[test] - fn test_min_max() { - assert!(min(0u32, 1u32) == 0u32); - assert!(min(-1.0f32, 0.0f32) == -1.0f32); - - assert!(max(0u32, 1u32) == 1u32); - assert!(max(-1.0f32, 0.0f32) == 0.0f32); - } - - #[test] - fn test_translate() { - let p = Rect::new(Point2D::new(0u32, 0u32), Size2D::new(50u32, 40u32)); - let pp = p.translate(&Point2D::new(10,15)); - - assert!(pp.size.width == 50); - assert!(pp.size.height == 40); - assert!(pp.origin.x == 10); - assert!(pp.origin.y == 15); - - - let r = Rect::new(Point2D::new(-10, -5), Size2D::new(50, 40)); - let rr = r.translate(&Point2D::new(0,-10)); - - assert!(rr.size.width == 50); - assert!(rr.size.height == 40); - assert!(rr.origin.x == -10); - assert!(rr.origin.y == -15); - } - - #[test] - fn test_translate_by_size() { - let p = Rect::new(Point2D::new(0u32, 0u32), Size2D::new(50u32, 40u32)); - let pp = p.translate_by_size(&Size2D::new(10,15)); - - assert!(pp.size.width == 50); - assert!(pp.size.height == 40); - assert!(pp.origin.x == 10); - assert!(pp.origin.y == 15); - - - let r = Rect::new(Point2D::new(-10, -5), Size2D::new(50, 40)); - let rr = r.translate_by_size(&Size2D::new(0,-10)); - - assert!(rr.size.width == 50); - assert!(rr.size.height == 40); - assert!(rr.origin.x == -10); - assert!(rr.origin.y == -15); - } - - #[test] - fn test_union() { - let p = Rect::new(Point2D::new(0, 0), Size2D::new(50, 40)); - let q = Rect::new(Point2D::new(20,20), Size2D::new(5, 5)); - let r = Rect::new(Point2D::new(-15, -30), Size2D::new(200, 15)); - let s = Rect::new(Point2D::new(20, -15), Size2D::new(250, 200)); - - let pq = p.union(&q); - assert!(pq.origin == Point2D::new(0, 0)); - assert!(pq.size == Size2D::new(50, 40)); - - let pr = p.union(&r); - assert!(pr.origin == Point2D::new(-15, -30)); - assert!(pr.size == Size2D::new(200, 70)); - - let ps = p.union(&s); - assert!(ps.origin == Point2D::new(0, -15)); - assert!(ps.size == Size2D::new(270, 200)); - - } - - #[test] - fn test_intersection() { - let p = Rect::new(Point2D::new(0, 0), Size2D::new(10, 20)); - let q = Rect::new(Point2D::new(5, 15), Size2D::new(10, 10)); - let r = Rect::new(Point2D::new(-5, -5), Size2D::new(8, 8)); - - let pq = p.intersection(&q); - assert!(pq.is_some()); - let pq = pq.unwrap(); - assert!(pq.origin == Point2D::new(5, 15)); - assert!(pq.size == Size2D::new(5, 5)); - - let pr = p.intersection(&r); - assert!(pr.is_some()); - let pr = pr.unwrap(); - assert!(pr.origin == Point2D::new(0, 0)); - assert!(pr.size == Size2D::new(3, 3)); - - let qr = q.intersection(&r); - assert!(qr.is_none()); - } - - #[test] - fn test_contains() { - let r = Rect::new(Point2D::new(-20, 15), Size2D::new(100, 200)); - - assert!(r.contains(&Point2D::new(0, 50))); - assert!(r.contains(&Point2D::new(-10, 200))); - - // The `contains` method is inclusive of the top/left edges, but not the - // bottom/right edges. - assert!(r.contains(&Point2D::new(-20, 15))); - assert!(!r.contains(&Point2D::new(80, 15))); - assert!(!r.contains(&Point2D::new(80, 215))); - assert!(!r.contains(&Point2D::new(-20, 215))); - - // Points beyond the top-left corner. - assert!(!r.contains(&Point2D::new(-25, 15))); - assert!(!r.contains(&Point2D::new(-15, 10))); - - // Points beyond the top-right corner. - assert!(!r.contains(&Point2D::new(85, 20))); - assert!(!r.contains(&Point2D::new(75, 10))); - - // Points beyond the bottom-right corner. - assert!(!r.contains(&Point2D::new(85, 210))); - assert!(!r.contains(&Point2D::new(75, 220))); - - // Points beyond the bottom-left corner. - assert!(!r.contains(&Point2D::new(-25, 210))); - assert!(!r.contains(&Point2D::new(-15, 220))); - - let r = Rect::new(Point2D::new(-20.0, 15.0), Size2D::new(100.0, 200.0)); - assert!(r.contains_rect(&r)); - assert!(!r.contains_rect(&r.translate(&Point2D::new( 0.1, 0.0)))); - assert!(!r.contains_rect(&r.translate(&Point2D::new(-0.1, 0.0)))); - assert!(!r.contains_rect(&r.translate(&Point2D::new( 0.0, 0.1)))); - assert!(!r.contains_rect(&r.translate(&Point2D::new( 0.0, -0.1)))); - // Empty rectangles are always considered as contained in other rectangles, - // even if their origin is not. - let p = Point2D::new(1.0, 1.0); - assert!(!r.contains(&p)); - assert!(r.contains_rect(&Rect::new(p, Size2D::zero()))); - } - - #[test] - fn test_scale() { - let p = Rect::new(Point2D::new(0u32, 0u32), Size2D::new(50u32, 40u32)); - let pp = p.scale(10, 15); - - assert!(pp.size.width == 500); - assert!(pp.size.height == 600); - assert!(pp.origin.x == 0); - assert!(pp.origin.y == 0); - - let r = Rect::new(Point2D::new(-10, -5), Size2D::new(50, 40)); - let rr = r.scale(1, 20); - - assert!(rr.size.width == 50); - assert!(rr.size.height == 800); - assert!(rr.origin.x == -10); - assert!(rr.origin.y == -100); - } - - #[test] - fn test_inflate() { - let p = Rect::new(Point2D::new(0, 0), Size2D::new(10, 10)); - let pp = p.inflate(10, 20); - - assert!(pp.size.width == 30); - assert!(pp.size.height == 50); - assert!(pp.origin.x == -10); - assert!(pp.origin.y == -20); - - let r = Rect::new(Point2D::new(0, 0), Size2D::new(10, 20)); - let rr = r.inflate(-2, -5); - - assert!(rr.size.width == 6); - assert!(rr.size.height == 10); - assert!(rr.origin.x == 2); - assert!(rr.origin.y == 5); - } - - #[test] - fn test_min_max_x_y() { - let p = Rect::new(Point2D::new(0u32, 0u32), Size2D::new(50u32, 40u32)); - assert!(p.max_y() == 40); - assert!(p.min_y() == 0); - assert!(p.max_x() == 50); - assert!(p.min_x() == 0); - - let r = Rect::new(Point2D::new(-10, -5), Size2D::new(50, 40)); - assert!(r.max_y() == 35); - assert!(r.min_y() == -5); - assert!(r.max_x() == 40); - assert!(r.min_x() == -10); - } - - #[test] - fn test_is_empty() { - assert!(Rect::new(Point2D::new(0u32, 0u32), Size2D::new(0u32, 0u32)).is_empty()); - assert!(Rect::new(Point2D::new(0u32, 0u32), Size2D::new(10u32, 0u32)).is_empty()); - assert!(Rect::new(Point2D::new(0u32, 0u32), Size2D::new(0u32, 10u32)).is_empty()); - assert!(!Rect::new(Point2D::new(0u32, 0u32), Size2D::new(1u32, 1u32)).is_empty()); - assert!(Rect::new(Point2D::new(10u32, 10u32), Size2D::new(0u32, 0u32)).is_empty()); - assert!(Rect::new(Point2D::new(10u32, 10u32), Size2D::new(10u32, 0u32)).is_empty()); - assert!(Rect::new(Point2D::new(10u32, 10u32), Size2D::new(0u32, 10u32)).is_empty()); - assert!(!Rect::new(Point2D::new(10u32, 10u32), Size2D::new(1u32, 1u32)).is_empty()); - } - - #[test] - fn test_round() { - let mut x = -2.0; - let mut y = -2.0; - let mut w = -2.0; - let mut h = -2.0; - while x < 2.0 { - while y < 2.0 { - while w < 2.0 { - while h < 2.0 { - let rect = Rect::new(Point2D::new(x, y), Size2D::new(w, h)); - - assert!(rect.contains_rect(&rect.round_in())); - assert!(rect.round_in().inflate(1.0, 1.0).contains_rect(&rect)); - - assert!(rect.round_out().contains_rect(&rect)); - assert!(rect.inflate(1.0, 1.0).contains_rect(&rect.round_out())); - - assert!(rect.inflate(1.0, 1.0).contains_rect(&rect.round())); - assert!(rect.round().inflate(1.0, 1.0).contains_rect(&rect)); - - h += 0.1; - } - w += 0.1; - } - y += 0.1; - } - x += 0.1 - } - } -} diff --git a/third_party/rust/euclid-0.11.3/src/scale_factor.rs b/third_party/rust/euclid-0.11.3/src/scale_factor.rs deleted file mode 100644 index 4ecfc4bc8dc5..000000000000 --- a/third_party/rust/euclid-0.11.3/src/scale_factor.rs +++ /dev/null @@ -1,172 +0,0 @@ -// Copyright 2014 The Servo Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. -//! A type-checked scaling factor between units. - -use num::One; - -use heapsize::HeapSizeOf; -use num_traits::NumCast; -use serde::{Deserialize, Deserializer, Serialize, Serializer}; -use std::fmt; -use std::ops::{Add, Mul, Sub, Div}; -use std::marker::PhantomData; - -/// A scaling factor between two different units of measurement. -/// -/// This is effectively a type-safe float, intended to be used in combination with other types like -/// `length::Length` to enforce conversion between systems of measurement at compile time. -/// -/// `Src` and `Dst` represent the units before and after multiplying a value by a `ScaleFactor`. They -/// may be types without values, such as empty enums. For example: -/// -/// ```rust -/// use euclid::scale_factor::ScaleFactor; -/// use euclid::length::Length; -/// enum Mm {}; -/// enum Inch {}; -/// -/// let mm_per_inch: ScaleFactor = ScaleFactor::new(25.4); -/// -/// let one_foot: Length = Length::new(12.0); -/// let one_foot_in_mm: Length = one_foot * mm_per_inch; -/// ``` -#[repr(C)] -#[derive(RustcDecodable, RustcEncodable)] -pub struct ScaleFactor(pub T, PhantomData<(Src, Dst)>); - -impl HeapSizeOf for ScaleFactor { - fn heap_size_of_children(&self) -> usize { - self.0.heap_size_of_children() - } -} - -impl Deserialize for ScaleFactor where T: Deserialize { - fn deserialize(deserializer: D) -> Result, D::Error> - where D: Deserializer { - Ok(ScaleFactor(try!(Deserialize::deserialize(deserializer)), PhantomData)) - } -} - -impl Serialize for ScaleFactor where T: Serialize { - fn serialize(&self, serializer: S) -> Result where S: Serializer { - self.0.serialize(serializer) - } -} - -impl ScaleFactor { - pub fn new(x: T) -> ScaleFactor { - ScaleFactor(x, PhantomData) - } -} - -impl ScaleFactor { - pub fn get(&self) -> T { - self.0.clone() - } -} - -impl, Src, Dst> ScaleFactor { - /// The inverse ScaleFactor (1.0 / self). - pub fn inv(&self) -> ScaleFactor { - let one: T = One::one(); - ScaleFactor::new(one / self.get()) - } -} - -// scale0 * scale1 -impl, A, B, C> -Mul> for ScaleFactor { - type Output = ScaleFactor; - #[inline] - fn mul(self, other: ScaleFactor) -> ScaleFactor { - ScaleFactor::new(self.get() * other.get()) - } -} - -// scale0 + scale1 -impl, Src, Dst> Add for ScaleFactor { - type Output = ScaleFactor; - #[inline] - fn add(self, other: ScaleFactor) -> ScaleFactor { - ScaleFactor::new(self.get() + other.get()) - } -} - -// scale0 - scale1 -impl, Src, Dst> Sub for ScaleFactor { - type Output = ScaleFactor; - #[inline] - fn sub(self, other: ScaleFactor) -> ScaleFactor { - ScaleFactor::new(self.get() - other.get()) - } -} - -impl ScaleFactor { - /// Cast from one numeric representation to another, preserving the units. - pub fn cast(&self) -> Option> { - NumCast::from(self.get()).map(ScaleFactor::new) - } -} - -// FIXME: Switch to `derive(PartialEq, Clone)` after this Rust issue is fixed: -// https://github.com/mozilla/rust/issues/7671 - -impl PartialEq for ScaleFactor { - fn eq(&self, other: &ScaleFactor) -> bool { - self.0 == other.0 - } -} - -impl Clone for ScaleFactor { - fn clone(&self) -> ScaleFactor { - ScaleFactor::new(self.get()) - } -} - -impl Copy for ScaleFactor {} - -impl fmt::Debug for ScaleFactor { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - self.0.fmt(f) - } -} - -impl fmt::Display for ScaleFactor { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - self.0.fmt(f) - } -} - -#[cfg(test)] -mod tests { - use super::ScaleFactor; - - enum Inch {} - enum Cm {} - enum Mm {} - - #[test] - fn test_scale_factor() { - let mm_per_inch: ScaleFactor = ScaleFactor::new(25.4); - let cm_per_mm: ScaleFactor = ScaleFactor::new(0.1); - - let mm_per_cm: ScaleFactor = cm_per_mm.inv(); - assert_eq!(mm_per_cm.get(), 10.0); - - let cm_per_inch: ScaleFactor = mm_per_inch * cm_per_mm; - assert_eq!(cm_per_inch, ScaleFactor::new(2.54)); - - let a: ScaleFactor = ScaleFactor::new(2); - let b: ScaleFactor = ScaleFactor::new(3); - assert!(a != b); - assert_eq!(a, a.clone()); - assert_eq!(a.clone() + b.clone(), ScaleFactor::new(5)); - assert_eq!(a - b, ScaleFactor::new(-1)); - } -} diff --git a/third_party/rust/euclid-0.11.3/src/side_offsets.rs b/third_party/rust/euclid-0.11.3/src/side_offsets.rs deleted file mode 100644 index 7a1a7487e2e7..000000000000 --- a/third_party/rust/euclid-0.11.3/src/side_offsets.rs +++ /dev/null @@ -1,283 +0,0 @@ -// Copyright 2013 The Servo Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! A group of side offsets, which correspond to top/left/bottom/right for borders, padding, -//! and margins in CSS. - -use super::UnknownUnit; -use length::Length; -use num::Zero; -use std::fmt; -use std::ops::Add; -use std::marker::PhantomData; - -#[cfg(feature = "unstable")] -use heapsize::HeapSizeOf; - -/// A group of side offsets, which correspond to top/left/bottom/right for borders, padding, -/// and margins in CSS, optionally tagged with a unit. -define_matrix! { - pub struct TypedSideOffsets2D { - pub top: T, - pub right: T, - pub bottom: T, - pub left: T, - } -} - -impl fmt::Debug for TypedSideOffsets2D { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "({:?},{:?},{:?},{:?})", - self.top, self.right, self.bottom, self.left) - } -} - -/// The default side offset type with no unit. -pub type SideOffsets2D = TypedSideOffsets2D; - -impl TypedSideOffsets2D { - /// Constructor taking a scalar for each side. - pub fn new(top: T, right: T, bottom: T, left: T) -> TypedSideOffsets2D { - TypedSideOffsets2D { - top: top, - right: right, - bottom: bottom, - left: left, - _unit: PhantomData, - } - } - - /// Constructor taking a typed Length for each side. - pub fn from_lengths(top: Length, - right: Length, - bottom: Length, - left: Length) -> TypedSideOffsets2D { - TypedSideOffsets2D::new(top.0, right.0, bottom.0, left.0) - } - - /// Access self.top as a typed Length instead of a scalar value. - pub fn top_typed(&self) -> Length { Length::new(self.top) } - - /// Access self.right as a typed Length instead of a scalar value. - pub fn right_typed(&self) -> Length { Length::new(self.right) } - - /// Access self.bottom as a typed Length instead of a scalar value. - pub fn bottom_typed(&self) -> Length { Length::new(self.bottom) } - - /// Access self.left as a typed Length instead of a scalar value. - pub fn left_typed(&self) -> Length { Length::new(self.left) } - - /// Constructor setting the same value to all sides, taking a scalar value directly. - pub fn new_all_same(all: T) -> TypedSideOffsets2D { - TypedSideOffsets2D::new(all, all, all, all) - } - - /// Constructor setting the same value to all sides, taking a typed Length. - pub fn from_length_all_same(all: Length) -> TypedSideOffsets2D { - TypedSideOffsets2D::new_all_same(all.0) - } -} - -impl TypedSideOffsets2D where T: Add + Copy { - pub fn horizontal(&self) -> T { - self.left + self.right - } - - pub fn vertical(&self) -> T { - self.top + self.bottom - } - - pub fn horizontal_typed(&self) -> Length { - Length::new(self.horizontal()) - } - - pub fn vertical_typed(&self) -> Length { - Length::new(self.vertical()) - } -} - -impl Add for TypedSideOffsets2D where T : Copy + Add { - type Output = TypedSideOffsets2D; - fn add(self, other: TypedSideOffsets2D) -> TypedSideOffsets2D { - TypedSideOffsets2D::new( - self.top + other.top, - self.right + other.right, - self.bottom + other.bottom, - self.left + other.left, - ) - } -} - -impl TypedSideOffsets2D { - /// Constructor, setting all sides to zero. - pub fn zero() -> TypedSideOffsets2D { - TypedSideOffsets2D::new( - Zero::zero(), - Zero::zero(), - Zero::zero(), - Zero::zero(), - ) - } -} - -/// A SIMD enabled version of TypedSideOffsets2D specialized for i32. -#[cfg(feature = "unstable")] -#[derive(Clone, Copy, PartialEq)] -#[repr(simd)] -pub struct SideOffsets2DSimdI32 { - pub top: i32, - pub bottom: i32, - pub right: i32, - pub left: i32, -} - -#[cfg(feature = "unstable")] -impl HeapSizeOf for SideOffsets2DSimdI32 { - fn heap_size_of_children(&self) -> usize { 0 } -} - -#[cfg(feature = "unstable")] -impl SideOffsets2DSimdI32 { - #[inline] - pub fn new(top: i32, right: i32, bottom: i32, left: i32) -> SideOffsets2DSimdI32 { - SideOffsets2DSimdI32 { - top: top, - bottom: bottom, - right: right, - left: left, - } - } -} - -#[cfg(feature = "unstable")] -impl SideOffsets2DSimdI32 { - #[inline] - pub fn new_all_same(all: i32) -> SideOffsets2DSimdI32 { - SideOffsets2DSimdI32::new(all.clone(), all.clone(), all.clone(), all.clone()) - } -} - -#[cfg(feature = "unstable")] -impl SideOffsets2DSimdI32 { - #[inline] - pub fn horizontal(&self) -> i32 { - self.left + self.right - } - - #[inline] - pub fn vertical(&self) -> i32 { - self.top + self.bottom - } -} - -/*impl Add for SideOffsets2DSimdI32 { - type Output = SideOffsets2DSimdI32; - #[inline] - fn add(self, other: SideOffsets2DSimdI32) -> SideOffsets2DSimdI32 { - self + other // Use SIMD addition - } -}*/ - -#[cfg(feature = "unstable")] -impl SideOffsets2DSimdI32 { - #[inline] - pub fn zero() -> SideOffsets2DSimdI32 { - SideOffsets2DSimdI32 { - top: 0, - bottom: 0, - right: 0, - left: 0, - } - } - - #[cfg(not(target_arch = "x86_64"))] - #[inline] - pub fn is_zero(&self) -> bool { - self.top == 0 && self.right == 0 && self.bottom == 0 && self.left == 0 - } - - #[cfg(target_arch = "x86_64")] - #[inline] - pub fn is_zero(&self) -> bool { - let is_zero: bool; - unsafe { - asm! { - "ptest $1, $1 - setz $0" - : "=r"(is_zero) - : "x"(*self) - : - : "intel" - }; - } - is_zero - } -} - -#[cfg(feature = "unstable")] -#[cfg(test)] -mod tests { - use super::SideOffsets2DSimdI32; - - #[test] - fn test_is_zero() { - assert!(SideOffsets2DSimdI32::new_all_same(0).is_zero()); - assert!(!SideOffsets2DSimdI32::new_all_same(1).is_zero()); - assert!(!SideOffsets2DSimdI32::new(1, 0, 0, 0).is_zero()); - assert!(!SideOffsets2DSimdI32::new(0, 1, 0, 0).is_zero()); - assert!(!SideOffsets2DSimdI32::new(0, 0, 1, 0).is_zero()); - assert!(!SideOffsets2DSimdI32::new(0, 0, 0, 1).is_zero()); - } -} - -#[cfg(feature = "unstable")] -#[cfg(bench)] -mod bench { - use test::BenchHarness; - use std::num::Zero; - use rand::{XorShiftRng, Rng}; - use super::SideOffsets2DSimdI32; - - #[cfg(target_arch = "x86")] - #[cfg(target_arch = "x86_64")] - #[bench] - fn bench_naive_is_zero(bh: &mut BenchHarness) { - fn is_zero(x: &SideOffsets2DSimdI32) -> bool { - x.top.is_zero() && x.right.is_zero() && x.bottom.is_zero() && x.left.is_zero() - } - let mut rng = XorShiftRng::new().unwrap(); - bh.iter(|| is_zero(&rng.gen::())) - } - - #[bench] - fn bench_is_zero(bh: &mut BenchHarness) { - let mut rng = XorShiftRng::new().unwrap(); - bh.iter(|| rng.gen::().is_zero()) - } - - #[bench] - fn bench_naive_add(bh: &mut BenchHarness) { - fn add(x: &SideOffsets2DSimdI32, y: &SideOffsets2DSimdI32) -> SideOffsets2DSimdI32 { - SideOffsets2DSimdI32 { - top: x.top + y.top, - right: x.right + y.right, - bottom: x.bottom + y.bottom, - left: x.left + y.left, - } - } - let mut rng = XorShiftRng::new().unwrap(); - bh.iter(|| add(&rng.gen::(), &rng.gen::())) - } - - #[bench] - fn bench_add(bh: &mut BenchHarness) { - let mut rng = XorShiftRng::new().unwrap(); - bh.iter(|| rng.gen::() + rng.gen::()) - } -} diff --git a/third_party/rust/euclid-0.11.3/src/size.rs b/third_party/rust/euclid-0.11.3/src/size.rs deleted file mode 100644 index 3b5288fa24f4..000000000000 --- a/third_party/rust/euclid-0.11.3/src/size.rs +++ /dev/null @@ -1,276 +0,0 @@ -// Copyright 2013 The Servo Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -use super::UnknownUnit; -use length::Length; -use scale_factor::ScaleFactor; -use num::*; - -use num_traits::NumCast; -use std::fmt; -use std::ops::{Add, Div, Mul, Sub}; -use std::marker::PhantomData; - -/// A 2d size tagged with a unit. -define_matrix! { - #[derive(RustcDecodable, RustcEncodable)] - pub struct TypedSize2D { - pub width: T, - pub height: T, - } -} - -/// Default 2d size type with no unit. -/// -/// `Size2D` provides the same methods as `TypedSize2D`. -pub type Size2D = TypedSize2D; - -impl fmt::Debug for TypedSize2D { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{:?}×{:?}", self.width, self.height) - } -} - -impl fmt::Display for TypedSize2D { - fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { - write!(formatter, "({}x{})", self.width, self.height) - } -} - -impl TypedSize2D { - /// Constructor taking scalar values. - pub fn new(width: T, height: T) -> TypedSize2D { - TypedSize2D { - width: width, - height: height, - _unit: PhantomData, - } - } -} - -impl TypedSize2D { - /// Constructor taking scalar strongly typed lengths. - pub fn from_lengths(width: Length, height: Length) -> TypedSize2D { - TypedSize2D::new(width.get(), height.get()) - } -} - -impl TypedSize2D { - /// Rounds each component to the nearest integer value. - /// - /// This behavior is preserved for negative values (unlike the basic cast). - pub fn round(&self) -> Self { - TypedSize2D::new(self.width.round(), self.height.round()) - } -} - -impl TypedSize2D { - /// Rounds each component to the smallest integer equal or greater than the original value. - /// - /// This behavior is preserved for negative values (unlike the basic cast). - pub fn ceil(&self) -> Self { - TypedSize2D::new(self.width.ceil(), self.height.ceil()) - } -} - -impl TypedSize2D { - /// Rounds each component to the biggest integer equal or lower than the original value. - /// - /// This behavior is preserved for negative values (unlike the basic cast). - pub fn floor(&self) -> Self { - TypedSize2D::new(self.width.floor(), self.height.floor()) - } -} - -impl, U> Add for TypedSize2D { - type Output = TypedSize2D; - fn add(self, other: TypedSize2D) -> TypedSize2D { - TypedSize2D::new(self.width + other.width, self.height + other.height) - } -} - -impl, U> Sub for TypedSize2D { - type Output = TypedSize2D; - fn sub(self, other: TypedSize2D) -> TypedSize2D { - TypedSize2D::new(self.width - other.width, self.height - other.height) - } -} - -impl, U> TypedSize2D { - pub fn area(&self) -> U { self.width * self.height } -} - -impl TypedSize2D { - pub fn zero() -> TypedSize2D { - TypedSize2D::new( - Zero::zero(), - Zero::zero(), - ) - } -} - -impl Zero for TypedSize2D { - fn zero() -> TypedSize2D { - TypedSize2D::new( - Zero::zero(), - Zero::zero(), - ) - } -} - -impl, U> Mul for TypedSize2D { - type Output = TypedSize2D; - #[inline] - fn mul(self, scale: T) -> TypedSize2D { - TypedSize2D::new(self.width * scale, self.height * scale) - } -} - -impl, U> Div for TypedSize2D { - type Output = TypedSize2D; - #[inline] - fn div(self, scale: T) -> TypedSize2D { - TypedSize2D::new(self.width / scale, self.height / scale) - } -} - -impl, U1, U2> Mul> for TypedSize2D { - type Output = TypedSize2D; - #[inline] - fn mul(self, scale: ScaleFactor) -> TypedSize2D { - TypedSize2D::new(self.width * scale.get(), self.height * scale.get()) - } -} - -impl, U1, U2> Div> for TypedSize2D { - type Output = TypedSize2D; - #[inline] - fn div(self, scale: ScaleFactor) -> TypedSize2D { - TypedSize2D::new(self.width / scale.get(), self.height / scale.get()) - } -} - -impl TypedSize2D { - /// Returns self.width as a Length carrying the unit. - #[inline] - pub fn width_typed(&self) -> Length { Length::new(self.width) } - - /// Returns self.height as a Length carrying the unit. - #[inline] - pub fn height_typed(&self) -> Length { Length::new(self.height) } - - #[inline] - pub fn to_array(&self) -> [T; 2] { [self.width, self.height] } - - /// Drop the units, preserving only the numeric value. - pub fn to_untyped(&self) -> Size2D { - TypedSize2D::new(self.width, self.height) - } - - /// Tag a unitless value with units. - pub fn from_untyped(p: &Size2D) -> TypedSize2D { - TypedSize2D::new(p.width, p.height) - } -} - -impl TypedSize2D { - /// Cast from one numeric representation to another, preserving the units. - /// - /// When casting from floating point to integer coordinates, the decimals are truncated - /// as one would expect from a simple cast, but this behavior does not always make sense - /// geometrically. Consider using `round()`, `ceil()` or `floor()` before casting. - pub fn cast(&self) -> Option> { - match (NumCast::from(self.width), NumCast::from(self.height)) { - (Some(w), Some(h)) => Some(TypedSize2D::new(w, h)), - _ => None - } - } - - // Convenience functions for common casts - - /// Cast into an `f32` size. - pub fn to_f32(&self) -> TypedSize2D { - self.cast().unwrap() - } - - /// Cast into an `uint` size, truncating decimals if any. - /// - /// When casting from floating point sizes, it is worth considering whether - /// to `round()`, `ceil()` or `floor()` before the cast in order to obtain - /// the desired conversion behavior. - pub fn to_uint(&self) -> TypedSize2D { - self.cast().unwrap() - } - - /// Cast into an `i32` size, truncating decimals if any. - /// - /// When casting from floating point sizes, it is worth considering whether - /// to `round()`, `ceil()` or `floor()` before the cast in order to obtain - /// the desired conversion behavior. - pub fn to_i32(&self) -> TypedSize2D { - self.cast().unwrap() - } - - /// Cast into an `i64` size, truncating decimals if any. - /// - /// When casting from floating point sizes, it is worth considering whether - /// to `round()`, `ceil()` or `floor()` before the cast in order to obtain - /// the desired conversion behavior. - pub fn to_i64(&self) -> TypedSize2D { - self.cast().unwrap() - } -} - -/// Shorthand for `TypedSize2D::new(w, h)`. -pub fn size2(w: T, h: T) -> TypedSize2D { - TypedSize2D::new(w, h) -} - -#[cfg(test)] -mod size2d { - use super::Size2D; - - #[test] - pub fn test_add() { - let p1 = Size2D::new(1.0, 2.0); - let p2 = Size2D::new(3.0, 4.0); - assert_eq!(p1 + p2, Size2D::new(4.0, 6.0)); - - let p1 = Size2D::new(1.0, 2.0); - let p2 = Size2D::new(0.0, 0.0); - assert_eq!(p1 + p2, Size2D::new(1.0, 2.0)); - - let p1 = Size2D::new(1.0, 2.0); - let p2 = Size2D::new(-3.0, -4.0); - assert_eq!(p1 + p2, Size2D::new(-2.0, -2.0)); - - let p1 = Size2D::new(0.0, 0.0); - let p2 = Size2D::new(0.0, 0.0); - assert_eq!(p1 + p2, Size2D::new(0.0, 0.0)); - } - - #[test] - pub fn test_sub() { - let p1 = Size2D::new(1.0, 2.0); - let p2 = Size2D::new(3.0, 4.0); - assert_eq!(p1 - p2, Size2D::new(-2.0, -2.0)); - - let p1 = Size2D::new(1.0, 2.0); - let p2 = Size2D::new(0.0, 0.0); - assert_eq!(p1 - p2, Size2D::new(1.0, 2.0)); - - let p1 = Size2D::new(1.0, 2.0); - let p2 = Size2D::new(-3.0, -4.0); - assert_eq!(p1 - p2, Size2D::new(4.0, 6.0)); - - let p1 = Size2D::new(0.0, 0.0); - let p2 = Size2D::new(0.0, 0.0); - assert_eq!(p1 - p2, Size2D::new(0.0, 0.0)); - } -} diff --git a/third_party/rust/euclid-0.11.3/src/trig.rs b/third_party/rust/euclid-0.11.3/src/trig.rs deleted file mode 100644 index 6f3f348a9b1a..000000000000 --- a/third_party/rust/euclid-0.11.3/src/trig.rs +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright 2013 The Servo Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - - -/// Trait for basic trigonometry functions, so they can be used on generic numeric types -pub trait Trig { - fn sin(self) -> Self; - fn cos(self) -> Self; - fn tan(self) -> Self; -} - -impl Trig for f32 { - #[inline] - fn sin(self) -> f32 { - self.sin() - } - - #[inline] - fn cos(self) -> f32 { - self.cos() - } - - #[inline] - fn tan(self) -> f32 { - self.tan() - } -} - -impl Trig for f64 { - #[inline] - fn sin(self) -> f64 { - self.sin() - } - - #[inline] - fn cos(self) -> f64 { - self.cos() - } - - #[inline] - fn tan(self) -> f64 { - self.tan() - } -} diff --git a/third_party/rust/smallvec-0.3.3/.cargo-checksum.json b/third_party/rust/smallvec-0.3.3/.cargo-checksum.json new file mode 100644 index 000000000000..66ad40a6677c --- /dev/null +++ b/third_party/rust/smallvec-0.3.3/.cargo-checksum.json @@ -0,0 +1 @@ +{"files":{".cargo-ok":"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",".gitignore":"f9b1ca6ae27d1c18215265024629a8960c31379f206d9ed20f64e0b2dcf79805",".travis.yml":"8d8372a5e10c6d301d70d45da3d51a4b8cbd6d51b57a62e7730942adc69da200","Cargo.toml":"48402d1ef9c6e0015e98104e1b9ec5c406a2e5ca5d8f8b0382a1ed4decdf96f8","README.md":"85c6105e404b1febba9e06773350cc81fe5966369530210669b3465c66237a09","benches/bench.rs":"54cf4879d36ba2a9f3423af91bb93227b70849200e5bf74e384a166d6aa09893","lib.rs":"acdf2c4778adb0b613efb08ff4612d8d7fb2d67747da026ab3894539e7f3e3ed"},"package":"4f8266519bc1d17d0b5b16f6c21295625d562841c708f6376f49028a43e9c11e"} \ No newline at end of file diff --git a/third_party/rust/euclid-0.11.3/.cargo-ok b/third_party/rust/smallvec-0.3.3/.cargo-ok similarity index 100% rename from third_party/rust/euclid-0.11.3/.cargo-ok rename to third_party/rust/smallvec-0.3.3/.cargo-ok diff --git a/third_party/rust/euclid-0.11.3/.gitignore b/third_party/rust/smallvec-0.3.3/.gitignore similarity index 55% rename from third_party/rust/euclid-0.11.3/.gitignore rename to third_party/rust/smallvec-0.3.3/.gitignore index 80faedecfd74..a9d37c560c6a 100644 --- a/third_party/rust/euclid-0.11.3/.gitignore +++ b/third_party/rust/smallvec-0.3.3/.gitignore @@ -1,2 +1,2 @@ +target Cargo.lock -/target/ diff --git a/third_party/rust/smallvec-0.3.3/.travis.yml b/third_party/rust/smallvec-0.3.3/.travis.yml new file mode 100644 index 000000000000..8a946c32de34 --- /dev/null +++ b/third_party/rust/smallvec-0.3.3/.travis.yml @@ -0,0 +1,13 @@ +language: rust +rust: + - nightly + - beta + - stable +script: | + cargo build --verbose && + cargo build --features=heapsizeof --verbose && + cargo test --verbose && + cargo test --features=heapsizeof --verbose && + ([ $TRAVIS_RUST_VERSION != nightly ] || cargo bench --verbose bench) +notifications: + webhooks: http://build.servo.org:54856/travis diff --git a/third_party/rust/smallvec-0.3.3/Cargo.toml b/third_party/rust/smallvec-0.3.3/Cargo.toml new file mode 100644 index 000000000000..2a64c0419afc --- /dev/null +++ b/third_party/rust/smallvec-0.3.3/Cargo.toml @@ -0,0 +1,20 @@ +[package] +name = "smallvec" +version = "0.3.3" +authors = ["Simon Sapin "] +license = "MPL-2.0" +repository = "https://github.com/servo/rust-smallvec" +description = "'Small vector' optimization: store up to a small number of items on the stack" +keywords = ["small", "vec", "vector", "stack"] +readme = "README.md" +documentation = "http://doc.servo.org/smallvec/" + +[features] +heapsizeof = ["heapsize"] + +[lib] +name = "smallvec" +path = "lib.rs" + +[dependencies] +heapsize = { version = "0.3", optional = true } diff --git a/third_party/rust/smallvec-0.3.3/README.md b/third_party/rust/smallvec-0.3.3/README.md new file mode 100644 index 000000000000..a7211e09ff6e --- /dev/null +++ b/third_party/rust/smallvec-0.3.3/README.md @@ -0,0 +1,6 @@ +rust-smallvec +============= + +[Documentation](http://doc.servo.org/smallvec/) + +"Small vector" optimization for Rust: store up to a small number of items on the stack diff --git a/third_party/rust/smallvec-0.3.3/benches/bench.rs b/third_party/rust/smallvec-0.3.3/benches/bench.rs new file mode 100644 index 000000000000..3ca112aab971 --- /dev/null +++ b/third_party/rust/smallvec-0.3.3/benches/bench.rs @@ -0,0 +1,111 @@ +#![feature(test)] + +extern crate smallvec; +extern crate test; + +use smallvec::SmallVec; +use self::test::Bencher; + +#[bench] +fn bench_push(b: &mut Bencher) { + #[inline(never)] + fn push_noinline(vec: &mut SmallVec<[u64; 16]>, x: u64) { + vec.push(x) + } + + b.iter(|| { + let mut vec: SmallVec<[u64; 16]> = SmallVec::new(); + for x in 0..100 { + push_noinline(&mut vec, x); + } + vec + }); +} + +#[bench] +fn bench_insert(b: &mut Bencher) { + #[inline(never)] + fn insert_noinline(vec: &mut SmallVec<[u64; 16]>, x: u64) { + vec.insert(0, x) + } + + b.iter(|| { + let mut vec: SmallVec<[u64; 16]> = SmallVec::new(); + for x in 0..100 { + insert_noinline(&mut vec, x); + } + vec + }); +} + +#[bench] +fn bench_insert_many(b: &mut Bencher) { + #[inline(never)] + fn insert_many_noinline>( + vec: &mut SmallVec<[u64; 16]>, index: usize, iterable: I) { + vec.insert_many(index, iterable) + } + + b.iter(|| { + let mut vec: SmallVec<[u64; 16]> = SmallVec::new(); + insert_many_noinline(&mut vec, 0, 0..100); + insert_many_noinline(&mut vec, 0, 0..100); + vec + }); +} + +#[bench] +fn bench_extend(b: &mut Bencher) { + b.iter(|| { + let mut vec: SmallVec<[u64; 16]> = SmallVec::new(); + vec.extend(0..100); + vec + }); +} + +#[bench] +fn bench_from_slice(b: &mut Bencher) { + let v: Vec = (0..100).collect(); + b.iter(|| { + let vec: SmallVec<[u64; 16]> = SmallVec::from_slice(&v); + vec + }); +} + +#[bench] +fn bench_extend_from_slice(b: &mut Bencher) { + let v: Vec = (0..100).collect(); + b.iter(|| { + let mut vec: SmallVec<[u64; 16]> = SmallVec::new(); + vec.extend_from_slice(&v); + vec + }); +} + +#[bench] +fn bench_insert_from_slice(b: &mut Bencher) { + let v: Vec = (0..100).collect(); + b.iter(|| { + let mut vec: SmallVec<[u64; 16]> = SmallVec::new(); + vec.insert_from_slice(0, &v); + vec.insert_from_slice(0, &v); + vec + }); +} + +#[bench] +fn bench_pushpop(b: &mut Bencher) { + #[inline(never)] + fn pushpop_noinline(vec: &mut SmallVec<[u64; 16]>, x: u64) { + vec.push(x); + vec.pop(); + } + + b.iter(|| { + let mut vec: SmallVec<[u64; 16]> = SmallVec::new(); + for x in 0..100 { + pushpop_noinline(&mut vec, x); + } + vec + }); +} diff --git a/third_party/rust/smallvec-0.3.3/lib.rs b/third_party/rust/smallvec-0.3.3/lib.rs new file mode 100644 index 000000000000..f03108a759fd --- /dev/null +++ b/third_party/rust/smallvec-0.3.3/lib.rs @@ -0,0 +1,1424 @@ +/* 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/. */ + +//! Small vectors in various sizes. These store a certain number of elements inline, and fall back +//! to the heap for larger allocations. This can be a useful optimization for improving cache +//! locality and reducing allocator traffic for workloads that fit within the inline buffer. + +#[cfg(feature="heapsizeof")] +extern crate heapsize; + +use std::borrow::{Borrow, BorrowMut}; +use std::cmp; +use std::fmt; +use std::hash::{Hash, Hasher}; +use std::iter::{IntoIterator, FromIterator}; +use std::mem; +use std::ops; +use std::ptr; +use std::slice; +#[cfg(feature="heapsizeof")] +use std::os::raw::c_void; + +#[cfg(feature="heapsizeof")] +use heapsize::{HeapSizeOf, heap_size_of}; +use SmallVecData::{Inline, Heap}; + +/// Common operations implemented by both `Vec` and `SmallVec`. +/// +/// This can be used to write generic code that works with both `Vec` and `SmallVec`. +/// +/// ## Example +/// +/// ```rust +/// use smallvec::{VecLike, SmallVec8}; +/// +/// fn initialize>(v: &mut V) { +/// for i in 0..5 { +/// v.push(i); +/// } +/// } +/// +/// let mut vec = Vec::new(); +/// initialize(&mut vec); +/// +/// let mut small_vec = SmallVec8::new(); +/// initialize(&mut small_vec); +/// ``` +pub trait VecLike: + ops::Index + + ops::IndexMut + + ops::Index, Output=[T]> + + ops::IndexMut> + + ops::Index, Output=[T]> + + ops::IndexMut> + + ops::Index, Output=[T]> + + ops::IndexMut> + + ops::Index + + ops::IndexMut + + ops::DerefMut + + Extend { + + /// Append an element to the vector. + fn push(&mut self, value: T); +} + +impl VecLike for Vec { + #[inline] + fn push(&mut self, value: T) { + Vec::push(self, value); + } +} + +unsafe fn deallocate(ptr: *mut T, capacity: usize) { + let _vec: Vec = Vec::from_raw_parts(ptr, 0, capacity); + // Let it drop. +} + +pub struct Drain<'a, T: 'a> { + iter: slice::IterMut<'a,T>, +} + +impl<'a, T: 'a> Iterator for Drain<'a,T> { + type Item = T; + + #[inline] + fn next(&mut self) -> Option { + match self.iter.next() { + None => None, + Some(reference) => { + unsafe { + Some(ptr::read(reference)) + } + } + } + } + + #[inline] + fn size_hint(&self) -> (usize, Option) { + self.iter.size_hint() + } +} + +impl<'a, T: 'a> DoubleEndedIterator for Drain<'a, T> { + #[inline] + fn next_back(&mut self) -> Option { + match self.iter.next_back() { + None => None, + Some(reference) => { + unsafe { + Some(ptr::read(reference)) + } + } + } + } +} + +impl<'a, T> ExactSizeIterator for Drain<'a, T> { } + +impl<'a, T: 'a> Drop for Drain<'a,T> { + fn drop(&mut self) { + // Destroy the remaining elements. + for _ in self.by_ref() {} + } +} + +enum SmallVecData { + Inline { array: A }, + Heap { ptr: *mut A::Item, capacity: usize }, +} + +impl SmallVecData { + fn ptr_mut(&mut self) -> *mut A::Item { + match *self { + Inline { ref mut array } => array.ptr_mut(), + Heap { ptr, .. } => ptr, + } + } +} + +unsafe impl Send for SmallVecData {} +unsafe impl Sync for SmallVecData {} + +impl Drop for SmallVecData { + fn drop(&mut self) { + unsafe { + match *self { + ref mut inline @ Inline { .. } => { + // Inhibit the array destructor. + ptr::write(inline, Heap { + ptr: ptr::null_mut(), + capacity: 0, + }); + } + Heap { ptr, capacity } => deallocate(ptr, capacity), + } + } + } +} + +/// A `Vec`-like container that can store a small number of elements inline. +/// +/// `SmallVec` acts like a vector, but can store a limited amount of data inline within the +/// `Smallvec` struct rather than in a separate allocation. If the data exceeds this limit, the +/// `SmallVec` will "spill" its data onto the heap, allocating a new buffer to hold it. +/// +/// The amount of data that a `SmallVec` can store inline depends on its backing store. The backing +/// store can be any type that implements the `Array` trait; usually it is a small fixed-sized +/// array. For example a `SmallVec<[u64; 8]>` can hold up to eight 64-bit integers inline. +/// +/// Type aliases like `SmallVec8` are provided as convenient shorthand for types like +/// `SmallVec<[T; 8]>`. +/// +/// ## Example +/// +/// ```rust +/// use smallvec::SmallVec; +/// let mut v = SmallVec::<[u8; 4]>::new(); // initialize an empty vector +/// +/// use smallvec::SmallVec4; +/// let mut v: SmallVec4 = SmallVec::new(); // alternate way to write the above +/// +/// // SmallVec4 can hold up to 4 items without spilling onto the heap. +/// v.extend(0..4); +/// assert_eq!(v.len(), 4); +/// assert!(!v.spilled()); +/// +/// // Pushing another element will force the buffer to spill: +/// v.push(4); +/// assert_eq!(v.len(), 5); +/// assert!(v.spilled()); +/// ``` +pub struct SmallVec { + len: usize, + data: SmallVecData, +} + +impl SmallVec { + /// Construct an empty vector + #[inline] + pub fn new() -> SmallVec { + unsafe { + SmallVec { + len: 0, + data: Inline { array: mem::uninitialized() }, + } + } + } + + /// Construct a new `SmallVec` from a `Vec` without copying + /// elements. + /// + /// ```rust + /// use smallvec::SmallVec; + /// + /// let vec = vec![1, 2, 3, 4, 5]; + /// let small_vec: SmallVec<[_; 3]> = SmallVec::from_vec(vec); + /// + /// assert_eq!(&*small_vec, &[1, 2, 3, 4, 5]); + /// ``` + #[inline] + pub fn from_vec(mut vec: Vec) -> SmallVec { + let (ptr, cap, len) = (vec.as_mut_ptr(), vec.capacity(), vec.len()); + mem::forget(vec); + + SmallVec { + len: len, + data: SmallVecData::Heap { + ptr: ptr, + capacity: cap + } + } + } + + /// Sets the length of a vector. + /// + /// This will explicitly set the size of the vector, without actually + /// modifying its buffers, so it is up to the caller to ensure that the + /// vector is actually the specified size. + pub unsafe fn set_len(&mut self, new_len: usize) { + self.len = new_len + } + + /// The maximum number of elements this vector can hold inline + #[inline] + pub fn inline_size(&self) -> usize { + A::size() + } + + /// The number of elements stored in the vector + #[inline] + pub fn len(&self) -> usize { + self.len + } + + /// Returns `true` if the vector is empty + #[inline] + pub fn is_empty(&self) -> bool { + self.len == 0 + } + + /// The number of items the vector can hold without reallocating + #[inline] + pub fn capacity(&self) -> usize { + match self.data { + Inline { .. } => A::size(), + Heap { capacity, .. } => capacity, + } + } + + /// Returns `true` if the data has spilled into a separate heap-allocated buffer. + #[inline] + pub fn spilled(&self) -> bool { + match self.data { + Inline { .. } => false, + Heap { .. } => true, + } + } + + /// Empty the vector and return an iterator over its former contents. + pub fn drain(&mut self) -> Drain { + unsafe { + let current_len = self.len(); + self.set_len(0); + + let ptr = self.data.ptr_mut(); + + let slice = slice::from_raw_parts_mut(ptr, current_len); + + Drain { + iter: slice.iter_mut(), + } + } + } + + /// Append an item to the vector. + #[inline] + pub fn push(&mut self, value: A::Item) { + let cap = self.capacity(); + if self.len == cap { + self.grow(cmp::max(cap * 2, 1)) + } + unsafe { + let end = self.as_mut_ptr().offset(self.len as isize); + ptr::write(end, value); + let len = self.len; + self.set_len(len + 1) + } + } + + /// Append elements from an iterator. + /// + /// This function is deprecated; it has been replaced by `Extend::extend`. + #[deprecated(note = "Use `extend` instead")] + pub fn push_all_move>(&mut self, other: V) { + self.extend(other) + } + + /// Remove an item from the end of the vector and return it, or None if empty. + #[inline] + pub fn pop(&mut self) -> Option { + if self.len == 0 { + return None + } + let last_index = self.len - 1; + if (last_index as isize) < 0 { + panic!("overflow") + } + unsafe { + let end_ptr = self.as_mut_ptr().offset(last_index as isize); + let value = ptr::replace(end_ptr, mem::uninitialized()); + self.set_len(last_index); + Some(value) + } + } + + /// Re-allocate to set the capacity to `new_cap`. + /// + /// Panics if `new_cap` is less than the vector's length. + pub fn grow(&mut self, new_cap: usize) { + assert!(new_cap >= self.len); + let mut vec: Vec = Vec::with_capacity(new_cap); + let new_alloc = vec.as_mut_ptr(); + unsafe { + mem::forget(vec); + ptr::copy_nonoverlapping(self.as_ptr(), new_alloc, self.len); + + match self.data { + Inline { .. } => {} + Heap { ptr, capacity } => deallocate(ptr, capacity), + } + ptr::write(&mut self.data, Heap { + ptr: new_alloc, + capacity: new_cap, + }); + } + } + + /// Reserve capacity for `additional` more elements to be inserted. + /// + /// May reserve more space to avoid frequent reallocations. + /// + /// If the new capacity would overflow `usize` then it will be set to `usize::max_value()` + /// instead. (This means that inserting `additional` new elements is not guaranteed to be + /// possible after calling this function.) + pub fn reserve(&mut self, additional: usize) { + let len = self.len(); + if self.capacity() - len < additional { + match len.checked_add(additional).and_then(usize::checked_next_power_of_two) { + Some(cap) => self.grow(cap), + None => self.grow(usize::max_value()), + } + } + } + + /// Reserve the minumum capacity for `additional` more elements to be inserted. + /// + /// Panics if the new capacity overflows `usize`. + pub fn reserve_exact(&mut self, additional: usize) { + let len = self.len(); + if self.capacity() - len < additional { + match len.checked_add(additional) { + Some(cap) => self.grow(cap), + None => panic!("reserve_exact overflow"), + } + } + } + + /// Shrink the capacity of the vector as much as possible. + /// + /// When possible, this will move data from an external heap buffer to the vector's inline + /// storage. + pub fn shrink_to_fit(&mut self) { + let len = self.len; + if self.inline_size() >= len { + unsafe { + let (ptr, capacity) = match self.data { + Inline { .. } => return, + Heap { ptr, capacity } => (ptr, capacity), + }; + ptr::write(&mut self.data, Inline { array: mem::uninitialized() }); + ptr::copy_nonoverlapping(ptr, self.as_mut_ptr(), len); + deallocate(ptr, capacity); + } + } else if self.capacity() > len { + self.grow(len); + } + } + + /// Shorten the vector, keeping the first `len` elements and dropping the rest. + /// + /// If `len` is greater than or equal to the vector's current length, this has no + /// effect. + /// + /// This does not re-allocate. If you want the vector's capacity to shrink, call + /// `shrink_to_fit` after truncating. + pub fn truncate(&mut self, len: usize) { + let end_ptr = self.as_ptr(); + while len < self.len { + unsafe { + let last_index = self.len - 1; + self.set_len(last_index); + ptr::read(end_ptr.offset(last_index as isize)); + } + } + } + + /// Remove the element at position `index`, replacing it with the last element. + /// + /// This does not preserve ordering, but is O(1). + /// + /// Panics if `index` is out of bounds. + #[inline] + pub fn swap_remove(&mut self, index: usize) -> A::Item { + let len = self.len; + self.swap(len - 1, index); + self.pop().unwrap() + } + + /// Remove all elements from the vector. + #[inline] + pub fn clear(&mut self) { + self.truncate(0); + } + + /// Remove and return the element at position `index`, shifting all elements after it to the + /// left. + /// + /// Panics if `index` is out of bounds. + pub fn remove(&mut self, index: usize) -> A::Item { + let len = self.len(); + + assert!(index < len); + + unsafe { + let ptr = self.as_mut_ptr().offset(index as isize); + let item = ptr::read(ptr); + ptr::copy(ptr.offset(1), ptr, len - index - 1); + self.set_len(len - 1); + item + } + } + + /// Insert an element at position `index`, shifting all elements after it to the right. + /// + /// Panics if `index` is out of bounds. + pub fn insert(&mut self, index: usize, element: A::Item) { + self.reserve(1); + + let len = self.len; + assert!(index <= len); + + unsafe { + let ptr = self.as_mut_ptr().offset(index as isize); + ptr::copy(ptr, ptr.offset(1), len - index); + ptr::write(ptr, element); + self.set_len(len + 1); + } + } + + pub fn insert_many>(&mut self, index: usize, iterable: I) { + let iter = iterable.into_iter(); + let (lower_size_bound, _) = iter.size_hint(); + assert!(lower_size_bound <= std::isize::MAX as usize); // Ensure offset is indexable + assert!(index + lower_size_bound >= index); // Protect against overflow + self.reserve(lower_size_bound); + + unsafe { + let old_len = self.len; + assert!(index <= old_len); + let ptr = self.as_mut_ptr().offset(index as isize); + ptr::copy(ptr, ptr.offset(lower_size_bound as isize), old_len - index); + for (off, element) in iter.enumerate() { + if off < lower_size_bound { + ptr::write(ptr.offset(off as isize), element); + self.len = self.len + 1; + } else { + // Iterator provided more elements than the hint. + assert!(index + off >= index); // Protect against overflow. + self.insert(index + off, element); + } + } + let num_added = self.len - old_len; + if num_added < lower_size_bound { + // Iterator provided fewer elements than the hint + ptr::copy(ptr.offset(lower_size_bound as isize), ptr.offset(num_added as isize), old_len - index); + } + } + } + + /// Convert a SmallVec to a Vec, without reallocating if the SmallVec has already spilled onto + /// the heap. + pub fn into_vec(self) -> Vec { + match self.data { + Inline { .. } => self.into_iter().collect(), + Heap { ptr, capacity } => unsafe { + let v = Vec::from_raw_parts(ptr, self.len, capacity); + mem::forget(self); + v + } + } + } +} + +impl SmallVec where A::Item: Copy { + pub fn from_slice(slice: &[A::Item]) -> Self { + let mut vec = Self::new(); + vec.extend_from_slice(slice); + vec + } + + pub fn insert_from_slice(&mut self, index: usize, slice: &[A::Item]) { + self.reserve(slice.len()); + + let len = self.len; + assert!(index <= len); + + unsafe { + let slice_ptr = slice.as_ptr(); + let ptr = self.as_mut_ptr().offset(index as isize); + ptr::copy(ptr, ptr.offset(slice.len() as isize), len - index); + ptr::copy(slice_ptr, ptr, slice.len()); + self.set_len(len + slice.len()); + } + } + + #[inline] + pub fn extend_from_slice(&mut self, slice: &[A::Item]) { + let len = self.len(); + self.insert_from_slice(len, slice); + } +} + +#[cfg(feature="heapsizeof")] +impl HeapSizeOf for SmallVec where A::Item: HeapSizeOf { + fn heap_size_of_children(&self) -> usize { + match self.data { + Inline { .. } => 0, + Heap { ptr, .. } => { + self.iter().fold( + unsafe { heap_size_of(ptr as *const c_void) }, + |n, elem| n + elem.heap_size_of_children()) + }, + } + } +} + +impl ops::Deref for SmallVec { + type Target = [A::Item]; + #[inline] + fn deref(&self) -> &[A::Item] { + let ptr: *const _ = match self.data { + Inline { ref array } => array.ptr(), + Heap { ptr, .. } => ptr, + }; + unsafe { + slice::from_raw_parts(ptr, self.len) + } + } +} + +impl ops::DerefMut for SmallVec { + #[inline] + fn deref_mut(&mut self) -> &mut [A::Item] { + let ptr = self.data.ptr_mut(); + unsafe { + slice::from_raw_parts_mut(ptr, self.len) + } + } +} + +impl AsRef<[A::Item]> for SmallVec { + #[inline] + fn as_ref(&self) -> &[A::Item] { + self + } +} + +impl AsMut<[A::Item]> for SmallVec { + #[inline] + fn as_mut(&mut self) -> &mut [A::Item] { + self + } +} + +impl Borrow<[A::Item]> for SmallVec { + #[inline] + fn borrow(&self) -> &[A::Item] { + self + } +} + +impl BorrowMut<[A::Item]> for SmallVec { + #[inline] + fn borrow_mut(&mut self) -> &mut [A::Item] { + self + } +} + +impl<'a, A: Array> From<&'a [A::Item]> for SmallVec where A::Item: Clone { + #[inline] + fn from(slice: &'a [A::Item]) -> SmallVec { + slice.into_iter().cloned().collect() + } +} + +macro_rules! impl_index { + ($index_type: ty, $output_type: ty) => { + impl ops::Index<$index_type> for SmallVec { + type Output = $output_type; + #[inline] + fn index(&self, index: $index_type) -> &$output_type { + &(&**self)[index] + } + } + + impl ops::IndexMut<$index_type> for SmallVec { + #[inline] + fn index_mut(&mut self, index: $index_type) -> &mut $output_type { + &mut (&mut **self)[index] + } + } + } +} + +impl_index!(usize, A::Item); +impl_index!(ops::Range, [A::Item]); +impl_index!(ops::RangeFrom, [A::Item]); +impl_index!(ops::RangeTo, [A::Item]); +impl_index!(ops::RangeFull, [A::Item]); + + +impl VecLike for SmallVec { + #[inline] + fn push(&mut self, value: A::Item) { + SmallVec::push(self, value); + } +} + +impl FromIterator for SmallVec { + fn from_iter>(iterable: I) -> SmallVec { + let mut v = SmallVec::new(); + v.extend(iterable); + v + } +} + +impl Extend for SmallVec { + fn extend>(&mut self, iterable: I) { + let iter = iterable.into_iter(); + let (lower_size_bound, _) = iter.size_hint(); + + let target_len = self.len + lower_size_bound; + + if target_len > self.capacity() { + self.grow(target_len); + } + + for elem in iter { + self.push(elem); + } + } +} + +impl fmt::Debug for SmallVec where A::Item: fmt::Debug { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "{:?}", &**self) + } +} + +impl Default for SmallVec { + #[inline] + fn default() -> SmallVec { + SmallVec::new() + } +} + +impl Drop for SmallVec { + fn drop(&mut self) { + // Note on panic safety: dropping an element may panic, + // but the inner SmallVecData destructor will still run + unsafe { + let ptr = self.as_ptr(); + for i in 0 .. self.len { + ptr::read(ptr.offset(i as isize)); + } + } + } +} + +impl Clone for SmallVec where A::Item: Clone { + fn clone(&self) -> SmallVec { + let mut new_vector = SmallVec::new(); + for element in self.iter() { + new_vector.push((*element).clone()) + } + new_vector + } +} + +impl PartialEq> for SmallVec + where A::Item: PartialEq { + #[inline] + fn eq(&self, other: &SmallVec) -> bool { self[..] == other[..] } + #[inline] + fn ne(&self, other: &SmallVec) -> bool { self[..] != other[..] } +} + +impl Eq for SmallVec where A::Item: Eq {} + +impl PartialOrd for SmallVec where A::Item: PartialOrd { + #[inline] + fn partial_cmp(&self, other: &SmallVec) -> Option { + PartialOrd::partial_cmp(&**self, &**other) + } +} + +impl Ord for SmallVec where A::Item: Ord { + #[inline] + fn cmp(&self, other: &SmallVec) -> cmp::Ordering { + Ord::cmp(&**self, &**other) + } +} + +impl Hash for SmallVec where A::Item: Hash { + fn hash(&self, state: &mut H) { + (**self).hash(state) + } +} + +unsafe impl Send for SmallVec where A::Item: Send {} + +pub struct IntoIter { + data: SmallVecData, + current: usize, + end: usize, +} + +impl Drop for IntoIter { + fn drop(&mut self) { + for _ in self { } + } +} + +impl Iterator for IntoIter { + type Item = A::Item; + + #[inline] + fn next(&mut self) -> Option { + if self.current == self.end { + None + } + else { + unsafe { + let current = self.current as isize; + self.current += 1; + Some(ptr::read(self.data.ptr_mut().offset(current))) + } + } + } + + #[inline] + fn size_hint(&self) -> (usize, Option) { + let size = self.end - self.current; + (size, Some(size)) + } +} + +impl DoubleEndedIterator for IntoIter { + #[inline] + fn next_back(&mut self) -> Option { + if self.current == self.end { + None + } + else { + unsafe { + self.end -= 1; + Some(ptr::read(self.data.ptr_mut().offset(self.end as isize))) + } + } + } +} + +impl ExactSizeIterator for IntoIter { } + +impl IntoIterator for SmallVec { + type IntoIter = IntoIter; + type Item = A::Item; + fn into_iter(mut self) -> Self::IntoIter { + let len = self.len(); + unsafe { + // Only grab the `data` field, the `IntoIter` type handles dropping of the elements + let data = ptr::read(&mut self.data); + mem::forget(self); + IntoIter { + data: data, + current: 0, + end: len, + } + } + } +} + +impl<'a, A: Array> IntoIterator for &'a SmallVec { + type IntoIter = slice::Iter<'a, A::Item>; + type Item = &'a A::Item; + fn into_iter(self) -> Self::IntoIter { + self.iter() + } +} + +impl<'a, A: Array> IntoIterator for &'a mut SmallVec { + type IntoIter = slice::IterMut<'a, A::Item>; + type Item = &'a mut A::Item; + fn into_iter(self) -> Self::IntoIter { + self.iter_mut() + } +} + +// TODO: Remove these and its users. + +/// Deprecated alias to ease transition from an earlier version. +#[deprecated] +pub type SmallVec1 = SmallVec<[T; 1]>; + +/// Deprecated alias to ease transition from an earlier version. +#[deprecated] +pub type SmallVec2 = SmallVec<[T; 2]>; + +/// Deprecated alias to ease transition from an earlier version. +#[deprecated] +pub type SmallVec4 = SmallVec<[T; 4]>; + +/// Deprecated alias to ease transition from an earlier version. +#[deprecated] +pub type SmallVec8 = SmallVec<[T; 8]>; + +/// Deprecated alias to ease transition from an earlier version. +#[deprecated] +pub type SmallVec16 = SmallVec<[T; 16]>; + +/// Deprecated alias to ease transition from an earlier version. +#[deprecated] +pub type SmallVec24 = SmallVec<[T; 24]>; + +/// Deprecated alias to ease transition from an earlier version. +#[deprecated] +pub type SmallVec32 = SmallVec<[T; 32]>; + +/// Types that can be used as the backing store for a SmallVec +pub unsafe trait Array { + type Item; + fn size() -> usize; + fn ptr(&self) -> *const Self::Item; + fn ptr_mut(&mut self) -> *mut Self::Item; +} + +macro_rules! impl_array( + ($($size:expr),+) => { + $( + unsafe impl Array for [T; $size] { + type Item = T; + fn size() -> usize { $size } + fn ptr(&self) -> *const T { &self[0] } + fn ptr_mut(&mut self) -> *mut T { &mut self[0] } + } + )+ + } +); + +impl_array!(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 20, 24, 32, 36, + 0x40, 0x80, 0x100, 0x200, 0x400, 0x800, 0x1000, 0x2000, 0x4000, 0x8000, + 0x10000, 0x20000, 0x40000, 0x80000, 0x100000); + +#[cfg(test)] +pub mod tests { + use SmallVec; + use std::borrow::ToOwned; + use std::iter::FromIterator; + + #[cfg(feature="heapsizeof")] + use heapsize::HeapSizeOf; + #[cfg(feature="heapsizeof")] + use std::mem::size_of; + + // We heap allocate all these strings so that double frees will show up under valgrind. + + #[test] + pub fn test_inline() { + let mut v = SmallVec::<[_; 16]>::new(); + v.push("hello".to_owned()); + v.push("there".to_owned()); + assert_eq!(&*v, &[ + "hello".to_owned(), + "there".to_owned(), + ][..]); + } + + #[test] + pub fn test_spill() { + let mut v = SmallVec::<[_; 2]>::new(); + v.push("hello".to_owned()); + assert_eq!(v[0], "hello"); + v.push("there".to_owned()); + v.push("burma".to_owned()); + assert_eq!(v[0], "hello"); + v.push("shave".to_owned()); + assert_eq!(&*v, &[ + "hello".to_owned(), + "there".to_owned(), + "burma".to_owned(), + "shave".to_owned(), + ][..]); + } + + #[test] + pub fn test_double_spill() { + let mut v = SmallVec::<[_; 2]>::new(); + v.push("hello".to_owned()); + v.push("there".to_owned()); + v.push("burma".to_owned()); + v.push("shave".to_owned()); + v.push("hello".to_owned()); + v.push("there".to_owned()); + v.push("burma".to_owned()); + v.push("shave".to_owned()); + assert_eq!(&*v, &[ + "hello".to_owned(), + "there".to_owned(), + "burma".to_owned(), + "shave".to_owned(), + "hello".to_owned(), + "there".to_owned(), + "burma".to_owned(), + "shave".to_owned(), + ][..]); + } + + /// https://github.com/servo/rust-smallvec/issues/4 + #[test] + fn issue_4() { + SmallVec::<[Box; 2]>::new(); + } + + /// https://github.com/servo/rust-smallvec/issues/5 + #[test] + fn issue_5() { + assert!(Some(SmallVec::<[&u32; 2]>::new()).is_some()); + } + + #[test] + fn drain() { + let mut v: SmallVec<[u8; 2]> = SmallVec::new(); + v.push(3); + assert_eq!(v.drain().collect::>(), &[3]); + + // spilling the vec + v.push(3); + v.push(4); + v.push(5); + assert_eq!(v.drain().collect::>(), &[3, 4, 5]); + } + + #[test] + fn drain_rev() { + let mut v: SmallVec<[u8; 2]> = SmallVec::new(); + v.push(3); + assert_eq!(v.drain().rev().collect::>(), &[3]); + + // spilling the vec + v.push(3); + v.push(4); + v.push(5); + assert_eq!(v.drain().rev().collect::>(), &[5, 4, 3]); + } + + #[test] + fn into_iter() { + let mut v: SmallVec<[u8; 2]> = SmallVec::new(); + v.push(3); + assert_eq!(v.into_iter().collect::>(), &[3]); + + // spilling the vec + let mut v: SmallVec<[u8; 2]> = SmallVec::new(); + v.push(3); + v.push(4); + v.push(5); + assert_eq!(v.into_iter().collect::>(), &[3, 4, 5]); + } + + #[test] + fn into_iter_rev() { + let mut v: SmallVec<[u8; 2]> = SmallVec::new(); + v.push(3); + assert_eq!(v.into_iter().rev().collect::>(), &[3]); + + // spilling the vec + let mut v: SmallVec<[u8; 2]> = SmallVec::new(); + v.push(3); + v.push(4); + v.push(5); + assert_eq!(v.into_iter().rev().collect::>(), &[5, 4, 3]); + } + + #[test] + fn into_iter_drop() { + use std::cell::Cell; + + struct DropCounter<'a>(&'a Cell); + + impl<'a> Drop for DropCounter<'a> { + fn drop(&mut self) { + self.0.set(self.0.get() + 1); + } + } + + { + let cell = Cell::new(0); + let mut v: SmallVec<[DropCounter; 2]> = SmallVec::new(); + v.push(DropCounter(&cell)); + v.into_iter(); + assert_eq!(cell.get(), 1); + } + + { + let cell = Cell::new(0); + let mut v: SmallVec<[DropCounter; 2]> = SmallVec::new(); + v.push(DropCounter(&cell)); + v.push(DropCounter(&cell)); + assert!(v.into_iter().next().is_some()); + assert_eq!(cell.get(), 2); + } + + { + let cell = Cell::new(0); + let mut v: SmallVec<[DropCounter; 2]> = SmallVec::new(); + v.push(DropCounter(&cell)); + v.push(DropCounter(&cell)); + v.push(DropCounter(&cell)); + assert!(v.into_iter().next().is_some()); + assert_eq!(cell.get(), 3); + } + { + let cell = Cell::new(0); + let mut v: SmallVec<[DropCounter; 2]> = SmallVec::new(); + v.push(DropCounter(&cell)); + v.push(DropCounter(&cell)); + v.push(DropCounter(&cell)); + { + let mut it = v.into_iter(); + assert!(it.next().is_some()); + assert!(it.next_back().is_some()); + } + assert_eq!(cell.get(), 3); + } + } + + #[test] + fn test_capacity() { + let mut v: SmallVec<[u8; 2]> = SmallVec::new(); + v.reserve(1); + assert_eq!(v.capacity(), 2); + assert!(!v.spilled()); + + v.reserve_exact(0x100); + assert!(v.capacity() >= 0x100); + + v.push(0); + v.push(1); + v.push(2); + v.push(3); + + v.shrink_to_fit(); + assert!(v.capacity() < 0x100); + } + + #[test] + fn test_truncate() { + let mut v: SmallVec<[Box; 8]> = SmallVec::new(); + + for x in 0..8 { + v.push(Box::new(x)); + } + v.truncate(4); + + assert_eq!(v.len(), 4); + assert!(!v.spilled()); + + assert_eq!(*v.swap_remove(1), 1); + assert_eq!(*v.remove(1), 3); + v.insert(1, Box::new(3)); + + assert_eq!(&v.iter().map(|v| **v).collect::>(), &[0, 3, 2]); + } + + #[test] + fn test_insert_many() { + let mut v: SmallVec<[u8; 8]> = SmallVec::new(); + for x in 0..4 { + v.push(x); + } + assert_eq!(v.len(), 4); + v.insert_many(1, [5, 6].iter().cloned()); + assert_eq!(&v.iter().map(|v| *v).collect::>(), &[0, 5, 6, 1, 2, 3]); + } + + struct MockHintIter{x: T, hint: usize} + impl Iterator for MockHintIter { + type Item = T::Item; + fn next(&mut self) -> Option {self.x.next()} + fn size_hint(&self) -> (usize, Option) {(self.hint, None)} + } + + #[test] + fn test_insert_many_short_hint() { + let mut v: SmallVec<[u8; 8]> = SmallVec::new(); + for x in 0..4 { + v.push(x); + } + assert_eq!(v.len(), 4); + v.insert_many(1, MockHintIter{x: [5, 6].iter().cloned(), hint: 5}); + assert_eq!(&v.iter().map(|v| *v).collect::>(), &[0, 5, 6, 1, 2, 3]); + } + + #[test] + fn test_insert_many_long_hint() { + let mut v: SmallVec<[u8; 8]> = SmallVec::new(); + for x in 0..4 { + v.push(x); + } + assert_eq!(v.len(), 4); + v.insert_many(1, MockHintIter{x: [5, 6].iter().cloned(), hint: 1}); + assert_eq!(&v.iter().map(|v| *v).collect::>(), &[0, 5, 6, 1, 2, 3]); + } + + #[test] + #[should_panic] + fn test_invalid_grow() { + let mut v: SmallVec<[u8; 8]> = SmallVec::new(); + v.extend(0..8); + v.grow(5); + } + + #[test] + fn test_insert_from_slice() { + let mut v: SmallVec<[u8; 8]> = SmallVec::new(); + for x in 0..4 { + v.push(x); + } + assert_eq!(v.len(), 4); + v.insert_from_slice(1, &[5, 6]); + assert_eq!(&v.iter().map(|v| *v).collect::>(), &[0, 5, 6, 1, 2, 3]); + } + + #[test] + fn test_extend_from_slice() { + let mut v: SmallVec<[u8; 8]> = SmallVec::new(); + for x in 0..4 { + v.push(x); + } + assert_eq!(v.len(), 4); + v.extend_from_slice(&[5, 6]); + assert_eq!(&v.iter().map(|v| *v).collect::>(), &[0, 1, 2, 3, 5, 6]); + } + + #[test] + #[should_panic] + fn test_drop_panic_smallvec() { + // This test should only panic once, and not double panic, + // which would mean a double drop + struct DropPanic; + + impl Drop for DropPanic { + fn drop(&mut self) { + panic!("drop"); + } + } + + let mut v = SmallVec::<[_; 1]>::new(); + v.push(DropPanic); + } + + #[test] + fn test_eq() { + let mut a: SmallVec<[u32; 2]> = SmallVec::new(); + let mut b: SmallVec<[u32; 2]> = SmallVec::new(); + let mut c: SmallVec<[u32; 2]> = SmallVec::new(); + // a = [1, 2] + a.push(1); + a.push(2); + // b = [1, 2] + b.push(1); + b.push(2); + // c = [3, 4] + c.push(3); + c.push(4); + + assert!(a == b); + assert!(a != c); + } + + #[test] + fn test_ord() { + let mut a: SmallVec<[u32; 2]> = SmallVec::new(); + let mut b: SmallVec<[u32; 2]> = SmallVec::new(); + let mut c: SmallVec<[u32; 2]> = SmallVec::new(); + // a = [1] + a.push(1); + // b = [1, 1] + b.push(1); + b.push(1); + // c = [1, 2] + c.push(1); + c.push(2); + + assert!(a < b); + assert!(b > a); + assert!(b < c); + assert!(c > b); + } + + #[test] + fn test_hash() { + use std::hash::Hash; + use std::collections::hash_map::DefaultHasher; + + { + let mut a: SmallVec<[u32; 2]> = SmallVec::new(); + let b = [1, 2]; + a.extend(b.iter().cloned()); + let mut hasher = DefaultHasher::new(); + assert_eq!(a.hash(&mut hasher), b.hash(&mut hasher)); + } + { + let mut a: SmallVec<[u32; 2]> = SmallVec::new(); + let b = [1, 2, 11, 12]; + a.extend(b.iter().cloned()); + let mut hasher = DefaultHasher::new(); + assert_eq!(a.hash(&mut hasher), b.hash(&mut hasher)); + } + } + + #[test] + fn test_as_ref() { + let mut a: SmallVec<[u32; 2]> = SmallVec::new(); + a.push(1); + assert_eq!(a.as_ref(), [1]); + a.push(2); + assert_eq!(a.as_ref(), [1, 2]); + a.push(3); + assert_eq!(a.as_ref(), [1, 2, 3]); + } + + #[test] + fn test_as_mut() { + let mut a: SmallVec<[u32; 2]> = SmallVec::new(); + a.push(1); + assert_eq!(a.as_mut(), [1]); + a.push(2); + assert_eq!(a.as_mut(), [1, 2]); + a.push(3); + assert_eq!(a.as_mut(), [1, 2, 3]); + a.as_mut()[1] = 4; + assert_eq!(a.as_mut(), [1, 4, 3]); + } + + #[test] + fn test_borrow() { + use std::borrow::Borrow; + + let mut a: SmallVec<[u32; 2]> = SmallVec::new(); + a.push(1); + assert_eq!(a.borrow(), [1]); + a.push(2); + assert_eq!(a.borrow(), [1, 2]); + a.push(3); + assert_eq!(a.borrow(), [1, 2, 3]); + } + + #[test] + fn test_borrow_mut() { + use std::borrow::BorrowMut; + + let mut a: SmallVec<[u32; 2]> = SmallVec::new(); + a.push(1); + assert_eq!(a.borrow_mut(), [1]); + a.push(2); + assert_eq!(a.borrow_mut(), [1, 2]); + a.push(3); + assert_eq!(a.borrow_mut(), [1, 2, 3]); + BorrowMut::<[u32]>::borrow_mut(&mut a)[1] = 4; + assert_eq!(a.borrow_mut(), [1, 4, 3]); + } + + #[test] + fn test_from() { + assert_eq!(&SmallVec::<[u32; 2]>::from(&[1][..])[..], [1]); + assert_eq!(&SmallVec::<[u32; 2]>::from(&[1, 2, 3][..])[..], [1, 2, 3]); + } + + #[test] + fn test_from_slice() { + assert_eq!(&SmallVec::<[u32; 2]>::from_slice(&[1][..])[..], [1]); + assert_eq!(&SmallVec::<[u32; 2]>::from_slice(&[1, 2, 3][..])[..], [1, 2, 3]); + } + + #[cfg(feature="heapsizeof")] + #[test] + fn test_heap_size_of_children() { + let mut vec = SmallVec::<[u32; 2]>::new(); + assert_eq!(vec.heap_size_of_children(), 0); + vec.push(1); + vec.push(2); + assert_eq!(vec.heap_size_of_children(), 0); + vec.push(3); + assert_eq!(vec.heap_size_of_children(), 16); + + // Now check with reserved space + let mut vec = SmallVec::<[u32; 2]>::new(); + vec.reserve(10); // Rounds up to 16 + assert_eq!(vec.heap_size_of_children(), 64); + + // Check with nested heap structures + let mut vec = SmallVec::<[Vec; 2]>::new(); + vec.reserve(10); + vec.push(vec![2, 3, 4]); + assert_eq!(vec.heap_size_of_children(), + vec![2, 3, 4].heap_size_of_children() + 16 * size_of::>()); + } + + #[test] + fn test_exact_size_iterator() { + let mut vec = SmallVec::<[u32; 2]>::from(&[1, 2, 3][..]); + assert_eq!(vec.clone().into_iter().len(), 3); + assert_eq!(vec.drain().len(), 3); + } + + #[test] + fn veclike_deref_slice() { + use super::VecLike; + + fn test>(vec: &mut T) { + assert!(!vec.is_empty()); + assert_eq!(vec.len(), 3); + + vec.sort(); + assert_eq!(&vec[..], [1, 2, 3]); + } + + let mut vec = SmallVec::<[i32; 2]>::from(&[3, 1, 2][..]); + test(&mut vec); + } + + #[test] + fn shrink_to_fit_unspill() { + let mut vec = SmallVec::<[u8; 2]>::from_iter(0..3); + vec.pop(); + assert!(vec.spilled()); + vec.shrink_to_fit(); + assert!(!vec.spilled(), "shrink_to_fit will un-spill if possible"); + } + + #[test] + fn test_into_vec() { + let vec = SmallVec::<[u8; 2]>::from_iter(0..2); + assert_eq!(vec.into_vec(), vec![0, 1]); + + let vec = SmallVec::<[u8; 2]>::from_iter(0..3); + assert_eq!(vec.into_vec(), vec![0, 1, 2]); + } + + #[test] + fn test_from_vec() { + let vec = vec![]; + let small_vec: SmallVec<[u8; 3]> = SmallVec::from_vec(vec); + assert_eq!(&*small_vec, &[]); + drop(small_vec); + + let vec = vec![]; + let small_vec: SmallVec<[u8; 1]> = SmallVec::from_vec(vec); + assert_eq!(&*small_vec, &[]); + drop(small_vec); + + let vec = vec![1]; + let small_vec: SmallVec<[u8; 3]> = SmallVec::from_vec(vec); + assert_eq!(&*small_vec, &[1]); + drop(small_vec); + + let vec = vec![1, 2, 3]; + let small_vec: SmallVec<[u8; 3]> = SmallVec::from_vec(vec); + assert_eq!(&*small_vec, &[1, 2, 3]); + drop(small_vec); + + let vec = vec![1, 2, 3, 4, 5]; + let small_vec: SmallVec<[u8; 3]> = SmallVec::from_vec(vec); + assert_eq!(&*small_vec, &[1, 2, 3, 4, 5]); + drop(small_vec); + + let vec = vec![1, 2, 3, 4, 5]; + let small_vec: SmallVec<[u8; 1]> = SmallVec::from_vec(vec); + assert_eq!(&*small_vec, &[1, 2, 3, 4, 5]); + drop(small_vec); + } +} diff --git a/third_party/rust/smallvec/.cargo-checksum.json b/third_party/rust/smallvec/.cargo-checksum.json index 66ad40a6677c..df64d9c1fe9c 100644 --- a/third_party/rust/smallvec/.cargo-checksum.json +++ b/third_party/rust/smallvec/.cargo-checksum.json @@ -1 +1 @@ -{"files":{".cargo-ok":"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",".gitignore":"f9b1ca6ae27d1c18215265024629a8960c31379f206d9ed20f64e0b2dcf79805",".travis.yml":"8d8372a5e10c6d301d70d45da3d51a4b8cbd6d51b57a62e7730942adc69da200","Cargo.toml":"48402d1ef9c6e0015e98104e1b9ec5c406a2e5ca5d8f8b0382a1ed4decdf96f8","README.md":"85c6105e404b1febba9e06773350cc81fe5966369530210669b3465c66237a09","benches/bench.rs":"54cf4879d36ba2a9f3423af91bb93227b70849200e5bf74e384a166d6aa09893","lib.rs":"acdf2c4778adb0b613efb08ff4612d8d7fb2d67747da026ab3894539e7f3e3ed"},"package":"4f8266519bc1d17d0b5b16f6c21295625d562841c708f6376f49028a43e9c11e"} \ No newline at end of file +{"files":{".cargo-ok":"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",".gitignore":"f9b1ca6ae27d1c18215265024629a8960c31379f206d9ed20f64e0b2dcf79805",".travis.yml":"8d8372a5e10c6d301d70d45da3d51a4b8cbd6d51b57a62e7730942adc69da200","Cargo.toml":"faecc14df6dfd788ebcb312f891846ecf2ea08fd081d242a7318e3015490ee77","README.md":"85c6105e404b1febba9e06773350cc81fe5966369530210669b3465c66237a09","benches/bench.rs":"54cf4879d36ba2a9f3423af91bb93227b70849200e5bf74e384a166d6aa09893","lib.rs":"acdf2c4778adb0b613efb08ff4612d8d7fb2d67747da026ab3894539e7f3e3ed"},"package":"2e40af10aafe98b4d8294ae8388d8a5cd0707c65d364872efe72d063ec44bee0"} \ No newline at end of file diff --git a/third_party/rust/smallvec/Cargo.toml b/third_party/rust/smallvec/Cargo.toml index 2a64c0419afc..47c34fbd7a7a 100644 --- a/third_party/rust/smallvec/Cargo.toml +++ b/third_party/rust/smallvec/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "smallvec" -version = "0.3.3" +version = "0.4.0" authors = ["Simon Sapin "] license = "MPL-2.0" repository = "https://github.com/servo/rust-smallvec" @@ -17,4 +17,4 @@ name = "smallvec" path = "lib.rs" [dependencies] -heapsize = { version = "0.3", optional = true } +heapsize = { version = "0.4", optional = true } diff --git a/toolkit/library/gtest/rust/Cargo.lock b/toolkit/library/gtest/rust/Cargo.lock index 70cefeff0e29..22d64cd732c6 100644 --- a/toolkit/library/gtest/rust/Cargo.lock +++ b/toolkit/library/gtest/rust/Cargo.lock @@ -287,18 +287,6 @@ dependencies = [ "regex 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "euclid" -version = "0.11.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "heapsize 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", - "num-traits 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-serialize 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 0.9.9 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "euclid" version = "0.13.0" @@ -789,7 +777,7 @@ dependencies = [ "phf 0.7.21 (registry+https://github.com/rust-lang/crates.io-index)", "phf_codegen 0.7.21 (registry+https://github.com/rust-lang/crates.io-index)", "precomputed-hash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "smallvec 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "smallvec 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -838,6 +826,11 @@ name = "smallvec" version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "smallvec" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "strsim" version = "0.6.0" @@ -857,7 +850,7 @@ dependencies = [ "byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "cfg-if 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "cssparser 0.13.7 (registry+https://github.com/rust-lang/crates.io-index)", - "euclid 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)", + "euclid 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", "itoa 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -875,7 +868,7 @@ dependencies = [ "rayon 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "regex 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "selectors 0.19.0", - "smallvec 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "smallvec 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "style_derive 0.0.1", "style_traits 0.0.1", "time 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)", @@ -900,7 +893,7 @@ version = "0.0.1" dependencies = [ "app_units 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "cssparser 0.13.7 (registry+https://github.com/rust-lang/crates.io-index)", - "euclid 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)", + "euclid 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1205,7 +1198,6 @@ dependencies = [ "checksum deque 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1614659040e711785ed8ea24219140654da1729f3ec8a47a9719d041112fe7bf" "checksum dwrote 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "74114b6b49d6731835da7a28a3642651451e315f7f9b9d04e907e65a45681796" "checksum env_logger 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ed39959122ea027670b704fb70539f4286ddf4a49eefede23bf0b4b2a069ec03" -"checksum euclid 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "f5517462c626a893f3b027615e88d7102cc6dd3f7f1bcb90c7220fb1da4970b5" "checksum euclid 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6083f113c422ff9cd855a1cf6cc8ec0903606c0eb43a0c6a0ced3bdc9731e4c1" "checksum fnv 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "6cc484842f1e2884faf56f529f960cc12ad8c71ce96cc7abba0a067c98fee344" "checksum freetype 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fde23272c687e4570aefec06cb71174ec0f5284b725deac4e77ba2665d635faf" @@ -1265,6 +1257,7 @@ dependencies = [ "checksum serde_derive 0.9.11 (registry+https://github.com/rust-lang/crates.io-index)" = "f15ea24bd037b2d64646b4d934fa99c649be66e3f7b29fb595a5543b212b1452" "checksum siphasher 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2ffc669b726f2bc9a3bcff66e5e23b56ba6bf70e22a34c3d7b6d0b3450b65b84" "checksum smallvec 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "4f8266519bc1d17d0b5b16f6c21295625d562841c708f6376f49028a43e9c11e" +"checksum smallvec 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2e40af10aafe98b4d8294ae8388d8a5cd0707c65d364872efe72d063ec44bee0" "checksum strsim 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b4d15c810519a91cf877e7e36e63fe068815c678181439f2f29e2562147c3694" "checksum syn 0.11.8 (registry+https://github.com/rust-lang/crates.io-index)" = "37c279fb816210c9bb28b2c292664581e7b87b4561e86b94df462664d8620bb8" "checksum synom 0.11.2 (registry+https://github.com/rust-lang/crates.io-index)" = "27e31aa4b09b9f4cb12dff3c30ba503e17b1a624413d764d32dab76e3920e5bc" diff --git a/toolkit/library/rust/Cargo.lock b/toolkit/library/rust/Cargo.lock index 45e68f3bef19..b470c8dc9dec 100644 --- a/toolkit/library/rust/Cargo.lock +++ b/toolkit/library/rust/Cargo.lock @@ -285,18 +285,6 @@ dependencies = [ "regex 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "euclid" -version = "0.11.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "heapsize 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", - "num-traits 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-serialize 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 0.9.9 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "euclid" version = "0.13.0" @@ -776,7 +764,7 @@ dependencies = [ "phf 0.7.21 (registry+https://github.com/rust-lang/crates.io-index)", "phf_codegen 0.7.21 (registry+https://github.com/rust-lang/crates.io-index)", "precomputed-hash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "smallvec 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "smallvec 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -825,6 +813,11 @@ name = "smallvec" version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "smallvec" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "strsim" version = "0.6.0" @@ -844,7 +837,7 @@ dependencies = [ "byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "cfg-if 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "cssparser 0.13.7 (registry+https://github.com/rust-lang/crates.io-index)", - "euclid 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)", + "euclid 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", "itoa 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -862,7 +855,7 @@ dependencies = [ "rayon 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "regex 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "selectors 0.19.0", - "smallvec 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "smallvec 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "style_derive 0.0.1", "style_traits 0.0.1", "time 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)", @@ -887,7 +880,7 @@ version = "0.0.1" dependencies = [ "app_units 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "cssparser 0.13.7 (registry+https://github.com/rust-lang/crates.io-index)", - "euclid 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)", + "euclid 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1192,7 +1185,6 @@ dependencies = [ "checksum deque 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1614659040e711785ed8ea24219140654da1729f3ec8a47a9719d041112fe7bf" "checksum dwrote 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "74114b6b49d6731835da7a28a3642651451e315f7f9b9d04e907e65a45681796" "checksum env_logger 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ed39959122ea027670b704fb70539f4286ddf4a49eefede23bf0b4b2a069ec03" -"checksum euclid 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "f5517462c626a893f3b027615e88d7102cc6dd3f7f1bcb90c7220fb1da4970b5" "checksum euclid 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6083f113c422ff9cd855a1cf6cc8ec0903606c0eb43a0c6a0ced3bdc9731e4c1" "checksum fnv 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "6cc484842f1e2884faf56f529f960cc12ad8c71ce96cc7abba0a067c98fee344" "checksum freetype 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fde23272c687e4570aefec06cb71174ec0f5284b725deac4e77ba2665d635faf" @@ -1252,6 +1244,7 @@ dependencies = [ "checksum serde_derive 0.9.11 (registry+https://github.com/rust-lang/crates.io-index)" = "f15ea24bd037b2d64646b4d934fa99c649be66e3f7b29fb595a5543b212b1452" "checksum siphasher 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2ffc669b726f2bc9a3bcff66e5e23b56ba6bf70e22a34c3d7b6d0b3450b65b84" "checksum smallvec 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "4f8266519bc1d17d0b5b16f6c21295625d562841c708f6376f49028a43e9c11e" +"checksum smallvec 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2e40af10aafe98b4d8294ae8388d8a5cd0707c65d364872efe72d063ec44bee0" "checksum strsim 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b4d15c810519a91cf877e7e36e63fe068815c678181439f2f29e2562147c3694" "checksum syn 0.11.8 (registry+https://github.com/rust-lang/crates.io-index)" = "37c279fb816210c9bb28b2c292664581e7b87b4561e86b94df462664d8620bb8" "checksum synom 0.11.2 (registry+https://github.com/rust-lang/crates.io-index)" = "27e31aa4b09b9f4cb12dff3c30ba503e17b1a624413d764d32dab76e3920e5bc"