@@ -1656,7 +1656,7 @@ impl Tessellator {
1656
1656
if a. x == b. x {
1657
1657
// Vertical line
1658
1658
let mut x = a. x ;
1659
- round_line_segment ( & mut x , & stroke , self . pixels_per_point ) ;
1659
+ stroke . round_center_to_pixel ( self . pixels_per_point , & mut x ) ;
1660
1660
a. x = x;
1661
1661
b. x = x;
1662
1662
@@ -1677,7 +1677,7 @@ impl Tessellator {
1677
1677
if a. y == b. y {
1678
1678
// Horizontal line
1679
1679
let mut y = a. y ;
1680
- round_line_segment ( & mut y , & stroke , self . pixels_per_point ) ;
1680
+ stroke . round_center_to_pixel ( self . pixels_per_point , & mut y ) ;
1681
1681
a. y = y;
1682
1682
b. y = y;
1683
1683
@@ -1778,7 +1778,6 @@ impl Tessellator {
1778
1778
1779
1779
let mut corner_radius = CornerRadiusF32 :: from ( corner_radius) ;
1780
1780
let round_to_pixels = round_to_pixels. unwrap_or ( self . options . round_rects_to_pixels ) ;
1781
- let pixel_size = 1.0 / self . pixels_per_point ;
1782
1781
1783
1782
if stroke. width == 0.0 {
1784
1783
stroke. color = Color32 :: TRANSPARENT ;
@@ -1849,17 +1848,7 @@ impl Tessellator {
1849
1848
}
1850
1849
StrokeKind :: Middle => {
1851
1850
// On this path we optimize for crisp and symmetric strokes.
1852
- // We put odd-width strokes in the center of pixels.
1853
- // To understand why, see `fn round_line_segment`.
1854
- if stroke. width <= 0.0 {
1855
- rect = rect. round_to_pixels ( self . pixels_per_point ) ;
1856
- } else if stroke. width <= pixel_size
1857
- || is_nearest_integer_odd ( self . pixels_per_point * stroke. width )
1858
- {
1859
- rect = rect. round_to_pixel_center ( self . pixels_per_point ) ;
1860
- } else {
1861
- rect = rect. round_to_pixels ( self . pixels_per_point ) ;
1862
- }
1851
+ stroke. round_rect_to_pixel ( self . pixels_per_point , & mut rect) ;
1863
1852
}
1864
1853
StrokeKind :: Outside => {
1865
1854
// Put the inside of the stroke on a pixel boundary.
@@ -2203,45 +2192,6 @@ impl Tessellator {
2203
2192
}
2204
2193
}
2205
2194
2206
- fn round_line_segment ( coord : & mut f32 , stroke : & Stroke , pixels_per_point : f32 ) {
2207
- // If the stroke is an odd number of pixels wide,
2208
- // we want to round the center of it to the center of a pixel.
2209
- //
2210
- // If however it is an even number of pixels wide,
2211
- // we want to round the center to be between two pixels.
2212
- //
2213
- // We also want to treat strokes that are _almost_ odd as it it was odd,
2214
- // to make it symmetric. Same for strokes that are _almost_ even.
2215
- //
2216
- // For strokes less than a pixel wide we also round to the center,
2217
- // because it will rendered as a single row of pixels by the tessellator.
2218
-
2219
- let pixel_size = 1.0 / pixels_per_point;
2220
-
2221
- if stroke. width <= pixel_size || is_nearest_integer_odd ( pixels_per_point * stroke. width ) {
2222
- * coord = coord. round_to_pixel_center ( pixels_per_point) ;
2223
- } else {
2224
- * coord = coord. round_to_pixels ( pixels_per_point) ;
2225
- }
2226
- }
2227
-
2228
- fn is_nearest_integer_odd ( width : f32 ) -> bool {
2229
- ( width * 0.5 + 0.25 ) . fract ( ) > 0.5
2230
- }
2231
-
2232
- #[ test]
2233
- fn test_is_nearest_integer_odd ( ) {
2234
- assert ! ( is_nearest_integer_odd( 0.6 ) ) ;
2235
- assert ! ( is_nearest_integer_odd( 1.0 ) ) ;
2236
- assert ! ( is_nearest_integer_odd( 1.4 ) ) ;
2237
- assert ! ( !is_nearest_integer_odd( 1.6 ) ) ;
2238
- assert ! ( !is_nearest_integer_odd( 2.0 ) ) ;
2239
- assert ! ( !is_nearest_integer_odd( 2.4 ) ) ;
2240
- assert ! ( is_nearest_integer_odd( 2.6 ) ) ;
2241
- assert ! ( is_nearest_integer_odd( 3.0 ) ) ;
2242
- assert ! ( is_nearest_integer_odd( 3.4 ) ) ;
2243
- }
2244
-
2245
2195
#[ deprecated = "Use `Tessellator::new(…).tessellate_shapes(…)` instead" ]
2246
2196
pub fn tessellate_shapes (
2247
2197
pixels_per_point : f32 ,
0 commit comments