Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 28.75 KB | None | 0 0
  1. impl Rgba {
  2. # [ doc = r" All components as an array" ] pub fn as_array ( & self ) -> & [
  3. f32 ; 4usize ] { unsafe { std :: mem :: transmute ( self ) } } # [
  4. doc = r" All components as an array" ] pub fn as_array_mut ( & mut self ) -> &
  5. mut [ f32 ; 4usize ] { unsafe { std :: mem :: transmute ( self ) } } # [
  6. doc = r" All components as an array" ] pub fn into_array ( self ) -> [
  7. f32 ; 4usize ] { unsafe { std :: mem :: transmute ( self ) } } fn fill (
  8. value : f32 ) -> Self { Self { r : value , g : value , b : value , a : value }
  9. } } impl num_traits :: Zero for Rgba {
  10. fn zero ( ) -> Self { Self :: fill ( 0.0 ) } fn is_zero ( & self ) -> bool {
  11. * self == Self :: zero ( ) } } impl num_traits :: One for Rgba {
  12. fn one ( ) -> Self { Self :: fill ( 1.0 ) } fn is_one ( & self ) -> bool {
  13. * self == Self :: one ( ) } } impl Color for Rgba {
  14. fn black ( ) -> Self {
  15. let c = Self :: fill ( 0.0 ) ; if 4usize == 4 { c . as_ref ( ) [ 3 ] = 1.0 ;
  16. } c } fn white ( ) -> Self {
  17. let c = Self :: fill ( 0.0 ) ; if 4usize == 4 { c . as_ref ( ) [ 3 ] = 1.0 ;
  18. } c } fn iter ( & self ) -> std :: slice :: Iter < f32 > {
  19. self . into_iter ( ) } fn iter_mut ( & mut self ) -> std :: slice :: IterMut
  20. < f32 > { self . into_iter ( ) } fn map < F > ( self , mut f : F ) -> Self
  21. where F : FnMut ( f32 ) -> f32 {
  22. Self {
  23. r : f ( self . r ) , g : f ( self . g ) , b : f ( self . b ) , a : f (
  24. self . a ) } } } impl AsRef < [ f32 ] > for Rgba {
  25. fn as_ref ( & self ) -> & [ f32 ] { self . as_array ( ) } } impl AsMut < [
  26. f32 ] > for Rgba {
  27. fn as_mut ( & mut self ) -> & mut [ f32 ] { self . as_array_mut ( ) } } # [
  28. doc = r" Iterator which owns a name" ] # [
  29. derive ( Debug , PartialEq , Clone , Copy ) ] pub struct RgbaIter {
  30. data : [ f32 ; 4usize ] , next_index : usize , } impl RgbaIter {
  31. fn new ( src : Rgba ) -> Self {
  32. Self { data : src . into_array ( ) , next_index : 0 , } } } impl Iterator for
  33. RgbaIter {
  34. type Item = f32 ; fn next ( & mut self ) -> Option < f32 > {
  35. if self . next_index >= 4usize { None } else {
  36. self . next_index += 1 ; Some ( self . data [ self . next_index - 1 ] ) } } fn
  37. size_hint ( & self ) -> ( usize , Option < usize > ) {
  38. let remaining = 4usize - self . next_index ; ( remaining , Some ( remaining )
  39. ) } } impl ExactSizeIterator for RgbaIter { } # [
  40. doc = r" Iterate through each component in order" ] impl std :: iter ::
  41. IntoIterator for Rgba {
  42. type Item = f32 ; type IntoIter = RgbaIter ; fn into_iter ( self ) -> Self ::
  43. IntoIter { RgbaIter :: new ( self ) } } # [
  44. doc = r" Iterate through each component in order" ] impl < 'a > std :: iter ::
  45. IntoIterator for & 'a Rgba {
  46. type Item = & 'a f32 ; type IntoIter = std :: slice :: Iter < 'a , f32 > ; fn
  47. into_iter ( self ) -> Self :: IntoIter { self . as_array ( ) . iter ( ) } }
  48. # [ doc = r" Iterate through each component in order" ] impl < 'a > std ::
  49. iter :: IntoIterator for & 'a mut Rgba {
  50. type Item = & 'a mut f32 ; type IntoIter = std :: slice :: IterMut < 'a , f32
  51. > ; fn into_iter ( self ) -> Self :: IntoIter {
  52. self . as_array_mut ( ) . iter_mut ( ) } } # [
  53. doc = "Add each component independently" ] impl std :: ops :: Add for Rgba {
  54. type Output = Self ; fn add ( self , other : Self ) -> Self {
  55. use std :: ops :: AddAssign ; let mut out = self ; out . add_assign ( other )
  56. ; out } } # [ doc = "Add each component independently" ] impl std :: ops ::
  57. AddAssign for Rgba {
  58. fn add_assign ( & mut self , other : Self ) {
  59. for ( c , other_c ) in self . iter_mut ( ) . zip ( other ) {
  60. c . add_assign ( other_c ) ; } } } # [
  61. doc = "Add a scalar value to each component" ] impl std :: ops :: Add < f32 >
  62. for Rgba {
  63. type Output = Self ; fn add ( self , scalar : f32 ) -> Self {
  64. self . map ( | c | c . add ( scalar ) ) } } # [
  65. doc = "Add a scalar value to each component" ] impl std :: ops :: AddAssign <
  66. f32 > for Rgba {
  67. fn add_assign ( & mut self , scalar : f32 ) {
  68. for c in self { c . add_assign ( scalar ) ; } } } # [
  69. doc = "Subtract each component independently" ] impl std :: ops :: Sub for
  70. Rgba {
  71. type Output = Self ; fn sub ( self , other : Self ) -> Self {
  72. use std :: ops :: SubAssign ; let mut out = self ; out . sub_assign ( other )
  73. ; out } } # [ doc = "Subtract each component independently" ] impl std :: ops
  74. :: SubAssign for Rgba {
  75. fn sub_assign ( & mut self , other : Self ) {
  76. for ( c , other_c ) in self . iter_mut ( ) . zip ( other ) {
  77. c . sub_assign ( other_c ) ; } } } # [
  78. doc = "Subtract a scalar value from each component" ] impl std :: ops :: Sub <
  79. f32 > for Rgba {
  80. type Output = Self ; fn sub ( self , scalar : f32 ) -> Self {
  81. self . map ( | c | c . sub ( scalar ) ) } } # [
  82. doc = "Subtract a scalar value from each component" ] impl std :: ops ::
  83. SubAssign < f32 > for Rgba {
  84. fn sub_assign ( & mut self , scalar : f32 ) {
  85. for c in self { c . sub_assign ( scalar ) ; } } } # [
  86. doc = "Multiply each component independently" ] impl std :: ops :: Mul for
  87. Rgba {
  88. type Output = Self ; fn mul ( self , other : Self ) -> Self {
  89. use std :: ops :: MulAssign ; let mut out = self ; out . mul_assign ( other )
  90. ; out } } # [ doc = "Multiply each component independently" ] impl std :: ops
  91. :: MulAssign for Rgba {
  92. fn mul_assign ( & mut self , other : Self ) {
  93. for ( c , other_c ) in self . iter_mut ( ) . zip ( other ) {
  94. c . mul_assign ( other_c ) ; } } } # [
  95. doc = "Multiply each component by a scalar value" ] impl std :: ops :: Mul <
  96. f32 > for Rgba {
  97. type Output = Self ; fn mul ( self , scalar : f32 ) -> Self {
  98. self . map ( | c | c . mul ( scalar ) ) } } # [
  99. doc = "Multiply each component by a scalar value" ] impl std :: ops ::
  100. MulAssign < f32 > for Rgba {
  101. fn mul_assign ( & mut self , scalar : f32 ) {
  102. for c in self { c . mul_assign ( scalar ) ; } } } # [
  103. doc = "Divide each component independently" ] impl std :: ops :: Div for Rgba
  104. {
  105. type Output = Self ; fn div ( self , other : Self ) -> Self {
  106. use std :: ops :: DivAssign ; let mut out = self ; out . div_assign ( other )
  107. ; out } } # [ doc = "Divide each component independently" ] impl std :: ops ::
  108. DivAssign for Rgba {
  109. fn div_assign ( & mut self , other : Self ) {
  110. for ( c , other_c ) in self . iter_mut ( ) . zip ( other ) {
  111. c . div_assign ( other_c ) ; } } } # [
  112. doc = "Divide each component by a scalar value" ] impl std :: ops :: Div < f32
  113. > for Rgba {
  114. type Output = Self ; fn div ( self , scalar : f32 ) -> Self {
  115. self . map ( | c | c . div ( scalar ) ) } } # [
  116. doc = "Divide each component by a scalar value" ] impl std :: ops :: DivAssign
  117. < f32 > for Rgba {
  118. fn div_assign ( & mut self , scalar : f32 ) {
  119. for c in self { c . div_assign ( scalar ) ; } } } # [
  120. doc = "Remainder each component independently" ] impl std :: ops :: Rem for
  121. Rgba {
  122. type Output = Self ; fn rem ( self , other : Self ) -> Self {
  123. use std :: ops :: RemAssign ; let mut out = self ; out . rem_assign ( other )
  124. ; out } } # [ doc = "Remainder each component independently" ] impl std :: ops
  125. :: RemAssign for Rgba {
  126. fn rem_assign ( & mut self , other : Self ) {
  127. for ( c , other_c ) in self . iter_mut ( ) . zip ( other ) {
  128. c . rem_assign ( other_c ) ; } } } # [
  129. doc = "Remainder each component by a scalar value" ] impl std :: ops :: Rem <
  130. f32 > for Rgba {
  131. type Output = Self ; fn rem ( self , scalar : f32 ) -> Self {
  132. self . map ( | c | c . rem ( scalar ) ) } } # [
  133. doc = "Remainder each component by a scalar value" ] impl std :: ops ::
  134. RemAssign < f32 > for Rgba {
  135. fn rem_assign ( & mut self , scalar : f32 ) {
  136. for c in self { c . rem_assign ( scalar ) ; } } }
  137. impl Rgb {
  138. # [ doc = r" All components as an array" ] pub fn as_array ( & self ) -> & [
  139. f32 ; 3usize ] { unsafe { std :: mem :: transmute ( self ) } } # [
  140. doc = r" All components as an array" ] pub fn as_array_mut ( & mut self ) -> &
  141. mut [ f32 ; 3usize ] { unsafe { std :: mem :: transmute ( self ) } } # [
  142. doc = r" All components as an array" ] pub fn into_array ( self ) -> [
  143. f32 ; 3usize ] { unsafe { std :: mem :: transmute ( self ) } } fn fill (
  144. value : f32 ) -> Self { Self { r : value , g : value , b : value } } } impl
  145. num_traits :: Zero for Rgb {
  146. fn zero ( ) -> Self { Self :: fill ( 0.0 ) } fn is_zero ( & self ) -> bool {
  147. * self == Self :: zero ( ) } } impl num_traits :: One for Rgb {
  148. fn one ( ) -> Self { Self :: fill ( 1.0 ) } fn is_one ( & self ) -> bool {
  149. * self == Self :: one ( ) } } impl Color for Rgb {
  150. fn black ( ) -> Self {
  151. let c = Self :: fill ( 0.0 ) ; if 3usize == 4 { c . as_ref ( ) [ 3 ] = 1.0 ;
  152. } c } fn white ( ) -> Self {
  153. let c = Self :: fill ( 0.0 ) ; if 3usize == 4 { c . as_ref ( ) [ 3 ] = 1.0 ;
  154. } c } fn iter ( & self ) -> std :: slice :: Iter < f32 > {
  155. self . into_iter ( ) } fn iter_mut ( & mut self ) -> std :: slice :: IterMut
  156. < f32 > { self . into_iter ( ) } fn map < F > ( self , mut f : F ) -> Self
  157. where F : FnMut ( f32 ) -> f32 {
  158. Self { r : f ( self . r ) , g : f ( self . g ) , b : f ( self . b ) } } } impl
  159. AsRef < [ f32 ] > for Rgb {
  160. fn as_ref ( & self ) -> & [ f32 ] { self . as_array ( ) } } impl AsMut < [
  161. f32 ] > for Rgb {
  162. fn as_mut ( & mut self ) -> & mut [ f32 ] { self . as_array_mut ( ) } } # [
  163. doc = r" Iterator which owns a name" ] # [
  164. derive ( Debug , PartialEq , Clone , Copy ) ] pub struct RgbIter {
  165. data : [ f32 ; 3usize ] , next_index : usize , } impl RgbIter {
  166. fn new ( src : Rgb ) -> Self {
  167. Self { data : src . into_array ( ) , next_index : 0 , } } } impl Iterator for
  168. RgbIter {
  169. type Item = f32 ; fn next ( & mut self ) -> Option < f32 > {
  170. if self . next_index >= 3usize { None } else {
  171. self . next_index += 1 ; Some ( self . data [ self . next_index - 1 ] ) } } fn
  172. size_hint ( & self ) -> ( usize , Option < usize > ) {
  173. let remaining = 3usize - self . next_index ; ( remaining , Some ( remaining )
  174. ) } } impl ExactSizeIterator for RgbIter { } # [
  175. doc = r" Iterate through each component in order" ] impl std :: iter ::
  176. IntoIterator for Rgb {
  177. type Item = f32 ; type IntoIter = RgbIter ; fn into_iter ( self ) -> Self ::
  178. IntoIter { RgbIter :: new ( self ) } } # [
  179. doc = r" Iterate through each component in order" ] impl < 'a > std :: iter ::
  180. IntoIterator for & 'a Rgb {
  181. type Item = & 'a f32 ; type IntoIter = std :: slice :: Iter < 'a , f32 > ; fn
  182. into_iter ( self ) -> Self :: IntoIter { self . as_array ( ) . iter ( ) } }
  183. # [ doc = r" Iterate through each component in order" ] impl < 'a > std ::
  184. iter :: IntoIterator for & 'a mut Rgb {
  185. type Item = & 'a mut f32 ; type IntoIter = std :: slice :: IterMut < 'a , f32
  186. > ; fn into_iter ( self ) -> Self :: IntoIter {
  187. self . as_array_mut ( ) . iter_mut ( ) } } # [
  188. doc = "Add each component independently" ] impl std :: ops :: Add for Rgb {
  189. type Output = Self ; fn add ( self , other : Self ) -> Self {
  190. use std :: ops :: AddAssign ; let mut out = self ; out . add_assign ( other )
  191. ; out } } # [ doc = "Add each component independently" ] impl std :: ops ::
  192. AddAssign for Rgb {
  193. fn add_assign ( & mut self , other : Self ) {
  194. for ( c , other_c ) in self . iter_mut ( ) . zip ( other ) {
  195. c . add_assign ( other_c ) ; } } } # [
  196. doc = "Add a scalar value to each component" ] impl std :: ops :: Add < f32 >
  197. for Rgb {
  198. type Output = Self ; fn add ( self , scalar : f32 ) -> Self {
  199. self . map ( | c | c . add ( scalar ) ) } } # [
  200. doc = "Add a scalar value to each component" ] impl std :: ops :: AddAssign <
  201. f32 > for Rgb {
  202. fn add_assign ( & mut self , scalar : f32 ) {
  203. for c in self { c . add_assign ( scalar ) ; } } } # [
  204. doc = "Subtract each component independently" ] impl std :: ops :: Sub for Rgb
  205. {
  206. type Output = Self ; fn sub ( self , other : Self ) -> Self {
  207. use std :: ops :: SubAssign ; let mut out = self ; out . sub_assign ( other )
  208. ; out } } # [ doc = "Subtract each component independently" ] impl std :: ops
  209. :: SubAssign for Rgb {
  210. fn sub_assign ( & mut self , other : Self ) {
  211. for ( c , other_c ) in self . iter_mut ( ) . zip ( other ) {
  212. c . sub_assign ( other_c ) ; } } } # [
  213. doc = "Subtract a scalar value from each component" ] impl std :: ops :: Sub <
  214. f32 > for Rgb {
  215. type Output = Self ; fn sub ( self , scalar : f32 ) -> Self {
  216. self . map ( | c | c . sub ( scalar ) ) } } # [
  217. doc = "Subtract a scalar value from each component" ] impl std :: ops ::
  218. SubAssign < f32 > for Rgb {
  219. fn sub_assign ( & mut self , scalar : f32 ) {
  220. for c in self { c . sub_assign ( scalar ) ; } } } # [
  221. doc = "Multiply each component independently" ] impl std :: ops :: Mul for Rgb
  222. {
  223. type Output = Self ; fn mul ( self , other : Self ) -> Self {
  224. use std :: ops :: MulAssign ; let mut out = self ; out . mul_assign ( other )
  225. ; out } } # [ doc = "Multiply each component independently" ] impl std :: ops
  226. :: MulAssign for Rgb {
  227. fn mul_assign ( & mut self , other : Self ) {
  228. for ( c , other_c ) in self . iter_mut ( ) . zip ( other ) {
  229. c . mul_assign ( other_c ) ; } } } # [
  230. doc = "Multiply each component by a scalar value" ] impl std :: ops :: Mul <
  231. f32 > for Rgb {
  232. type Output = Self ; fn mul ( self , scalar : f32 ) -> Self {
  233. self . map ( | c | c . mul ( scalar ) ) } } # [
  234. doc = "Multiply each component by a scalar value" ] impl std :: ops ::
  235. MulAssign < f32 > for Rgb {
  236. fn mul_assign ( & mut self , scalar : f32 ) {
  237. for c in self { c . mul_assign ( scalar ) ; } } } # [
  238. doc = "Divide each component independently" ] impl std :: ops :: Div for Rgb {
  239. type Output = Self ; fn div ( self , other : Self ) -> Self {
  240. use std :: ops :: DivAssign ; let mut out = self ; out . div_assign ( other )
  241. ; out } } # [ doc = "Divide each component independently" ] impl std :: ops ::
  242. DivAssign for Rgb {
  243. fn div_assign ( & mut self , other : Self ) {
  244. for ( c , other_c ) in self . iter_mut ( ) . zip ( other ) {
  245. c . div_assign ( other_c ) ; } } } # [
  246. doc = "Divide each component by a scalar value" ] impl std :: ops :: Div < f32
  247. > for Rgb {
  248. type Output = Self ; fn div ( self , scalar : f32 ) -> Self {
  249. self . map ( | c | c . div ( scalar ) ) } } # [
  250. doc = "Divide each component by a scalar value" ] impl std :: ops :: DivAssign
  251. < f32 > for Rgb {
  252. fn div_assign ( & mut self , scalar : f32 ) {
  253. for c in self { c . div_assign ( scalar ) ; } } } # [
  254. doc = "Remainder each component independently" ] impl std :: ops :: Rem for
  255. Rgb {
  256. type Output = Self ; fn rem ( self , other : Self ) -> Self {
  257. use std :: ops :: RemAssign ; let mut out = self ; out . rem_assign ( other )
  258. ; out } } # [ doc = "Remainder each component independently" ] impl std :: ops
  259. :: RemAssign for Rgb {
  260. fn rem_assign ( & mut self , other : Self ) {
  261. for ( c , other_c ) in self . iter_mut ( ) . zip ( other ) {
  262. c . rem_assign ( other_c ) ; } } } # [
  263. doc = "Remainder each component by a scalar value" ] impl std :: ops :: Rem <
  264. f32 > for Rgb {
  265. type Output = Self ; fn rem ( self , scalar : f32 ) -> Self {
  266. self . map ( | c | c . rem ( scalar ) ) } } # [
  267. doc = "Remainder each component by a scalar value" ] impl std :: ops ::
  268. RemAssign < f32 > for Rgb {
  269. fn rem_assign ( & mut self , scalar : f32 ) {
  270. for c in self { c . rem_assign ( scalar ) ; } } }
  271. impl Rg {
  272. # [ doc = r" All components as an array" ] pub fn as_array ( & self ) -> & [
  273. f32 ; 2usize ] { unsafe { std :: mem :: transmute ( self ) } } # [
  274. doc = r" All components as an array" ] pub fn as_array_mut ( & mut self ) -> &
  275. mut [ f32 ; 2usize ] { unsafe { std :: mem :: transmute ( self ) } } # [
  276. doc = r" All components as an array" ] pub fn into_array ( self ) -> [
  277. f32 ; 2usize ] { unsafe { std :: mem :: transmute ( self ) } } fn fill (
  278. value : f32 ) -> Self { Self { r : value , g : value } } } impl num_traits ::
  279. Zero for Rg {
  280. fn zero ( ) -> Self { Self :: fill ( 0.0 ) } fn is_zero ( & self ) -> bool {
  281. * self == Self :: zero ( ) } } impl num_traits :: One for Rg {
  282. fn one ( ) -> Self { Self :: fill ( 1.0 ) } fn is_one ( & self ) -> bool {
  283. * self == Self :: one ( ) } } impl Color for Rg {
  284. fn black ( ) -> Self {
  285. let c = Self :: fill ( 0.0 ) ; if 2usize == 4 { c . as_ref ( ) [ 3 ] = 1.0 ;
  286. } c } fn white ( ) -> Self {
  287. let c = Self :: fill ( 0.0 ) ; if 2usize == 4 { c . as_ref ( ) [ 3 ] = 1.0 ;
  288. } c } fn iter ( & self ) -> std :: slice :: Iter < f32 > {
  289. self . into_iter ( ) } fn iter_mut ( & mut self ) -> std :: slice :: IterMut
  290. < f32 > { self . into_iter ( ) } fn map < F > ( self , mut f : F ) -> Self
  291. where F : FnMut ( f32 ) -> f32 {
  292. Self { r : f ( self . r ) , g : f ( self . g ) } } } impl AsRef < [ f32 ] >
  293. for Rg { fn as_ref ( & self ) -> & [ f32 ] { self . as_array ( ) } } impl
  294. AsMut < [ f32 ] > for Rg {
  295. fn as_mut ( & mut self ) -> & mut [ f32 ] { self . as_array_mut ( ) } } # [
  296. doc = r" Iterator which owns a name" ] # [
  297. derive ( Debug , PartialEq , Clone , Copy ) ] pub struct RgIter {
  298. data : [ f32 ; 2usize ] , next_index : usize , } impl RgIter {
  299. fn new ( src : Rg ) -> Self {
  300. Self { data : src . into_array ( ) , next_index : 0 , } } } impl Iterator for
  301. RgIter {
  302. type Item = f32 ; fn next ( & mut self ) -> Option < f32 > {
  303. if self . next_index >= 2usize { None } else {
  304. self . next_index += 1 ; Some ( self . data [ self . next_index - 1 ] ) } } fn
  305. size_hint ( & self ) -> ( usize , Option < usize > ) {
  306. let remaining = 2usize - self . next_index ; ( remaining , Some ( remaining )
  307. ) } } impl ExactSizeIterator for RgIter { } # [
  308. doc = r" Iterate through each component in order" ] impl std :: iter ::
  309. IntoIterator for Rg {
  310. type Item = f32 ; type IntoIter = RgIter ; fn into_iter ( self ) -> Self ::
  311. IntoIter { RgIter :: new ( self ) } } # [
  312. doc = r" Iterate through each component in order" ] impl < 'a > std :: iter ::
  313. IntoIterator for & 'a Rg {
  314. type Item = & 'a f32 ; type IntoIter = std :: slice :: Iter < 'a , f32 > ; fn
  315. into_iter ( self ) -> Self :: IntoIter { self . as_array ( ) . iter ( ) } }
  316. # [ doc = r" Iterate through each component in order" ] impl < 'a > std ::
  317. iter :: IntoIterator for & 'a mut Rg {
  318. type Item = & 'a mut f32 ; type IntoIter = std :: slice :: IterMut < 'a , f32
  319. > ; fn into_iter ( self ) -> Self :: IntoIter {
  320. self . as_array_mut ( ) . iter_mut ( ) } } # [
  321. doc = "Add each component independently" ] impl std :: ops :: Add for Rg {
  322. type Output = Self ; fn add ( self , other : Self ) -> Self {
  323. use std :: ops :: AddAssign ; let mut out = self ; out . add_assign ( other )
  324. ; out } } # [ doc = "Add each component independently" ] impl std :: ops ::
  325. AddAssign for Rg {
  326. fn add_assign ( & mut self , other : Self ) {
  327. for ( c , other_c ) in self . iter_mut ( ) . zip ( other ) {
  328. c . add_assign ( other_c ) ; } } } # [
  329. doc = "Add a scalar value to each component" ] impl std :: ops :: Add < f32 >
  330. for Rg {
  331. type Output = Self ; fn add ( self , scalar : f32 ) -> Self {
  332. self . map ( | c | c . add ( scalar ) ) } } # [
  333. doc = "Add a scalar value to each component" ] impl std :: ops :: AddAssign <
  334. f32 > for Rg {
  335. fn add_assign ( & mut self , scalar : f32 ) {
  336. for c in self { c . add_assign ( scalar ) ; } } } # [
  337. doc = "Subtract each component independently" ] impl std :: ops :: Sub for Rg
  338. {
  339. type Output = Self ; fn sub ( self , other : Self ) -> Self {
  340. use std :: ops :: SubAssign ; let mut out = self ; out . sub_assign ( other )
  341. ; out } } # [ doc = "Subtract each component independently" ] impl std :: ops
  342. :: SubAssign for Rg {
  343. fn sub_assign ( & mut self , other : Self ) {
  344. for ( c , other_c ) in self . iter_mut ( ) . zip ( other ) {
  345. c . sub_assign ( other_c ) ; } } } # [
  346. doc = "Subtract a scalar value from each component" ] impl std :: ops :: Sub <
  347. f32 > for Rg {
  348. type Output = Self ; fn sub ( self , scalar : f32 ) -> Self {
  349. self . map ( | c | c . sub ( scalar ) ) } } # [
  350. doc = "Subtract a scalar value from each component" ] impl std :: ops ::
  351. SubAssign < f32 > for Rg {
  352. fn sub_assign ( & mut self , scalar : f32 ) {
  353. for c in self { c . sub_assign ( scalar ) ; } } } # [
  354. doc = "Multiply each component independently" ] impl std :: ops :: Mul for Rg
  355. {
  356. type Output = Self ; fn mul ( self , other : Self ) -> Self {
  357. use std :: ops :: MulAssign ; let mut out = self ; out . mul_assign ( other )
  358. ; out } } # [ doc = "Multiply each component independently" ] impl std :: ops
  359. :: MulAssign for Rg {
  360. fn mul_assign ( & mut self , other : Self ) {
  361. for ( c , other_c ) in self . iter_mut ( ) . zip ( other ) {
  362. c . mul_assign ( other_c ) ; } } } # [
  363. doc = "Multiply each component by a scalar value" ] impl std :: ops :: Mul <
  364. f32 > for Rg {
  365. type Output = Self ; fn mul ( self , scalar : f32 ) -> Self {
  366. self . map ( | c | c . mul ( scalar ) ) } } # [
  367. doc = "Multiply each component by a scalar value" ] impl std :: ops ::
  368. MulAssign < f32 > for Rg {
  369. fn mul_assign ( & mut self , scalar : f32 ) {
  370. for c in self { c . mul_assign ( scalar ) ; } } } # [
  371. doc = "Divide each component independently" ] impl std :: ops :: Div for Rg {
  372. type Output = Self ; fn div ( self , other : Self ) -> Self {
  373. use std :: ops :: DivAssign ; let mut out = self ; out . div_assign ( other )
  374. ; out } } # [ doc = "Divide each component independently" ] impl std :: ops ::
  375. DivAssign for Rg {
  376. fn div_assign ( & mut self , other : Self ) {
  377. for ( c , other_c ) in self . iter_mut ( ) . zip ( other ) {
  378. c . div_assign ( other_c ) ; } } } # [
  379. doc = "Divide each component by a scalar value" ] impl std :: ops :: Div < f32
  380. > for Rg {
  381. type Output = Self ; fn div ( self , scalar : f32 ) -> Self {
  382. self . map ( | c | c . div ( scalar ) ) } } # [
  383. doc = "Divide each component by a scalar value" ] impl std :: ops :: DivAssign
  384. < f32 > for Rg {
  385. fn div_assign ( & mut self , scalar : f32 ) {
  386. for c in self { c . div_assign ( scalar ) ; } } } # [
  387. doc = "Remainder each component independently" ] impl std :: ops :: Rem for Rg
  388. {
  389. type Output = Self ; fn rem ( self , other : Self ) -> Self {
  390. use std :: ops :: RemAssign ; let mut out = self ; out . rem_assign ( other )
  391. ; out } } # [ doc = "Remainder each component independently" ] impl std :: ops
  392. :: RemAssign for Rg {
  393. fn rem_assign ( & mut self , other : Self ) {
  394. for ( c , other_c ) in self . iter_mut ( ) . zip ( other ) {
  395. c . rem_assign ( other_c ) ; } } } # [
  396. doc = "Remainder each component by a scalar value" ] impl std :: ops :: Rem <
  397. f32 > for Rg {
  398. type Output = Self ; fn rem ( self , scalar : f32 ) -> Self {
  399. self . map ( | c | c . rem ( scalar ) ) } } # [
  400. doc = "Remainder each component by a scalar value" ] impl std :: ops ::
  401. RemAssign < f32 > for Rg {
  402. fn rem_assign ( & mut self , scalar : f32 ) {
  403. for c in self { c . rem_assign ( scalar ) ; } } }
  404. impl Grayscale {
  405. # [ doc = r" All components as an array" ] pub fn as_array ( & self ) -> & [
  406. f32 ; 1usize ] { unsafe { std :: mem :: transmute ( self ) } } # [
  407. doc = r" All components as an array" ] pub fn as_array_mut ( & mut self ) -> &
  408. mut [ f32 ; 1usize ] { unsafe { std :: mem :: transmute ( self ) } } # [
  409. doc = r" All components as an array" ] pub fn into_array ( self ) -> [
  410. f32 ; 1usize ] { unsafe { std :: mem :: transmute ( self ) } } fn fill (
  411. value : f32 ) -> Self { Self ( value ) } } impl num_traits :: Zero for
  412. Grayscale {
  413. fn zero ( ) -> Self { Self :: fill ( 0.0 ) } fn is_zero ( & self ) -> bool {
  414. * self == Self :: zero ( ) } } impl num_traits :: One for Grayscale {
  415. fn one ( ) -> Self { Self :: fill ( 1.0 ) } fn is_one ( & self ) -> bool {
  416. * self == Self :: one ( ) } } impl Color for Grayscale {
  417. fn black ( ) -> Self {
  418. let c = Self :: fill ( 0.0 ) ; if 1usize == 4 { c . as_ref ( ) [ 3 ] = 1.0 ;
  419. } c } fn white ( ) -> Self {
  420. let c = Self :: fill ( 0.0 ) ; if 1usize == 4 { c . as_ref ( ) [ 3 ] = 1.0 ;
  421. } c } fn iter ( & self ) -> std :: slice :: Iter < f32 > {
  422. self . into_iter ( ) } fn iter_mut ( & mut self ) -> std :: slice :: IterMut
  423. < f32 > { self . into_iter ( ) } fn map < F > ( self , mut f : F ) -> Self
  424. where F : FnMut ( f32 ) -> f32 { Self ( f ( self . 0 ) ) } } impl AsRef < [
  425. f32 ] > for Grayscale {
  426. fn as_ref ( & self ) -> & [ f32 ] { self . as_array ( ) } } impl AsMut < [
  427. f32 ] > for Grayscale {
  428. fn as_mut ( & mut self ) -> & mut [ f32 ] { self . as_array_mut ( ) } } # [
  429. doc = r" Iterator which owns a name" ] # [
  430. derive ( Debug , PartialEq , Clone , Copy ) ] pub struct GrayscaleIter {
  431. data : [ f32 ; 1usize ] , next_index : usize , } impl GrayscaleIter {
  432. fn new ( src : Grayscale ) -> Self {
  433. Self { data : src . into_array ( ) , next_index : 0 , } } } impl Iterator for
  434. GrayscaleIter {
  435. type Item = f32 ; fn next ( & mut self ) -> Option < f32 > {
  436. if self . next_index >= 1usize { None } else {
  437. self . next_index += 1 ; Some ( self . data [ self . next_index - 1 ] ) } } fn
  438. size_hint ( & self ) -> ( usize , Option < usize > ) {
  439. let remaining = 1usize - self . next_index ; ( remaining , Some ( remaining )
  440. ) } } impl ExactSizeIterator for GrayscaleIter { } # [
  441. doc = r" Iterate through each component in order" ] impl std :: iter ::
  442. IntoIterator for Grayscale {
  443. type Item = f32 ; type IntoIter = GrayscaleIter ; fn into_iter ( self ) ->
  444. Self :: IntoIter { GrayscaleIter :: new ( self ) } } # [
  445. doc = r" Iterate through each component in order" ] impl < 'a > std :: iter ::
  446. IntoIterator for & 'a Grayscale {
  447. type Item = & 'a f32 ; type IntoIter = std :: slice :: Iter < 'a , f32 > ; fn
  448. into_iter ( self ) -> Self :: IntoIter { self . as_array ( ) . iter ( ) } }
  449. # [ doc = r" Iterate through each component in order" ] impl < 'a > std ::
  450. iter :: IntoIterator for & 'a mut Grayscale {
  451. type Item = & 'a mut f32 ; type IntoIter = std :: slice :: IterMut < 'a , f32
  452. > ; fn into_iter ( self ) -> Self :: IntoIter {
  453. self . as_array_mut ( ) . iter_mut ( ) } } # [
  454. doc = "Add each component independently" ] impl std :: ops :: Add for
  455. Grayscale {
  456. type Output = Self ; fn add ( self , other : Self ) -> Self {
  457. use std :: ops :: AddAssign ; let mut out = self ; out . add_assign ( other )
  458. ; out } } # [ doc = "Add each component independently" ] impl std :: ops ::
  459. AddAssign for Grayscale {
  460. fn add_assign ( & mut self , other : Self ) {
  461. for ( c , other_c ) in self . iter_mut ( ) . zip ( other ) {
  462. c . add_assign ( other_c ) ; } } } # [
  463. doc = "Add a scalar value to each component" ] impl std :: ops :: Add < f32 >
  464. for Grayscale {
  465. type Output = Self ; fn add ( self , scalar : f32 ) -> Self {
  466. self . map ( | c | c . add ( scalar ) ) } } # [
  467. doc = "Add a scalar value to each component" ] impl std :: ops :: AddAssign <
  468. f32 > for Grayscale {
  469. fn add_assign ( & mut self , scalar : f32 ) {
  470. for c in self { c . add_assign ( scalar ) ; } } } # [
  471. doc = "Subtract each component independently" ] impl std :: ops :: Sub for
  472. Grayscale {
  473. type Output = Self ; fn sub ( self , other : Self ) -> Self {
  474. use std :: ops :: SubAssign ; let mut out = self ; out . sub_assign ( other )
  475. ; out } } # [ doc = "Subtract each component independently" ] impl std :: ops
  476. :: SubAssign for Grayscale {
  477. fn sub_assign ( & mut self , other : Self ) {
  478. for ( c , other_c ) in self . iter_mut ( ) . zip ( other ) {
  479. c . sub_assign ( other_c ) ; } } } # [
  480. doc = "Subtract a scalar value from each component" ] impl std :: ops :: Sub <
  481. f32 > for Grayscale {
  482. type Output = Self ; fn sub ( self , scalar : f32 ) -> Self {
  483. self . map ( | c | c . sub ( scalar ) ) } } # [
  484. doc = "Subtract a scalar value from each component" ] impl std :: ops ::
  485. SubAssign < f32 > for Grayscale {
  486. fn sub_assign ( & mut self , scalar : f32 ) {
  487. for c in self { c . sub_assign ( scalar ) ; } } } # [
  488. doc = "Multiply each component independently" ] impl std :: ops :: Mul for
  489. Grayscale {
  490. type Output = Self ; fn mul ( self , other : Self ) -> Self {
  491. use std :: ops :: MulAssign ; let mut out = self ; out . mul_assign ( other )
  492. ; out } } # [ doc = "Multiply each component independently" ] impl std :: ops
  493. :: MulAssign for Grayscale {
  494. fn mul_assign ( & mut self , other : Self ) {
  495. for ( c , other_c ) in self . iter_mut ( ) . zip ( other ) {
  496. c . mul_assign ( other_c ) ; } } } # [
  497. doc = "Multiply each component by a scalar value" ] impl std :: ops :: Mul <
  498. f32 > for Grayscale {
  499. type Output = Self ; fn mul ( self , scalar : f32 ) -> Self {
  500. self . map ( | c | c . mul ( scalar ) ) } } # [
  501. doc = "Multiply each component by a scalar value" ] impl std :: ops ::
  502. MulAssign < f32 > for Grayscale {
  503. fn mul_assign ( & mut self , scalar : f32 ) {
  504. for c in self { c . mul_assign ( scalar ) ; } } } # [
  505. doc = "Divide each component independently" ] impl std :: ops :: Div for
  506. Grayscale {
  507. type Output = Self ; fn div ( self , other : Self ) -> Self {
  508. use std :: ops :: DivAssign ; let mut out = self ; out . div_assign ( other )
  509. ; out } } # [ doc = "Divide each component independently" ] impl std :: ops ::
  510. DivAssign for Grayscale {
  511. fn div_assign ( & mut self , other : Self ) {
  512. for ( c , other_c ) in self . iter_mut ( ) . zip ( other ) {
  513. c . div_assign ( other_c ) ; } } } # [
  514. doc = "Divide each component by a scalar value" ] impl std :: ops :: Div < f32
  515. > for Grayscale {
  516. type Output = Self ; fn div ( self , scalar : f32 ) -> Self {
  517. self . map ( | c | c . div ( scalar ) ) } } # [
  518. doc = "Divide each component by a scalar value" ] impl std :: ops :: DivAssign
  519. < f32 > for Grayscale {
  520. fn div_assign ( & mut self , scalar : f32 ) {
  521. for c in self { c . div_assign ( scalar ) ; } } } # [
  522. doc = "Remainder each component independently" ] impl std :: ops :: Rem for
  523. Grayscale {
  524. type Output = Self ; fn rem ( self , other : Self ) -> Self {
  525. use std :: ops :: RemAssign ; let mut out = self ; out . rem_assign ( other )
  526. ; out } } # [ doc = "Remainder each component independently" ] impl std :: ops
  527. :: RemAssign for Grayscale {
  528. fn rem_assign ( & mut self , other : Self ) {
  529. for ( c , other_c ) in self . iter_mut ( ) . zip ( other ) {
  530. c . rem_assign ( other_c ) ; } } } # [
  531. doc = "Remainder each component by a scalar value" ] impl std :: ops :: Rem <
  532. f32 > for Grayscale {
  533. type Output = Self ; fn rem ( self , scalar : f32 ) -> Self {
  534. self . map ( | c | c . rem ( scalar ) ) } } # [
  535. doc = "Remainder each component by a scalar value" ] impl std :: ops ::
  536. RemAssign < f32 > for Grayscale {
  537. fn rem_assign ( & mut self , scalar : f32 ) {
  538. for c in self { c . rem_assign ( scalar ) ; } } }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement