auto align

This commit is contained in:
Tanasart 2024-07-05 09:50:07 +07:00
parent 6a0a36a577
commit 8442cc6f19
3 changed files with 38 additions and 3 deletions

View file

@ -110,7 +110,7 @@ function node_vdistribute(nodeList) {
ds_priority_destroy(nodes);
}
function node_hdistribute_dist(nodeList, anchor, distance = 0) {
function node_hdistribute_dist(nodeList, anchor = noone, distance = 0) {
var amo = array_length(nodeList);
var nodes = ds_priority_create();
@ -130,6 +130,7 @@ function node_hdistribute_dist(nodeList, anchor, distance = 0) {
ar[i] = ds_priority_delete_min(nodes);
ds_priority_destroy(nodes);
if(anchor == noone) anchor = ar[0];
var an_ind = array_find(ar, anchor);
var an_ind_x = anchor.x + anchor.w + distance;
@ -145,7 +146,7 @@ function node_hdistribute_dist(nodeList, anchor, distance = 0) {
}
}
function node_vdistribute_dist(nodeList, anchor, distance = 0) {
function node_vdistribute_dist(nodeList, anchor = noone, distance = 0) {
var amo = array_length(nodeList);
var nodes = ds_priority_create();
@ -165,6 +166,7 @@ function node_vdistribute_dist(nodeList, anchor, distance = 0) {
ar[i] = ds_priority_delete_min(nodes);
ds_priority_destroy(nodes);
if(anchor == noone) anchor = ar[0];
var an_ind = array_find(ar, anchor);
var an_ind_y = anchor.y + anchor.h + distance;
@ -179,3 +181,32 @@ function node_vdistribute_dist(nodeList, anchor, distance = 0) {
an_ind_y -= ar[i].h + distance;
}
}
function node_auto_align(nodeList) {
var h_avg = 0, h_var = 0;
var v_avg = 0, v_var = 0;
var amo = array_length(nodeList);
for( var i = 0; i < amo; i++ ) {
var _n = nodeList[i];
var _x = _n.x;
var _y = _n.y;
h_avg += _x;
v_avg += _y;
}
h_avg /= amo;
v_avg /= amo;
for( var i = 0; i < amo; i++ ) {
var _n = nodeList[i];
h_var += sqr(_n.x - h_avg);
v_var += sqr(_n.y - v_avg);
}
if(h_var < v_var) { node_halign(nodeList); node_vdistribute(nodeList); }
else if(v_var < h_var) { node_valign(nodeList); node_hdistribute(nodeList); }
}

View file

@ -80,6 +80,8 @@
function panel_graph_duplicate() { CALL("graph_duplicate"); PANEL_GRAPH.doDuplicate(); }
function panel_graph_copy() { CALL("graph_copy"); PANEL_GRAPH.doCopy(); }
function panel_graph_paste() { CALL("graph_paste"); PANEL_GRAPH.doPaste(); }
function panel_graph_auto_align() { CALL("graph_auto_align"); node_auto_align(PANEL_GRAPH.nodes_selecting);}
function panel_graph_pan() {
CALL("graph_pan");
@ -391,6 +393,8 @@ function Panel_Graph(project = PROJECT) : PanelContent() constructor {
addHotkey("Graph", "Pan", "", MOD_KEY.ctrl, panel_graph_pan);
addHotkey("Graph", "Zoom", "", MOD_KEY.alt | MOD_KEY.ctrl, panel_graph_zoom);
addHotkey("Graph", "Auto Align", "L", MOD_KEY.none, panel_graph_auto_align);
#endregion
#region ++++ toolbars ++++

View file

@ -537,9 +537,9 @@ float sceneSDF(int index, vec3 p) {
mat3 irotMatrix = inverse(rotMatrix);
float sca = objectScale[index];
p /= sca;
p -= position[index];
p = irotMatrix * p;
p /= sca;
p = wave(waveAmp[index], waveShift[index], waveInt[index], p);