fix viewport translation with nonzero x,y

master
Sameer Puri 4 years ago
parent 4215e474d7
commit f3016f9e20

@ -84,8 +84,8 @@ pub fn svg2program<'input>(
if let Some(view_box) = node.attribute("viewBox") { if let Some(view_box) = node.attribute("viewBox") {
let view_box = ViewBox::from_str(view_box).expect("could not parse viewBox"); let view_box = ViewBox::from_str(view_box).expect("could not parse viewBox");
transforms.push( transforms.push(
Transform2D::scale(1. / view_box.w, 1. / view_box.h) Transform2D::translation(-view_box.x, -view_box.y)
.then_translate(vector(view_box.x, view_box.y)), .then_scale(1. / view_box.w, 1. / view_box.h),
); );
} }

@ -250,4 +250,12 @@ mod test {
assert_eq!(actual, include_str!("../tests/square_transformed.gcode")) assert_eq!(actual, include_str!("../tests/square_transformed.gcode"))
} }
#[test]
fn square_viewport_produces_expected_gcode() {
let square_transformed = include_str!("../tests/square_viewport.svg");
let actual = get_actual(square_transformed);
assert_eq!(actual, include_str!("../tests/square_viewport.gcode"))
}
} }

@ -0,0 +1,45 @@
G21
G90;svg#svg8 > g#layer1 > path#path838
G0 X1 Y9
G1 X9 Y9 F300
G1 X9 Y1 F300
G1 X1 Y1 F300
G1 X1 Y9 F300;svg#svg8 > g#layer1 > path#path832
G0 X8 Y2.5
G1 X7.992016 Y2.4110041813117045 F300
G1 X7.9683189770239995 Y2.324850533089038 F300
G1 X7.929665719197761 Y2.24429045824164 F300
G1 X7.877290656963224 Y2.171896723319837 F300
G1 X7.812866440307907 Y2.1099812946420924 F300
G1 X7.738450521014919 Y2.060521503338657 F300
G1 X7.656419445882797 Y2.025096897304599 F300
G1 X7.569392959326962 Y2.0048387967582206 F300
G1 X7.5 Y2 F300
G1 X7.4110041813117045 Y2.007984 F300
G1 X7.324850533089037 Y2.031681022976 F300
G1 X7.24429045824164 Y2.0703342808022382 F300
G1 X7.171896723319837 Y2.1227093430367767 F300
G1 X7.1099812946420915 Y2.1871335596920924 F300
G1 X7.0605215033386575 Y2.261549478985082 F300
G1 X7.025096897304598 Y2.343580554117203 F300
G1 X7.004838796758221 Y2.430607040673038 F300
G1 X7 Y2.5000000000000004 F300
G1 X7.007984 Y2.5889958186882964 F300
G1 X7.0316810229760005 Y2.6751494669109626 F300
G1 X7.070334280802239 Y2.7557095417583604 F300
G1 X7.122709343036777 Y2.8281032766801633 F300
G1 X7.187133559692093 Y2.8900187053579085 F300
G1 X7.261549478985082 Y2.9394784966613434 F300
G1 X7.343580554117204 Y2.9749031026954014 F300
G1 X7.4306070406730385 Y2.9951612032417794 F300
G1 X7.5 Y3 F300
G1 X7.5889958186882955 Y2.992016 F300
G1 X7.675149466910963 Y2.968318977024 F300
G1 X7.75570954175836 Y2.9296657191977618 F300
G1 X7.828103276680163 Y2.8772906569632233 F300
G1 X7.890018705357908 Y2.8128664403079076 F300
G1 X7.9394784966613425 Y2.7384505210149186 F300
G1 X7.974903102695401 Y2.656419445882797 F300
G1 X7.995161203241779 Y2.5693929593269624 F300
G1 X8 Y2.5 F300
M2

@ -0,0 +1,71 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
sodipodi:docname="square_viewport.svg"
inkscape:version="1.1 (c4e8f9ed74, 2021-05-24)"
id="svg8"
version="1.1"
viewBox="-10 -10 10 10"
height="10mm"
width="10mm"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:dc="http://purl.org/dc/elements/1.1/">
<defs
id="defs2" />
<sodipodi:namedview
inkscape:window-maximized="1"
inkscape:window-y="0"
inkscape:window-x="0"
inkscape:window-height="2160"
inkscape:window-width="3840"
units="mm"
showgrid="true"
inkscape:document-rotation="0"
inkscape:current-layer="layer1"
inkscape:document-units="mm"
inkscape:cy="43.362194"
inkscape:cx="-1.7671114"
inkscape:zoom="18.391597"
inkscape:pageshadow="2"
inkscape:pageopacity="0.0"
borderopacity="1.0"
bordercolor="#666666"
pagecolor="#ffffff"
id="base"
inkscape:pagecheckerboard="0">
<inkscape:grid
spacingy="1"
spacingx="1"
units="mm"
id="grid836"
type="xygrid" />
</sodipodi:namedview>
<metadata
id="metadata5">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
</cc:Work>
</rdf:RDF>
</metadata>
<g
id="layer1"
inkscape:groupmode="layer"
inkscape:label="Layer 1">
<path
id="path838"
d="m -9,-9 h 8 v 8 h -8 z"
style="fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
<path
id="path832"
style="fill:#000000;fill-opacity:1;stroke:#000000;stroke-width:0.396875;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none"
d="M -2,-2.5 A 0.5,0.5 0 0 1 -2.5,-2 0.5,0.5 0 0 1 -3,-2.5 0.5,0.5 0 0 1 -2.5,-3 0.5,0.5 0 0 1 -2,-2.5 Z" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 2.2 KiB

Loading…
Cancel
Save