mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2025-12-23 10:11:54 +00:00
Fix angle logic in the Grid node to allow slanted isometric grids (#2602)
* Fix angles * Fix hardcoded index * More information on monitor nodes
This commit is contained in:
parent
dd1feee734
commit
704dad4f76
3 changed files with 29 additions and 10 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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:?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue