euclid.rs (6788B)
1 // Copyright 2019 The Servo Project Developers. See the COPYRIGHT 2 // file at the top-level directory of this distribution and at 3 // http://rust-lang.org/COPYRIGHT. 4 // 5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or 6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license 7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your 8 // option. This file may not be copied, modified, or distributed 9 // except according to those terms. 10 11 #![allow(clippy::let_and_return)] 12 13 use crate::{Peek, Poke}; 14 use euclid::{Point2D, Rect, Box2D, SideOffsets2D, Size2D, Transform3D, Vector2D}; 15 16 unsafe impl<T: Poke, U> Poke for Point2D<T, U> { 17 #[inline(always)] 18 fn max_size() -> usize { 19 2 * T::max_size() 20 } 21 #[inline(always)] 22 unsafe fn poke_into(&self, bytes: *mut u8) -> *mut u8 { 23 let bytes = self.x.poke_into(bytes); 24 let bytes = self.y.poke_into(bytes); 25 bytes 26 } 27 } 28 impl<T: Peek, U> Peek for Point2D<T, U> { 29 #[inline(always)] 30 unsafe fn peek_from(bytes: *const u8, output: *mut Self) -> *const u8 { 31 let bytes = T::peek_from(bytes, &mut (*output).x); 32 let bytes = T::peek_from(bytes, &mut (*output).y); 33 bytes 34 } 35 } 36 37 unsafe impl<T: Poke, U> Poke for Rect<T, U> { 38 #[inline(always)] 39 fn max_size() -> usize { 40 Point2D::<T, U>::max_size() + Size2D::<T, U>::max_size() 41 } 42 #[inline(always)] 43 unsafe fn poke_into(&self, bytes: *mut u8) -> *mut u8 { 44 let bytes = self.origin.poke_into(bytes); 45 let bytes = self.size.poke_into(bytes); 46 bytes 47 } 48 } 49 impl<T: Peek, U> Peek for Rect<T, U> { 50 #[inline(always)] 51 unsafe fn peek_from(bytes: *const u8, output: *mut Self) -> *const u8 { 52 let bytes = Point2D::<T, U>::peek_from(bytes, &mut (*output).origin); 53 let bytes = Size2D::<T, U>::peek_from(bytes, &mut (*output).size); 54 bytes 55 } 56 } 57 58 unsafe impl<T: Poke, U> Poke for Box2D<T, U> { 59 #[inline(always)] 60 fn max_size() -> usize { 61 Point2D::<T, U>::max_size() * 2 62 } 63 #[inline(always)] 64 unsafe fn poke_into(&self, bytes: *mut u8) -> *mut u8 { 65 let bytes = self.min.poke_into(bytes); 66 let bytes = self.max.poke_into(bytes); 67 bytes 68 } 69 } 70 impl<T: Peek, U> Peek for Box2D<T, U> { 71 #[inline(always)] 72 unsafe fn peek_from(bytes: *const u8, output: *mut Self) -> *const u8 { 73 let bytes = Point2D::<T, U>::peek_from(bytes, &mut (*output).min); 74 let bytes = Point2D::<T, U>::peek_from(bytes, &mut (*output).max); 75 bytes 76 } 77 } 78 79 unsafe impl<T: Poke, U> Poke for SideOffsets2D<T, U> { 80 #[inline(always)] 81 fn max_size() -> usize { 82 4 * T::max_size() 83 } 84 #[inline(always)] 85 unsafe fn poke_into(&self, bytes: *mut u8) -> *mut u8 { 86 let bytes = self.top.poke_into(bytes); 87 let bytes = self.right.poke_into(bytes); 88 let bytes = self.bottom.poke_into(bytes); 89 let bytes = self.left.poke_into(bytes); 90 bytes 91 } 92 } 93 impl<T: Peek, U> Peek for SideOffsets2D<T, U> { 94 #[inline(always)] 95 unsafe fn peek_from(bytes: *const u8, output: *mut Self) -> *const u8 { 96 let bytes = T::peek_from(bytes, &mut (*output).top); 97 let bytes = T::peek_from(bytes, &mut (*output).right); 98 let bytes = T::peek_from(bytes, &mut (*output).bottom); 99 let bytes = T::peek_from(bytes, &mut (*output).left); 100 bytes 101 } 102 } 103 104 unsafe impl<T: Poke, U> Poke for Size2D<T, U> { 105 #[inline(always)] 106 fn max_size() -> usize { 107 2 * T::max_size() 108 } 109 #[inline(always)] 110 unsafe fn poke_into(&self, bytes: *mut u8) -> *mut u8 { 111 let bytes = self.width.poke_into(bytes); 112 let bytes = self.height.poke_into(bytes); 113 bytes 114 } 115 } 116 impl<T: Peek, U> Peek for Size2D<T, U> { 117 #[inline(always)] 118 unsafe fn peek_from(bytes: *const u8, output: *mut Self) -> *const u8 { 119 let bytes = T::peek_from(bytes, &mut (*output).width); 120 let bytes = T::peek_from(bytes, &mut (*output).height); 121 bytes 122 } 123 } 124 125 unsafe impl<T: Poke, S, D> Poke for Transform3D<T, S, D> { 126 #[inline(always)] 127 fn max_size() -> usize { 128 16 * T::max_size() 129 } 130 #[inline(always)] 131 unsafe fn poke_into(&self, bytes: *mut u8) -> *mut u8 { 132 let bytes = self.m11.poke_into(bytes); 133 let bytes = self.m12.poke_into(bytes); 134 let bytes = self.m13.poke_into(bytes); 135 let bytes = self.m14.poke_into(bytes); 136 let bytes = self.m21.poke_into(bytes); 137 let bytes = self.m22.poke_into(bytes); 138 let bytes = self.m23.poke_into(bytes); 139 let bytes = self.m24.poke_into(bytes); 140 let bytes = self.m31.poke_into(bytes); 141 let bytes = self.m32.poke_into(bytes); 142 let bytes = self.m33.poke_into(bytes); 143 let bytes = self.m34.poke_into(bytes); 144 let bytes = self.m41.poke_into(bytes); 145 let bytes = self.m42.poke_into(bytes); 146 let bytes = self.m43.poke_into(bytes); 147 let bytes = self.m44.poke_into(bytes); 148 bytes 149 } 150 } 151 impl<T: Peek, S, D> Peek for Transform3D<T, S, D> { 152 #[inline(always)] 153 unsafe fn peek_from(bytes: *const u8, output: *mut Self) -> *const u8 { 154 let bytes = T::peek_from(bytes, &mut (*output).m11); 155 let bytes = T::peek_from(bytes, &mut (*output).m12); 156 let bytes = T::peek_from(bytes, &mut (*output).m13); 157 let bytes = T::peek_from(bytes, &mut (*output).m14); 158 let bytes = T::peek_from(bytes, &mut (*output).m21); 159 let bytes = T::peek_from(bytes, &mut (*output).m22); 160 let bytes = T::peek_from(bytes, &mut (*output).m23); 161 let bytes = T::peek_from(bytes, &mut (*output).m24); 162 let bytes = T::peek_from(bytes, &mut (*output).m31); 163 let bytes = T::peek_from(bytes, &mut (*output).m32); 164 let bytes = T::peek_from(bytes, &mut (*output).m33); 165 let bytes = T::peek_from(bytes, &mut (*output).m34); 166 let bytes = T::peek_from(bytes, &mut (*output).m41); 167 let bytes = T::peek_from(bytes, &mut (*output).m42); 168 let bytes = T::peek_from(bytes, &mut (*output).m43); 169 let bytes = T::peek_from(bytes, &mut (*output).m44); 170 bytes 171 } 172 } 173 174 unsafe impl<T: Poke, U> Poke for Vector2D<T, U> { 175 #[inline(always)] 176 fn max_size() -> usize { 177 2 * T::max_size() 178 } 179 #[inline(always)] 180 unsafe fn poke_into(&self, bytes: *mut u8) -> *mut u8 { 181 let bytes = self.x.poke_into(bytes); 182 let bytes = self.y.poke_into(bytes); 183 bytes 184 } 185 } 186 impl<T: Peek, U> Peek for Vector2D<T, U> { 187 #[inline(always)] 188 unsafe fn peek_from(bytes: *const u8, output: *mut Self) -> *const u8 { 189 let bytes = T::peek_from(bytes, &mut (*output).x); 190 let bytes = T::peek_from(bytes, &mut (*output).y); 191 bytes 192 } 193 }