diff --git a/sg2d-vega-test-data/vega-scenegraphs/symbol/wedge_stroke_angle.dims.json b/sg2d-vega-test-data/vega-scenegraphs/symbol/wedge_stroke_angle.dims.json new file mode 100644 index 0000000..50fd0bc --- /dev/null +++ b/sg2d-vega-test-data/vega-scenegraphs/symbol/wedge_stroke_angle.dims.json @@ -0,0 +1,6 @@ +{ + "width": 500, + "height": 100, + "origin_x": 0, + "origin_y": 0 +} \ No newline at end of file diff --git a/sg2d-vega-test-data/vega-scenegraphs/symbol/wedge_stroke_angle.png b/sg2d-vega-test-data/vega-scenegraphs/symbol/wedge_stroke_angle.png new file mode 100644 index 0000000..ee80992 Binary files /dev/null and b/sg2d-vega-test-data/vega-scenegraphs/symbol/wedge_stroke_angle.png differ diff --git a/sg2d-vega-test-data/vega-scenegraphs/symbol/wedge_stroke_angle.sg.json b/sg2d-vega-test-data/vega-scenegraphs/symbol/wedge_stroke_angle.sg.json new file mode 100644 index 0000000..7d7e7db --- /dev/null +++ b/sg2d-vega-test-data/vega-scenegraphs/symbol/wedge_stroke_angle.sg.json @@ -0,0 +1,127 @@ +{ + "marktype": "group", + "name": "root", + "role": "frame", + "interactive": true, + "clip": false, + "items": [ + { + "items": [ + { + "marktype": "symbol", + "role": "mark", + "interactive": true, + "clip": false, + "items": [ + { + "x": 30, + "y": 40, + "fill": "red", + "stroke": "black", + "strokeWidth": 3, + "size": 600, + "shape": "wedge", + "angle": 0 + }, + { + "x": 60, + "y": 40, + "fill": "red", + "stroke": "black", + "strokeWidth": 3, + "size": 1200, + "shape": "wedge", + "angle": 30 + }, + { + "x": 90, + "y": 40, + "fill": "red", + "stroke": "black", + "strokeWidth": 3, + "size": 1800, + "shape": "wedge", + "angle": 90 + }, + { + "x": 150, + "y": 40, + "fill": "red", + "stroke": "black", + "strokeWidth": 3, + "size": 2200, + "shape": "wedge", + "angle": 120 + }, + { + "x": 200, + "y": 40, + "fill": "red", + "stroke": "black", + "strokeWidth": 3, + "size": 2800, + "shape": "wedge", + "angle": 180 + }, + { + "x": 250, + "y": 40, + "fill": "red", + "stroke": "black", + "strokeWidth": 3, + "size": 3000, + "shape": "wedge", + "angle": 240 + }, + { + "x": 310, + "y": 40, + "fill": "red", + "stroke": "black", + "strokeWidth": 3, + "size": 1600, + "shape": "wedge", + "angle": 270 + }, + { + "x": 360, + "y": 40, + "fill": "red", + "stroke": "black", + "strokeWidth": 3, + "size": 2400, + "shape": "wedge", + "angle": 300 + }, + { + "x": 400, + "y": 40, + "fill": "red", + "stroke": "black", + "strokeWidth": 3, + "size": 3000, + "shape": "wedge", + "angle": 330 + }, + { + "x": 450, + "y": 40, + "fill": "red", + "stroke": "black", + "strokeWidth": 3, + "size": 3600, + "shape": "wedge", + "angle": 360 + } + ], + "zindex": 0 + } + ], + "x": 0, + "y": 0, + "width": 500, + "height": 100 + } + ], + "zindex": 0 +} \ No newline at end of file diff --git a/sg2d-vega-test-data/vega-specs/symbol/wedge_stroke_angle.vg.json b/sg2d-vega-test-data/vega-specs/symbol/wedge_stroke_angle.vg.json new file mode 100644 index 0000000..90e7161 --- /dev/null +++ b/sg2d-vega-test-data/vega-specs/symbol/wedge_stroke_angle.vg.json @@ -0,0 +1,40 @@ +{ + "width": 500, + "height": 100, + "background": "white", + "data": [ + { + "name": "data_1", + "values": [ + {"x": 30, "angle": 0, "size": 600}, + {"x": 60, "angle": 30, "size": 1200}, + {"x": 90, "angle": 90, "size": 1800}, + {"x": 150, "angle": 120, "size": 2200}, + {"x": 200, "angle": 180, "size": 2800}, + {"x": 250, "angle": 240, "size": 3000}, + {"x": 310, "angle": 270, "size": 1600}, + {"x": 360, "angle": 300, "size": 2400}, + {"x": 400, "angle": 330, "size": 3000}, + {"x": 450, "angle": 360, "size": 3600} + ] + } + ], + "marks": [ + { + "type": "symbol", + "from": {"data": "data_1"}, + "encode": { + "update": { + "x": {"field": "x"}, + "y": {"value": 40}, + "shape": {"value": "wedge"}, + "fill": {"value": "red"}, + "stroke": {"value": "black"}, + "strokeWidth": {"value": 3}, + "size": {"field": "size"}, + "angle": {"field": "angle"} + } + } + } + ] +} \ No newline at end of file diff --git a/sg2d-wgpu/src/marks/polygon_symbol.wgsl b/sg2d-wgpu/src/marks/polygon_symbol.wgsl index 7c41414..22fcd52 100644 --- a/sg2d-wgpu/src/marks/polygon_symbol.wgsl +++ b/sg2d-wgpu/src/marks/polygon_symbol.wgsl @@ -63,8 +63,9 @@ fn vs_main( // The factor of 2.0 here is because the normal vector that lyon // returns has length such that moving all stroke vertices by the length // of the "normal" vector will increase the line width by 2. + let normal = rot * model.normal; var diff = scaled_stroke_width - instance.stroke_width; - let adjusted_pos = pos - diff * model.normal / 2.0; + let adjusted_pos = pos - diff * normal / 2.0; let normalized_pos = 2.0 * adjusted_pos / chart_uniforms.size - 1.0; out.clip_position = vec4(normalized_pos, 0.0, 1.0); diff --git a/sg2d-wgpu/tests/test_image_baselines.rs b/sg2d-wgpu/tests/test_image_baselines.rs index 113f53b..7f581e1 100644 --- a/sg2d-wgpu/tests/test_image_baselines.rs +++ b/sg2d-wgpu/tests/test_image_baselines.rs @@ -36,6 +36,7 @@ mod test_image_baselines { case("symbol", "scatter_transparent_stroke_star", 0.005), case("symbol", "wind_vector", 0.0015), case("symbol", "wedge_angle", 0.001), + case("symbol", "wedge_stroke_angle", 0.001), case("rule", "wide_rule_axes", 0.0001), case("text", "bar_axis_labels", 0.01) )]