Skip to content

Fix angle logic in the Grid node to allow slanted isometric grids #2602

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

Merged
merged 3 commits into from
Apr 20, 2025
Merged
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
@@ -17,6 +17,7 @@ use graphene_core::raster::{
SelectiveColorChoice,
};
use graphene_core::text::Font;
use graphene_core::vector::generator_nodes::grid;
use graphene_core::vector::misc::CentroidType;
use graphene_core::vector::style::{GradientType, LineCap, LineJoin};
use graphene_std::animation::RealTimeMode;
@@ -27,7 +28,7 @@ use graphene_std::vector::VectorDataTable;
use graphene_std::vector::misc::ArcType;
use graphene_std::vector::misc::{BooleanOperation, GridType};
use graphene_std::vector::style::{Fill, FillChoice, FillType, GradientStops};
use graphene_std::{GraphicGroupTable, RasterFrame};
use graphene_std::{GraphicGroupTable, NodeInputDecleration, RasterFrame};

pub(crate) fn string_properties(text: &str) -> Vec<LayoutGroup> {
let widget = TextLabel::new(text).widget_holder();
@@ -1621,11 +1622,11 @@ pub(crate) fn _gpu_map_properties(parameter_widgets_info: ParameterWidgetsInfo)
}

pub(crate) fn grid_properties(node_id: NodeId, context: &mut NodePropertiesContext) -> Vec<LayoutGroup> {
let grid_type_index = 1;
let spacing_index = 2;
let angles_index = 3;
let rows_index = 4;
let columns_index = 5;
let grid_type_index = grid::GridTypeInput::INDEX;
let spacing_index = grid::SpacingInput::<f64>::INDEX;
let angles_index = grid::AnglesInput::INDEX;
let rows_index = grid::RowsInput::INDEX;
let columns_index = grid::ColumnsInput::INDEX;

let document_node = match get_document_node(node_id, context) {
Ok(document_node) => document_node,
2 changes: 1 addition & 1 deletion editor/src/node_graph_executor/runtime.rs
Original file line number Diff line number Diff line change
@@ -295,7 +295,7 @@ impl NodeRuntime {
} else if let Some(record) = introspected_data.downcast_ref::<IORecord<Context, VectorDataTable>>() {
self.vector_modify.insert(parent_network_node_id, record.output.one_instance().instance.clone());
} else {
log::warn!("failed to downcast monitor node output");
log::warn!("failed to downcast monitor node output {parent_network_node_id:?}");
}
}
}
24 changes: 21 additions & 3 deletions node-graph/gcore/src/vector/generator_nodes.rs
Original file line number Diff line number Diff line change
@@ -205,9 +205,14 @@ fn grid<T: GridSpacing>(
for x in 0..columns {
// Add current point to the grid with offset for odd columns
let current_index = vector_data.point_domain.ids().len();
vector_data
.point_domain
.push(point_id.next_id(), DVec2::new(spacing.x * x as f64, spacing.y * (y as f64 - (x % 2) as f64 * 0.5)));

let a_angles_eaten = ((x + 1) / 2) as f64;
let b_angles_eaten = (x / 2) as f64;

let offset_y_fraction = b_angles_eaten * tan_b - a_angles_eaten * tan_a;

let position = DVec2::new(spacing.x * x as f64, spacing.y * y as f64 + offset_y_fraction * spacing.x);
vector_data.point_domain.push(point_id.next_id(), position);

// Helper function to connect points with line segments
let mut push_segment = |to_index: Option<usize>| {
@@ -259,3 +264,16 @@ fn isometric_grid_test() {
);
}
}

#[test]
fn skew_isometric_grid_test() {
let grid = grid((), (), GridType::Isometric, 10., (40., 30.).into(), 5, 5);
assert_eq!(grid.one_instance().instance.point_domain.ids().len(), 5 * 5);
assert_eq!(grid.one_instance().instance.segment_bezier_iter().count(), 4 * 5 + 4 * 9);
for (_, bezier, _, _) in grid.one_instance().instance.segment_bezier_iter() {
assert_eq!(bezier.handles, bezier_rs::BezierHandles::Linear);
let vector = bezier.start - bezier.end;
let angle = (vector.angle_to(DVec2::X).to_degrees() + 180.) % 180.;
assert!([90., 150., 40.].into_iter().any(|target| (target - angle).abs() < 1e-10), "unexpected angle of {}", angle)
}
}