Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix rotation of symbols with stroke #14

Merged
merged 1 commit into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"width": 500,
"height": 100,
"origin_x": 0,
"origin_y": 0
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
127 changes: 127 additions & 0 deletions sg2d-vega-test-data/vega-scenegraphs/symbol/wedge_stroke_angle.sg.json
Original file line number Diff line number Diff line change
@@ -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
}
40 changes: 40 additions & 0 deletions sg2d-vega-test-data/vega-specs/symbol/wedge_stroke_angle.vg.json
Original file line number Diff line number Diff line change
@@ -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"}
}
}
}
]
}
3 changes: 2 additions & 1 deletion sg2d-wgpu/src/marks/polygon_symbol.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -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<f32>(normalized_pos, 0.0, 1.0);
Expand Down
1 change: 1 addition & 0 deletions sg2d-wgpu/tests/test_image_baselines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)]
Expand Down