Skip to content

Commit

Permalink
x and y spacing now use InputNumber, added style.
Browse files Browse the repository at this point in the history
  • Loading branch information
i-make-robots committed Feb 7, 2025
1 parent f82e3ff commit da9866d
Showing 1 changed file with 22 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.marginallyclever.makelangelo.donatelloimpl.nodes.points;

import com.marginallyclever.donatello.ports.InputDouble;
import com.marginallyclever.donatello.ports.InputInt;
import com.marginallyclever.donatello.ports.InputNumber;
import com.marginallyclever.donatello.ports.InputOneOfMany;
import com.marginallyclever.nodegraphcore.Node;

import javax.vecmath.Point2d;
Expand All @@ -12,9 +13,10 @@
*/
public class GridOfPoints extends Node {
private final InputInt numberAcross = new InputInt("x count",10);
private final InputDouble spaceAcross = new InputDouble("x spacing",10d);
private final InputNumber spaceAcross = new InputNumber("x spacing",10d);
private final InputInt numberDown = new InputInt("y count",10);
private final InputDouble spaceDown = new InputDouble("y spacing",10d);
private final InputNumber spaceDown = new InputNumber("y spacing",10d);
private final InputOneOfMany style = new InputOneOfMany("style");
private final OutputPoints output = new OutputPoints("output");

public GridOfPoints() {
Expand All @@ -23,23 +25,34 @@ public GridOfPoints() {
addVariable(spaceAcross);
addVariable(numberDown);
addVariable(spaceDown);
addVariable(style);
addVariable(output);

style.setOptions(new String[]{"spacing","total"});
}

@Override
public void update() {
var nx = Math.max(1,numberAcross.getValue());
var ny = Math.max(1,numberDown.getValue());
var dx = spaceAcross.getValue();
var dy = spaceDown.getValue();
double dx, dy;

var list = new ListOfPoints();
IntStream.range(0,ny).forEach(y->{
IntStream.range(0,nx).forEach(x->{
list.add(new Point2d(x*dx,y*dy));
if(style.getValue()==1) {
// total distance divided by number of points.
dx = spaceAcross.getValue().doubleValue() / nx;
dy = spaceDown.getValue().doubleValue() / ny;
} else {
// space between points
dx = spaceAcross.getValue().doubleValue();
dy = spaceDown.getValue().doubleValue();
}

IntStream.range(0, ny).forEach(y -> {
IntStream.range(0, nx).forEach(x -> {
list.add(new Point2d(x * dx, y * dy));
});
});

output.send(list);
}
}

0 comments on commit da9866d

Please sign in to comment.