Skip to content

Commit

Permalink
Added temp fix to relative quadratic commands, and changed example to…
Browse files Browse the repository at this point in the history
… show it works
  • Loading branch information
TheLeonsver1 committed Feb 25, 2021
1 parent cf5cbda commit e88b461
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
18 changes: 9 additions & 9 deletions examples/svg_path_shape_example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fn main() {
}
struct Name(String);
struct BlacksmithMarker;
struct HouseOfPrayerMarker;
struct ToolShackMarker;
#[derive(Bundle)]
struct BuildingBundle {
name: Name,
Expand Down Expand Up @@ -59,37 +59,37 @@ fn startup_system(commands: &mut Commands, mut materials: ResMut<Assets<ColorMat
.with(GlobalTransform::default());
});
commands.spawn(BuildingBundle {
name: Name("House Of Prayer".to_owned()),
transform:Transform::from_translation(Vec3::new(375.,0.,0.)),
name: Name("Shack".to_owned()),
transform:Transform{translation:Vec3::new(375.,0.,0.),scale:Vec3::new(0.1,0.1,1.),..Default::default()},
global_transform:GlobalTransform::default()
})
.with(HouseOfPrayerMarker)
.with(ToolShackMarker)
//we split our art in this example to two children because our art is made out of 2 paths,
//one path who's width is 4,
//and another whose width is 2.5
//the art style was approximated from https://www.kenney.nl/assets/cartography-pack
.with_children(|parent|{
let svg_doc_size = Vec2::new(512.,512.);
let svg_doc_size = Vec2::new(1000.,1000.);
parent.spawn(
GeometryBuilder::build_as(
&shapes::SvgPathShape{
svg_path_string:"m 451.08823,183.34138 v 1.23527 l 32.93058,-1.23527 C 449.61188,131.857 418.92615,69.387224 385.22702,18.688274 347.37606,79.500094 318.96905,124.78068 286.43521,183.34138 h 32.93062 m 131.7224,1.23527 c -1.235,97.55653 -0.82797,200.67401 2.2e-4,295.14045 M 319.36583,216.27223 c -1.37219,-1.37232 -4.80245,-1.37232 -10.29081,0 -97.52186,34.53072 -190.38406,59.53117 -286.084619,98.79176 7.134941,12.0746 12.760607,17.83761 16.876939,17.2887 4.116305,-0.55022 7.546573,2.74437 10.290808,9.87915 l 2.469641,-1.64596 c 1.097791,0.28059 2.19551,2.74437 3.293049,7.40919 2.351405,48.53927 -2.559249,92.5245 0,131.72262 M 319.36569,216.27282 c -1.37219,-17.01407 -1.37219,-27.9909 0,-32.93059".to_owned(),
svg_path_string:"m 254.47507,533.90714 28.03554,-31.1502 29.07393,-32.18938 30.11225,-26.99742 29.07391,-30.11185 28.03556,-34.26547 29.07391,-25.95885 28.03556,-29.0741 q 13.49859,-16.61388 21.80543,-21.80524 l 25.95885,-17.65243 q 20.76708,9.34498 26.9972,26.99742 6.2297,18.68994 25.95885,35.30382 l 34.26568,29.07411 31.15062,24.9205 26.9972,23.88213 24.92049,29.07412 28.03556,37.38075 q 12.46024,18.69016 22.84378,21.80522 11.4219,4.15218 28.03556,20.76687 m -332.27326,332.27305 2.07692,-44.64881 v -40.496 l -6.23054,-39.45766 -3.11527,-42.57209 1.03835,-35.30383 6.23054,-46.72655 44.64922,-3.1161 38.4191,1.03627 30.11226,-1.03627 52.95605,3.1161 q 5.19218,20.76749 -2.0767,43.61128 -6.22972,22.84357 1.03835,41.53437 7.26806,18.68995 3.11527,39.45682 l -6.23054,46.72656 q -1.03836,25.95884 1.03835,35.30381 l 3.11527,42.5721 m 164.05971,-83.0681 -33.22711,-1.03629 -47.76428,1.03629 -4.15362,-32.18855 4.15362,-50.87956 34.26567,1.03628 48.80264,-1.03628 m -498.40988,-83.06873 30.11226,4.15217 52.95606,-4.15217 3.11505,33.22774 q -3.11505,11.42189 -3.11505,49.84099 l -28.03557,1.03628 -55.03275,-1.03628".to_owned(),
svg_doc_size_in_px:svg_doc_size.to_owned()
},

materials.add(ColorMaterial::color(Color::BLACK)),
TessellationMode::Stroke(StrokeOptions::default().with_line_width(4.)),
TessellationMode::Stroke(StrokeOptions::default().with_line_width(20.)),
Transform::default()
))
.with(GlobalTransform::default())
.spawn(GeometryBuilder::build_as(
&shapes::SvgPathShape{
svg_path_string:"M 319.36583,183.34138 C 343.33899,145.4125 364.63234,109.93103 382.3456,71.788704 l 2.8813,-3.70451 c 23.4704,40.721146 42.63396,73.872316 61.74487,110.729226 l 4.11637,4.52796 m -1.235,98.7918 -13.17225,-0.41051 -18.52347,0.41051 c 2.74409,5.48846 3.15591,9.60474 1.235,12.34888 -1.64632,3.0181 -2.05801,9.87915 -1.235,20.58157 l 10.29087,-1.64596 22.63976,1.64596 m -65.86103,-98.7918 13.99549,-11.93711 6.58613,-9.46787 12.34896,-11.52547 -13.17221,-11.93747 -8.23267,-8.2326 c -11.81354,-15.42301 -12.23497,-12.07317 -25.10955,0.41051 l -6.58613,6.99751 -12.76064,12.76078 c 3.29309,6.31174 7.13498,10.70256 11.52572,13.17216 l 8.6443,7.40955 12.7606,12.34874 m -332.599069,124.31311 4.527956,-3.29292 12.348983,-2.47058 15.230396,-4.11655 15.642024,-6.17424 16.46532,-3.29327 15.23039,-5.35133 15.2304,-8.64424 15.64203,-6.58587 14.40714,-5.35123 15.64206,-4.11655 18.52345,-4.11628 c 6.03729,-1.6461 10.83966,-3.84255 14.40714,-6.58592 3.8419,-2.47059 8.50709,-3.70487 13.99552,-3.70487 5.48844,0 10.70244,-1.64609 15.64203,-4.93973 18.92671,-12.50988 42.50014,-13.60179 63.80304,-22.63953 l 3.70469,-21.40502 c 0.27378,-3.56737 -0.96054,-7.40929 -3.70469,-11.52556 m 0,32.93058 c 4.67089,22.68942 -0.40415,42.79932 3.2e-4,65.86131 l 18.93508,-0.41051 13.99552,0.41051 -2.0583,20.58134 c -0.82328,2.19668 -0.13687,6.31174 2.0583,12.34911 l -19.34677,1.23532 -13.58383,-1.23532 c 1.07316,49.43391 -1.86756,86.9026 9e-5,131.7223 m 0,-164.65275 c -0.5489,3.56741 -0.68603,6.99778 -0.41164,10.29079 l 0.41164,22.63966 m 32.93057,131.7223 c 0.24585,-33.44016 -0.087,-69.45583 0,-98.7918 21.47192,0.45467 46.52051,0.0979 65.86119,0 0.78263,36.13255 0.48729,71.43814 0,98.7918 m -288.14271,-124.72411 -8.23267,9.46751 2.46964,18.11175 -0.41164,12.34874 -0.82328,17.2887 -1.23497,16.46543 c -0.82329,4.66519 -0.82329,10.7022 0,18.11171 l 18.11185,-0.41051 14.81876,0.41051 0.82329,-20.58171 -2.0583,-14.8187 c -1.64632,-5.4885 -2.05797,-10.83969 -1.23497,-16.05379 l 3.29305,-14.81875 c 1.09779,-4.66518 0.82328,-10.01615 -0.82328,-16.05338 l -7.82101,-9.05624 -8.6443,-7.40919 -8.23264,6.99792 m 123.48975,9.46751 c -1.37219,7.68356 -1.23497,13.03488 0.41164,16.05338 1.92076,3.29292 1.92076,8.36974 0,15.23039 -1.64632,6.86064 -1.64632,12.76087 0,17.70047 1.64632,4.93955 1.78354,8.9186 0.41164,11.93711 -1.37219,3.293 -1.64663,10.42806 -0.82328,21.40498 l -13.58386,1.23531 -19.34674,-1.23531 -2.46963,-16.87702 c -0.82328,-5.76287 -0.41164,-11.93715 1.23497,-18.52339 l 2.0583,-16.46543 -0.41164,-10.70219 -0.41163,-19.7583 c 5.21396,-4.11632 8.36981,-7.68405 9.46752,-10.70256 1.37219,-2.74436 3.7048,-4.66519 6.99772,-5.76287 5.48844,0.82476 8.2327,3.29323 8.2327,7.40919 0.27378,4.39065 3.01853,7.40956 8.23265,9.05624 m -197.583659,49.39588 11.525746,0.82476 21.404872,-0.82476 c 2.744077,5.21396 3.43034,9.33024 2.058297,12.34874 -1.372192,3.01828 -2.058297,9.87929 -2.058297,20.58171 l -13.995486,0.41051 -18.935132,-0.41051".to_owned(),
svg_path_string:"m 254.47507,866.18019 q 18.69037,-88.25945 8.30683,-113.17996 -9.34519,-24.92049 -8.30683,-52.95625 11.42188,-69.57013 0,-83.06873 v -83.06811 l -34.26568,42.57292 q -8.30684,13.49862 -48.80263,40.49519 l -49.841,-39.45683 Q 99.760328,557.78928 88.33844,533.90714 99.760328,499.64167 136.10271,475.75953 l 67.49301,-53.99462 57.10946,-62.30123 q 28.03557,-33.22712 57.10947,-53.9946 29.07391,-20.76688 55.03276,-58.14762 26.9972,-36.34218 62.30124,-59.18595 36.34239,-21.80524 47.76428,-45.68738 12.46024,-23.88276 20.76708,-23.88276 17.65201,12.46025 43.61086,52.95626 25.95885,40.49601 65.4163,66.45486 l 72.68478,55.03235 57.10946,58.14822 60.22453,60.22453 q 36.34259,31.1502 47.76427,60.22432 11.42191,29.07412 34.26569,45.68736 23.88214,17.65244 34.26589,16.61387 l -43.61088,41.53437 -39.45764,41.53374 q -17.65203,-26.99657 -38.4191,-40.49519 l -44.64922,-42.57292 v 60.22453 105.91231 83.06811 h -2.07671 q -7.26826,4.15217 2.07671,83.0681".to_owned(),
svg_doc_size_in_px:svg_doc_size.to_owned()
},

materials.add(ColorMaterial::color(Color::BLACK)),
TessellationMode::Stroke(StrokeOptions::default().with_line_width(2.5)),
TessellationMode::Stroke(StrokeOptions::default().with_line_width(17.5)),
Transform::default()
))
.with(GlobalTransform::default());
Expand Down
4 changes: 4 additions & 0 deletions src/shapes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,10 +371,14 @@ impl Geometry for SvgPathShape {
get_point_after_offset(x, y, offset_x, offset_y),
);
} else {
/*
svg_builder.relative_quadratic_bezier_to(
get_corrected_relative_vector(x1, y1),
get_corrected_relative_vector(x, y),
);
*/
//temporary fix until Lyon 0.17.6(?) comes out
svg_builder.quadratic_bezier_to(svg_builder.current_position()+get_corrected_relative_vector(x1, y1),svg_builder.current_position()+get_corrected_relative_vector(x, y));
}
}
PathSegment::SmoothQuadratic { abs, x, y } => {
Expand Down

0 comments on commit e88b461

Please sign in to comment.