Repository: GraphiteEditor/Graphite
File: node-graph/gcore/src/vector/vector_nodes.rs (Rust)

Code before:
	insert_new_segments(&mut vector_data, &new_segments);

	vector_data
}

#[node_macro::node(category("Vector"), path(graphene_core::vector))]
fn bevel(_: impl Ctx, source: VectorDataTable, #[default(10.)] distance: Length) -> VectorDataTable {
	let source_transform = source.transform();
	let source = source.one_instance_ref().instance;

	let mut result = VectorDataTable::new(bevel_algorithm(source.clone(), source_transform, distance));
	*result.transform_mut() = source_transform;
	result
}

#[node_macro::node(name("Close Path"), category("Vector"), path(graphene_core::vector))]
fn close_path(_: impl Ctx, source: VectorDataTable) -> VectorDataTable {
	let mut new_table = VectorDataTable::empty();
	for mut source_instance in source.instance_iter() {
		source_instance.instance.close_subpaths();
		new_table.push(Instance {
			instance: source_instance.instance,
			transform: source_instance.transform,
			alpha_blending: source_instance.alpha_blending,
			source_node_id: source_instance.source_node_id,
		})
	}
	new_table
}

#[node_macro::node(name("Point Inside Shape"), category("Vector"), path(graphene_core::vector))]
fn point_inside(_: impl Ctx, source: VectorDataTable, point: DVec2) -> bool {
	source.instance_iter().any(|instance| {
		let tranform = instance.transform;
		instance.instance.check_point_inside_shape(tranform, point)
	})
}

#[node_macro::node(name("Merge by Distance"), category("Vector"), path(graphene_core::vector))]
fn merge_by_distance(_: impl Ctx, source: VectorDataTable, #[default(10.)] distance: Length) -> VectorDataTable {
	let source_transform = source.transform();
	let mut source = source.one_instance_ref().instance.clone();

	source.merge_by_distance(distance);

	let mut result = VectorDataTable::new(source);
	*result.transform_mut() = source_transform;

	result
}


Review comment (suggestion):
You don't need to construct a new instance composed of all the same fields as the current instance. Just push the current instance (`source_instance`).

Code after:
	insert_new_segments(&mut vector_data, &new_segments);

	vector_data
}

#[node_macro::node(category("Vector"), path(graphene_core::vector))]
fn bevel(_: impl Ctx, source: VectorDataTable, #[default(10.)] distance: Length) -> VectorDataTable {
	let source_transform = source.transform();
	let source = source.one_instance_ref().instance;

	let mut result = VectorDataTable::new(bevel_algorithm(source.clone(), source_transform, distance));
	*result.transform_mut() = source_transform;
	result
}

#[node_macro::node(category("Vector"), path(graphene_core::vector))]
fn close_path(_: impl Ctx, source: VectorDataTable) -> VectorDataTable {
	let mut new_table = VectorDataTable::empty();

	for mut source_instance in source.instance_iter() {
		source_instance.instance.close_subpaths();
		new_table.push(source_instance);
	}

	new_table
}

#[node_macro::node(category("Vector"), path(graphene_core::vector))]
fn point_inside(_: impl Ctx, source: VectorDataTable, point: DVec2) -> bool {
	source.instance_iter().any(|instance| instance.instance.check_point_inside_shape(instance.transform, point))
}

#[node_macro::node(name("Merge by Distance"), category("Vector"), path(graphene_core::vector))]
fn merge_by_distance(_: impl Ctx, source: VectorDataTable, #[default(10.)] distance: Length) -> VectorDataTable {
	let source_transform = source.transform();
	let mut source = source.one_instance_ref().instance.clone();

	source.merge_by_distance(distance);

	let mut result = VectorDataTable::new(source);
	*result.transform_mut() = source_transform;

	result
}

#[node_macro::node(category("Vector"), path(graphene_core::vector))]
async fn area(ctx: impl Ctx + CloneVarArgs + ExtractAll, vector_data: impl Node<Context<'static>, Output = VectorDataTable>) -> f64 {
	let new_ctx = OwnedContextImpl::from(ctx).with_footprint(Footprint::default()).into_context();
	let vector_data = vector_data.eval(new_ctx).await;

	let vector_data_transform = vector_data.transform();