1 ! Copyright (C) 2010 Erik Charlebois.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors kernel locals math math.order math.polynomials
4 math.splines opengl.gl sequences ui.gadgets ui.gadgets.panes ui.render
6 IN: math.splines.viewer
9 : eval-polynomials ( polynomials-seq n -- xy-sequence )
12 /f swap [ polyval ] with map
17 TUPLE: spline-gadget < gadget polynomials steps spline-dim ;
19 M: spline-gadget pref-dim* spline-dim>> ;
21 M:: spline-gadget draw-gadget* ( gadget -- )
24 gadget [ polynomials>> ] [ steps>> ] bi eval-polynomials :> pts
26 pts [ first ] [ max ] map-reduce :> x-max
27 pts [ first ] [ min ] map-reduce :> x-min
28 pts [ second ] [ max ] map-reduce :> y-max
29 pts [ second ] [ min ] map-reduce :> y-min
32 [ first x-min - x-max x-min - / gadget spline-dim>> first * ]
33 [ second y-min - y-max y-min - / gadget spline-dim>> second * ] bi 2array
38 first2 neg gadget spline-dim>> second + glVertex2f
42 :: <spline-gadget> ( polynomials dim steps -- gadget )
45 polynomials >>polynomials
48 : spline. ( curve dim steps -- )
49 <spline-gadget> gadget. ;