summaryrefslogtreecommitdiffstats
path: root/gfx/wr/peek-poke/src/euclid.rs
blob: dc4dd7774b4aa120c592c9a84cbc539be34d6edd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
// Copyright 2019 The Servo Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use crate::{Peek, Poke};
use euclid::{Point2D, Rect, Box2D, SideOffsets2D, Size2D, Transform3D, Vector2D};

unsafe impl<T: Poke, U> Poke for Point2D<T, U> {
    #[inline(always)]
    fn max_size() -> usize {
        2 * T::max_size()
    }
    #[inline(always)]
    unsafe fn poke_into(&self, bytes: *mut u8) -> *mut u8 {
        let bytes = self.x.poke_into(bytes);
        let bytes = self.y.poke_into(bytes);
        bytes
    }
}
impl<T: Peek, U> Peek for Point2D<T, U> {
    #[inline(always)]
    unsafe fn peek_from(bytes: *const u8, output: *mut Self) -> *const u8 {
        let bytes = T::peek_from(bytes, &mut (*output).x);
        let bytes = T::peek_from(bytes, &mut (*output).y);
        bytes
    }
}

unsafe impl<T: Poke, U> Poke for Rect<T, U> {
    #[inline(always)]
    fn max_size() -> usize {
        Point2D::<T, U>::max_size() + Size2D::<T, U>::max_size()
    }
    #[inline(always)]
    unsafe fn poke_into(&self, bytes: *mut u8) -> *mut u8 {
        let bytes = self.origin.poke_into(bytes);
        let bytes = self.size.poke_into(bytes);
        bytes
    }
}
impl<T: Peek, U> Peek for Rect<T, U> {
    #[inline(always)]
    unsafe fn peek_from(bytes: *const u8, output: *mut Self) -> *const u8 {
        let bytes = Point2D::<T, U>::peek_from(bytes, &mut (*output).origin);
        let bytes = Size2D::<T, U>::peek_from(bytes, &mut (*output).size);
        bytes
    }
}

unsafe impl<T: Poke, U> Poke for Box2D<T, U> {
    #[inline(always)]
    fn max_size() -> usize {
        Point2D::<T, U>::max_size() * 2
    }
    #[inline(always)]
    unsafe fn poke_into(&self, bytes: *mut u8) -> *mut u8 {
        let bytes = self.min.poke_into(bytes);
        let bytes = self.max.poke_into(bytes);
        bytes
    }
}
impl<T: Peek, U> Peek for Box2D<T, U> {
    #[inline(always)]
    unsafe fn peek_from(bytes: *const u8, output: *mut Self) -> *const u8 {
        let bytes = Point2D::<T, U>::peek_from(bytes, &mut (*output).min);
        let bytes = Point2D::<T, U>::peek_from(bytes, &mut (*output).max);
        bytes
    }
}

unsafe impl<T: Poke, U> Poke for SideOffsets2D<T, U> {
    #[inline(always)]
    fn max_size() -> usize {
        4 * T::max_size()
    }
    #[inline(always)]
    unsafe fn poke_into(&self, bytes: *mut u8) -> *mut u8 {
        let bytes = self.top.poke_into(bytes);
        let bytes = self.right.poke_into(bytes);
        let bytes = self.bottom.poke_into(bytes);
        let bytes = self.left.poke_into(bytes);
        bytes
    }
}
impl<T: Peek, U> Peek for SideOffsets2D<T, U> {
    #[inline(always)]
    unsafe fn peek_from(bytes: *const u8, output: *mut Self) -> *const u8 {
        let bytes = T::peek_from(bytes, &mut (*output).top);
        let bytes = T::peek_from(bytes, &mut (*output).right);
        let bytes = T::peek_from(bytes, &mut (*output).bottom);
        let bytes = T::peek_from(bytes, &mut (*output).left);
        bytes
    }
}

unsafe impl<T: Poke, U> Poke for Size2D<T, U> {
    #[inline(always)]
    fn max_size() -> usize {
        2 * T::max_size()
    }
    #[inline(always)]
    unsafe fn poke_into(&self, bytes: *mut u8) -> *mut u8 {
        let bytes = self.width.poke_into(bytes);
        let bytes = self.height.poke_into(bytes);
        bytes
    }
}
impl<T: Peek, U> Peek for Size2D<T, U> {
    #[inline(always)]
    unsafe fn peek_from(bytes: *const u8, output: *mut Self) -> *const u8 {
        let bytes = T::peek_from(bytes, &mut (*output).width);
        let bytes = T::peek_from(bytes, &mut (*output).height);
        bytes
    }
}

unsafe impl<T: Poke, S, D> Poke for Transform3D<T, S, D> {
    #[inline(always)]
    fn max_size() -> usize {
        16 * T::max_size()
    }
    #[inline(always)]
    unsafe fn poke_into(&self, bytes: *mut u8) -> *mut u8 {
        let bytes = self.m11.poke_into(bytes);
        let bytes = self.m12.poke_into(bytes);
        let bytes = self.m13.poke_into(bytes);
        let bytes = self.m14.poke_into(bytes);
        let bytes = self.m21.poke_into(bytes);
        let bytes = self.m22.poke_into(bytes);
        let bytes = self.m23.poke_into(bytes);
        let bytes = self.m24.poke_into(bytes);
        let bytes = self.m31.poke_into(bytes);
        let bytes = self.m32.poke_into(bytes);
        let bytes = self.m33.poke_into(bytes);
        let bytes = self.m34.poke_into(bytes);
        let bytes = self.m41.poke_into(bytes);
        let bytes = self.m42.poke_into(bytes);
        let bytes = self.m43.poke_into(bytes);
        let bytes = self.m44.poke_into(bytes);
        bytes
    }
}
impl<T: Peek, S, D> Peek for Transform3D<T, S, D> {
    #[inline(always)]
    unsafe fn peek_from(bytes: *const u8, output: *mut Self) -> *const u8 {
        let bytes = T::peek_from(bytes, &mut (*output).m11);
        let bytes = T::peek_from(bytes, &mut (*output).m12);
        let bytes = T::peek_from(bytes, &mut (*output).m13);
        let bytes = T::peek_from(bytes, &mut (*output).m14);
        let bytes = T::peek_from(bytes, &mut (*output).m21);
        let bytes = T::peek_from(bytes, &mut (*output).m22);
        let bytes = T::peek_from(bytes, &mut (*output).m23);
        let bytes = T::peek_from(bytes, &mut (*output).m24);
        let bytes = T::peek_from(bytes, &mut (*output).m31);
        let bytes = T::peek_from(bytes, &mut (*output).m32);
        let bytes = T::peek_from(bytes, &mut (*output).m33);
        let bytes = T::peek_from(bytes, &mut (*output).m34);
        let bytes = T::peek_from(bytes, &mut (*output).m41);
        let bytes = T::peek_from(bytes, &mut (*output).m42);
        let bytes = T::peek_from(bytes, &mut (*output).m43);
        let bytes = T::peek_from(bytes, &mut (*output).m44);
        bytes
    }
}

unsafe impl<T: Poke, U> Poke for Vector2D<T, U> {
    #[inline(always)]
    fn max_size() -> usize {
        2 * T::max_size()
    }
    #[inline(always)]
    unsafe fn poke_into(&self, bytes: *mut u8) -> *mut u8 {
        let bytes = self.x.poke_into(bytes);
        let bytes = self.y.poke_into(bytes);
        bytes
    }
}
impl<T: Peek, U> Peek for Vector2D<T, U> {
    #[inline(always)]
    unsafe fn peek_from(bytes: *const u8, output: *mut Self) -> *const u8 {
        let bytes = T::peek_from(bytes, &mut (*output).x);
        let bytes = T::peek_from(bytes, &mut (*output).y);
        bytes
    }
}