Say what order a terminal index actually follows

The comment on elementTerminals() said the order of Element::terminals()
"also comes from the definition", which reads as file order and is
wrong. Element::parseTerminal() re-sorts the list on every insertion, top
to bottom then left to right on each terminal's local position, so index 0
is the topmost terminal whatever order the .elmt lists them in.

bobine_ka_a_remanence.elmt writes A2 (y=20) before A1 (y=-20) and index 0
is A1. Measured by placing 400 shipped elements and reading the real order
back: a top-to-bottom, left-to-right prediction matched all 400, while
file order matched only the 100 where the two happen to coincide. Of the
837 shipped elements with distinct named terminals, 619 list them in a
different order than QElectroTech indexes them.

Comment only. Two terminals at one point tie and the sort is not stable;
the comment says so.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
ispyisail
2026-09-21 21:57:01 +12:00
parent fc41cf9f5d
commit 528d33792d
2 changed files with 15 additions and 4 deletions
+12 -3
View File
@@ -680,9 +680,18 @@ QString QetScriptApi::elementName(int folioIndex, const QString &elementUuid) co
base, and where it is not, every instance of that same element carries
the same one -- two coils of one type placed side by side have
byte-identical terminal uuids, which is plainly visible in the saved
file of any project written through this API. The order of
Element::terminals() also comes from the definition, but it is at least
unambiguous within the element the caller has already named by uuid.
file of any project written through this API.
The index is the terminal's place in Element::terminals(), and that is
@b not the order the .elmt lists them in. Element::parseTerminal()
re-sorts the list on every insertion, top to bottom and then left to
right on each terminal's local position, so index 0 is the topmost
terminal. bobine_ka_a_remanence.elmt writes A2 (y=20) before A1 (y=-20)
and index 0 is A1. Of the 837 shipped elements whose terminals all have
distinct names, 619 list them in a different order than this. Two
terminals at the same point tie, and the sort is not stable, so which
of those is which is undefined -- read this listing rather than
assuming.
*/
QStringList QetScriptApi::elementTerminals(int folioIndex, const QString &elementUuid) const
{