node-red-contrib-polygon 0.0.5

Piecewise linear interpolation with up to 20 XY pairs; robust endpoint extrapolation.

npm install node-red-contrib-polygon

node-red-contrib-polygon

Piecewise linear interpolation Node-RED node with up to 20 (X,Y) breakpoint pairs, optional endpoint extrapolation, and strict monotonic X validation.


📌 English

What this node does

polygon computes an output value from an input (msg.payload) by linearly interpolating between user-defined breakpoints. It supports 20 (X,Y) rows, each with a Use checkbox to activate the pair. Outside the endpoint range, it can extrapolate or clamp—your choice. Settings persist correctly in the editor.

Key features

  • 20 × (Use, X, Y) rows in the edit dialog
  • Strictly increasing X enforced:
    • Editor-side validation blocks saving when used X’s are not strictly increasing.
    • Runtime guard raises alarm if a mismatched flow slips through.
  • Endpoint behavior selectable:
    • Extrapolate (default ON): linear continuation beyond first/last point.
    • Clamp: hold Y at the nearest endpoint.
  • Exact-knot handling: if IN == Xk (within a tiny epsilon), OUT = Yk.
  • One output:
    1. OUT – cloned incoming message with computed msg.payload, plus msg.trbl_al, msg.n_bp, msg.segment
  • Status text indicators for quick debugging (e.g., seg k, extrap, clamped, X order invalid, etc.)

Installation

Install from the Node-RED userDir (usually ~/.node-red, Docker: /data), then restart Node-RED and hard-refresh the editor.

cd ~/.node-red      # or: cd /data (Docker)
npm install /path/to/your/node-red-contrib-polygon
node-red-restart
# In browser: Ctrl+F5 to clear cached editor assets

Configuration & algorithm

Let the active (Use ✓) points be (X1,Y1)
(Xn,Yn), n ≄ 2, with strictly increasing X:

  • If IN is inside: find k with Xk < IN < Xk+1 and compute
    OUT = Yk + (IN − Xk) * (Yk+1 − Yk) / (Xk+1 − Xk)
  • If exactly on a knot IN == Xk (epsilon match): OUT = Yk
  • If IN < X1:
    • Extrapolate ON: use slope of (X1,Y1)–(X2,Y2)
    • Extrapolate OFF: OUT = Y1 (clamp)
  • If IN > Xn:
    • Extrapolate ON: use slope of (Xn−1,Yn−1)–(Xn,Yn)
    • Extrapolate OFF: OUT = Yn (clamp)
  • Faults (alarm true):
    • Not enough points (n < 2)
    • X order invalid (Xk ≄ Xk+1 among used rows)

Outputs

  • Output 1 (OUT): computed value in msg.payload, plus:
    • msg.trbl_al – boolean: parameter fault occurred
    • msg.n_bp – number of active pairs
    • msg.segment – used segment index (-1 if clamped/extrapolated/knot)
  • Output 2 (TRBL_AL): { payload: <boolean> } alarm

Quick test

Set two points and enable extrapolation:

  • Use1: X=0, Y=0
  • Use2: X=10, Y=100
  • Extrapolate: ON

Expected:

  • IN=-5 → OUT=-50 (left extrapolation)
  • IN=0 → OUT=0 (knot)
  • IN=5 → OUT=50 (interpolation)
  • IN=10 → OUT=100 (knot)
  • IN=15 → OUT=150 (right extrapolation)

Troubleshooting

  • Node doesn’t appear in the palette: install from the userDir (~/.node-red or /data), then restart Node-RED and hard-refresh the editor (Ctrl+F5).
  • Keeps clamping instead of extrapolating: ensure the Extrapolate checkbox is ON and X’s are strictly increasing.

🇭đŸ‡ș Magyar

Mit csinĂĄl ez a node?

A polygon a bemeneti msg.payload alapjĂĄn szĂĄmĂ­t kimenetet a törĂ©spontok között lineĂĄris interpolĂĄciĂłval. A szerkesztƑben 20 sor ĂĄll rendelkezĂ©sre (Use, X, Y), a szĂ©lsƑ tartomĂĄnyokon pedig extrapolĂĄl vagy klampel – beĂĄllĂ­tĂĄstĂłl fĂŒggƑen. A beĂĄllĂ­tĂĄsokat helyesen megƑrzi.

FƑ funkciók

  • 20 × (Use, X, Y) sor
  • SzigorĂșan növekvƑ X kikĂ©nyszerĂ­tĂ©se:
    • SzerkesztƑ: a mentĂ©s (Done) nem engedĂ©lyezett, ha a pipĂĄlt sorok X Ă©rtĂ©kei nem szigorĂșan növekvƑk.
    • FutĂĄsidƑ: ha hibĂĄs flow kerĂŒl be, riasztĂĄst ad (TRBL_AL).
  • VĂ©gpont-kezelĂ©s vĂĄlaszthatĂł:
    • ExtrapolĂĄlĂĄs (alapbĂłl BE): lineĂĄris folytatĂĄs az elsƑ/utolsĂł szakasz meredeksĂ©gĂ©vel.
    • KlampelĂ©s: Y az adott vĂ©gpontnĂĄl marad.
  • Pontos csomĂłpont (X-egyezĂ©s): ha IN == Xk, akkor OUT = Yk.
  • Egy kimenet:
    1. OUT – a bejövƑ ĂŒzenet mĂĄsolata szĂĄmĂ­tott msg.payload-dal, plusz msg.trbl_al, msg.n_bp, msg.segment
  • ÁllapotjelzĂ©sek a debughoz (seg k, extrap, clamped, X order invalid, stb.)

Telepítés

TelepĂ­ts a Node-RED userDir-bƑl (jellemzƑen ~/.node-red, Dockerben /data), majd indĂ­tsd Ășjra a Node-RED-et Ă©s frissĂ­tsd a böngĂ©szƑt (Ctrl+F5).

cd ~/.node-red      # vagy: cd /data (Docker)
npm install /ELERESI/UT/node-red-contrib-polygon
node-red-restart
# BöngĂ©szƑ: Ctrl+F5

BeĂĄllĂ­tĂĄs & algoritmus

Legyenek az aktĂ­v (Use ✓) pontok (X1,Y1)
(Xn,Yn), n ≄ 2, szigorĂșan növekvƑ X-szel:

  • Ha IN belĂŒl van: keresĂŒnk k-t, ahol Xk < IN < Xk+1, Ă©s szĂĄmolunk:
    OUT = Yk + (IN − Xk) * (Yk+1 − Yk) / (Xk+1 − Xk)
  • Ha pontosan IN == Xk: OUT = Yk
  • Ha IN < X1:
    • Extrap BE: az (X1,Y1)–(X2,Y2) szakasz meredeksĂ©gĂ©vel
    • Extrap KI: OUT = Y1 (klampel)
  • Ha IN > Xn:
    • Extrap BE: az (Xn−1,Yn−1)–(Xn,Yn) szakasz meredeksĂ©gĂ©vel
    • Extrap KI: OUT = Yn (klampel)
  • HibĂĄk (TRBL_AL = true):
    • KevĂ©s pont (n < 2)
    • X sorrend hibĂĄs (Xk ≄ Xk+1 a hasznĂĄlt sorokban)

Kimenetek

  • 1. kimenet (OUT): szĂĄmĂ­tott msg.payload, tovĂĄbbĂĄ:
    • msg.trbl_al – logikai zĂĄszlĂł hiba esetĂ©n
    • msg.n_bp – hasznĂĄlt pontpĂĄrok szĂĄma
    • msg.segment – a hasznĂĄlt szegmens indexe (-1 klampelĂ©s/extrapolĂĄciĂł/csomĂłpont esetĂ©n)
  • 2. kimenet (TRBL_AL): { payload: <boolean> } jelzƑ

Gyors prĂłba

Két pont, extrapolålås BE:

  • Use1: X=0, Y=0
  • Use2: X=10, Y=100

Vårt értékek:

  • IN=-5 → OUT=-50
  • IN=0 → OUT=0
  • IN=5 → OUT=50
  • IN=10 → OUT=100
  • IN=15 → OUT=150

HibaelhĂĄrĂ­tĂĄs

  • Nem jelenik meg a palettĂĄn: a userDir-bƑl telepĂ­ts (~/.node-red vagy /data), indĂ­ts Ășjra, Ă©s Ctrl+F5.
  • Klampel extrapolĂĄlĂĄs helyett: kapcsold BE az ExtrapolĂĄlĂĄs pipĂĄt Ă©s ellenƑrizd a szigorĂș X-sorrendet.

License

MIT

Node Info

Version: 0.0.5
Updated 2 weeks, 3 days ago
License: MIT
Rating: not yet rated

Categories

Actions

Rate:

Downloads

185 in the last week

Nodes

  • polygon

Keywords

  • node-red
  • interpolation
  • linear
  • breakpoints
  • extrapolation

Maintainers