🐛 Initialize flex line arithmetic before placing the first child

The first layout line starts as nil. JavaScript arithmetic treated its
missing count and bounds as zero, while the JVM threw. Give those three
values zero defaults before calculating gaps and the next line bounds.

A regression failed on the JVM before the fix. Six combinations of row
and column layout with start, around and even spacing now pass. Existing
flex tests pass too; the layout oracle fixtures pass on the JVM.

AI-assisted-by: GPT-6
This commit is contained in:
alonso.torres 2026-10-23 08:46:25 +02:00
parent ac83604f49
commit 2b31f88797
2 changed files with 17 additions and 1 deletions

View File

@ -63,7 +63,8 @@
{:keys [line-min-width line-min-height
line-max-width line-max-height
num-children
children-data]} line-data
children-data]
:or {line-min-width 0 line-min-height 0 num-children 0}} line-data
child-width (gpo/width-points child-bounds)
child-height (gpo/height-points child-bounds)

View File

@ -6,7 +6,9 @@
(ns common-tests.geom-flex-layout-test
(:require
[app.common.geom.modifiers]
[app.common.geom.rect :as grc]
[app.common.geom.shapes.flex-layout.layout-data :as fld]
[app.common.geom.shapes.flex-layout.params :as flparams]
[app.common.geom.shapes.flex-layout.positions :as flp]
[app.common.math :as mth]
@ -135,3 +137,16 @@
:y -2.1457672119140625E-6
:width 100 :height 100}))]
(t/is (every? #(not (neg? %)) (vals padding)))))
(t/deftest first-child-starts-a-flex-line-on-both-runtimes
(doseq [direction [:row :column]
justify [:start :space-around :space-evenly]]
(let [frame (make-col-frame :layout-flex-dir direction :layout-justify-content justify)
child (cts/setup-shape {:type :rect :x 0 :y 0 :width 40 :height 30})
bounds (rect->bounds (grc/make-rect 0 0 200 200))
child-bounds (rect->bounds (grc/make-rect 0 0 40 30))
objects {(:id frame) frame (:id child) child}
lines (fld/init-layout-lines frame [[child-bounds child]] bounds
{(:id frame) bounds (:id child) child-bounds} objects false)]
(t/is (= 1 (count lines)))
(t/is (= 1 (:num-children (first lines)))))))