Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: linebender/piet
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: d1f85eabba671fd9ee578e2c4041ded9e3ef21e1
Choose a base ref
..
head repository: linebender/piet
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: f5abbb15391aa585440f6c5c0725c2251a4f432f
Choose a head ref
Showing with 3 additions and 48 deletions.
  1. +3 −48 piet/src/samples/picture_16.rs
51 changes: 3 additions & 48 deletions piet/src/samples/picture_16.rs
Original file line number Diff line number Diff line change
@@ -9,7 +9,6 @@ pub const SIZE: Size = Size::new(200., 200.);

const RED: Color = Color::rgb8(255, 0, 0);
const BLUE: Color = Color::rgb8(0, 0, 255);
const GREEN: Color = Color::rgb8(0, 255, 0);
const INTERPOLATION_MODE: InterpolationMode = InterpolationMode::NearestNeighbor;
const BORDER_WIDTH: f64 = 4.0;

@@ -18,17 +17,13 @@ pub fn draw<R: RenderContext>(rc: &mut R) -> Result<(), Error> {

let outer_rect_red = Rect::new(20., 20., 180., 180.);
let inner_rect_blue = outer_rect_red.inset(-BORDER_WIDTH);
let inner_rect_green = Rect::new(25., 25., 150., 50.);

// Draw boxes
// Draw a box with a red border
rc.fill(outer_rect_red, &RED);
rc.fill(inner_rect_blue, &BLUE);
rc.fill(inner_rect_green, &GREEN);

// Cache the image, clear the context and re-draw the box from the cache
let cache = rc
.capture_image_area(Rect::from_origin_size(kurbo::Point::ZERO, SIZE))
.unwrap();
// Cache the box, clear the image and re-draw the box from the cache
let cache = rc.capture_image_area(outer_rect_red).unwrap();
rc.clear(None, Color::BLACK);
rc.draw_image(&cache, outer_rect_red, INTERPOLATION_MODE);

@@ -43,45 +38,5 @@ pub fn draw<R: RenderContext>(rc: &mut R) -> Result<(), Error> {
rc.draw_image(&cache, bottom_left_corner, INTERPOLATION_MODE);
rc.draw_image(&cache, bottom_right_corner, INTERPOLATION_MODE);

// Capture the top left corner and redrew it inset diagonally towards the center of the image
let corner_tl_rect = Rect::from_origin_size((0., 0.), (50., 50.));
let corner_tl_cache = rc.capture_image_area(corner_tl_rect).unwrap();
let corner_tl_cachedraw_rect = Rect::from_origin_size((50., 50.), (50., 50.));
rc.draw_image(
&corner_tl_cache,
corner_tl_cachedraw_rect,
INTERPOLATION_MODE,
);

// Capture the top right corner and redrew it inset diagonally towards the center of the image
let corner_tr_rect = Rect::from_origin_size((150., 0.), (50., 50.));
let corner_tr_cache = rc.capture_image_area(corner_tr_rect).unwrap();
let corner_tr_cachedraw_rect = Rect::from_origin_size((100., 50.), (50., 50.));
rc.draw_image(
&corner_tr_cache,
corner_tr_cachedraw_rect,
INTERPOLATION_MODE,
);

// Capture the bottom left corner and redrew it inset diagonally towards the center of the image
let corner_bl_rect = Rect::from_origin_size((0., 150.), (50., 50.));
let corner_bl_cache = rc.capture_image_area(corner_bl_rect).unwrap();
let corner_bl_cachedraw_rect = Rect::from_origin_size((50., 100.), (50., 50.));
rc.draw_image(
&corner_bl_cache,
corner_bl_cachedraw_rect,
INTERPOLATION_MODE,
);

// Capture the bottom right corner and redrew it inset diagonally towards the center of the image
let corner_br_rect = Rect::from_origin_size((150., 150.), (50., 50.));
let corner_br_cache = rc.capture_image_area(corner_br_rect).unwrap();
let corner_br_cachedraw_rect = Rect::from_origin_size((100., 100.), (50., 50.));
rc.draw_image(
&corner_br_cache,
corner_br_cachedraw_rect,
INTERPOLATION_MODE,
);

Ok(())
}