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

Code before:
	#[hard_min(2.)]
	#[implementations(u32, u64, f64)]
	sides: T,
	#[unit(" px")]
	#[default(50)]
	radius_1: f64,
	#[unit(" px")]
	#[default(25)]
	radius_2: f64,
) -> Table<Vector> {
	let points = sides.as_u64();
	let diameter: f64 = radius_1 * 2.;
	let inner_diameter = radius_2 * 2.;

	Table::new_from_element(Vector::from_subpath(subpath::Subpath::new_star_polygon(DVec2::splat(-diameter), points, diameter, inner_diameter)))
}

/// Generates a QR code from the input text.
#[node_macro::node(category("Vector: Shape"))]
fn qr_code(
	_: impl Ctx,
	_primary: (),
	#[default("https://graphite.art")] text: String,
	#[default(true)]
	#[name("Merge Adjacent Tiles")]
	merge: bool,
) -> Table<Vector> {
	let ecc = qrcodegen::QrCodeEcc::Medium;

	let Ok(qr_code) = qrcodegen::QrCode::encode_text(&text, ecc) else {
		return Table::default();
	};

	let size = qr_code.size();
	let mut vector = Vector::default();
	let offset = DVec2::splat(0.0);

	if merge {
		use std::collections::{HashMap, HashSet, VecDeque};

		let mut remaining: HashSet<(i32, i32)> = HashSet::new();
		for y in 0..size {
			for x in 0..size {
				if qr_code.get_module(x, y) {
					remaining.insert((x, y));
				}
			}
		}

		while let Some(&(start_x, start_y)) = remaining.iter().next() {
			let mut island = HashSet::new();

Review comment (suggestion):
Don't use `#[name(...)]` here, it should be used only to fix capitalization issues which isn't needed in this case.

Let's call this `individual_squares` which is the inverse of the current `merge`. It should be `false` by default, meaning the `#[default(true)]` line should be removed, since we normally want the squares to be merged by default unless the user chooses to have individual squares.

Code after:
	#[hard_min(2.)]
	#[implementations(u32, u64, f64)]
	sides: T,
	#[unit(" px")]
	#[default(50)]
	radius_1: f64,
	#[unit(" px")]
	#[default(25)]
	radius_2: f64,
) -> Table<Vector> {
	let points = sides.as_u64();
	let diameter: f64 = radius_1 * 2.;
	let inner_diameter = radius_2 * 2.;

	Table::new_from_element(Vector::from_subpath(subpath::Subpath::new_star_polygon(DVec2::splat(-diameter), points, diameter, inner_diameter)))
}

/// Generates a QR code from the input text.
#[node_macro::node(category("Vector: Shape"), name("QR Code"))]
fn qr_code(
	_: impl Ctx,
	_primary: (),
	#[default("https://graphite.art")] text: String,
	/// Error correction level, from low (0) to high (3).
	#[default(1)]
	error_correction: u32,
	#[default(false)] individual_squares: bool,
) -> Table<Vector> {
	let ecc = match error_correction.min(3) {
		0 => qrcodegen::QrCodeEcc::Low,
		1 => qrcodegen::QrCodeEcc::Medium,
		2 => qrcodegen::QrCodeEcc::Quartile,
		3 => qrcodegen::QrCodeEcc::High,
		_ => unreachable!(),
	};

	let Ok(qr_code) = qrcodegen::QrCode::encode_text(&text, ecc) else {
		return Table::default();
	};

	let size = qr_code.size() as usize;
	let mut vector = Vector::default();

	if individual_squares {
		for y in 0..size {
			for x in 0..size {
				if qr_code.get_module(x as i32, y as i32) {
					let corner1 = DVec2::new(x as f64, y as f64);
					let corner2 = corner1 + DVec2::splat(1.);
					vector.append_subpath(
						subpath::Subpath::from_anchors([corner1, DVec2::new(corner2.x, corner1.y), corner2, DVec2::new(corner1.x, corner2.y)], true),