Seregon/StratoSDK

StratoSDK is a framework with a declarative approach similar to Flutter/React, written and designed entirely for Rust.

Rust/27.3 KB/No license
crates/strato-ui-core/src/fonts_test.rs
StratoSDK / crates / strato-ui-core / src / fonts_test.rs
1use super::*;
2 
3#[test]
4fn test_subpixel_alignment_computation() {
5 {
6 // Default case - a non-fractional offset should have an alignment
7 // value of zero.
8 let pos = vec2f(0., 0.);
9 let alignment = SubpixelAlignment::new(pos);
10 assert_eq!(alignment.0, 0);
11 }
12 {
13 // 0.1 rounds down to 0 (not up to 0.33 -> 1)
14 let pos = vec2f(0.1, 0.);
15 let alignment = SubpixelAlignment::new(pos);
16 assert_eq!(alignment.0, 0);
17 }
18 {
19 // y-position doesn't affect computation
20 let pos = vec2f(0.1, 0.33);
21 let alignment = SubpixelAlignment::new(pos);
22 assert_eq!(alignment.0, 0);
23 }
24 {
25 // 0.2 rounds up to 0.33 -> 1
26 let pos = vec2f(0.2, 0.);
27 let alignment = SubpixelAlignment::new(pos);
28 assert_eq!(alignment.0, 1);
29 }
30 {
31 // 0.66 doesn't round, and converts to 2
32 let pos = vec2f(0.66, 0.);
33 let alignment = SubpixelAlignment::new(pos);
34 assert_eq!(alignment.0, 2);
35 }
36 {
37 // 0.9 rounds up to 1.0 -> 0
38 let pos = vec2f(0.9, 0.);
39 let alignment = SubpixelAlignment::new(pos);
40 assert_eq!(alignment.0, 0);
41 }
42}
43