@@ -1522,8 +1522,28 @@ impl Graphics {
15221522 . map_err ( |e| PyRuntimeError :: new_err ( format ! ( "{e}" ) ) )
15231523 }
15241524
1525- pub fn line ( & self , x1 : f32 , y1 : f32 , x2 : f32 , y2 : f32 ) -> PyResult < ( ) > {
1526- graphics_record_command ( self . entity , DrawCommand :: Line { x1, y1, x2, y2 } )
1525+ /// `line(x1, y1, x2, y2)`, or in 3D `line(x1, y1, z1, x2, y2, z2)`.
1526+ #[ pyo3( signature = ( x1, y1, x2, y2, * args) ) ]
1527+ pub fn line (
1528+ & self ,
1529+ x1 : f32 ,
1530+ y1 : f32 ,
1531+ x2 : f32 ,
1532+ y2 : f32 ,
1533+ args : & Bound < ' _ , PyTuple > ,
1534+ ) -> PyResult < ( ) > {
1535+ let rest: Vec < f32 > = args. extract ( ) ?;
1536+ let ( from, to) = match rest[ ..] {
1537+ [ ] => ( Vec3 :: new ( x1, y1, 0.0 ) , Vec3 :: new ( x2, y2, 0.0 ) ) ,
1538+ // six numbers read as two points
1539+ [ a, b] => ( Vec3 :: new ( x1, y1, x2) , Vec3 :: new ( y2, a, b) ) ,
1540+ _ => {
1541+ return Err ( pyo3:: exceptions:: PyTypeError :: new_err (
1542+ "line() takes 4 numbers, or 6 in 3D" ,
1543+ ) ) ;
1544+ }
1545+ } ;
1546+ graphics_record_command ( self . entity , DrawCommand :: Line { from, to } )
15271547 . map_err ( |e| PyRuntimeError :: new_err ( format ! ( "{e}" ) ) )
15281548 }
15291549
@@ -1569,9 +1589,15 @@ impl Graphics {
15691589 . map_err ( |e| PyRuntimeError :: new_err ( format ! ( "{e}" ) ) )
15701590 }
15711591
1572- pub fn point ( & self , x : f32 , y : f32 ) -> PyResult < ( ) > {
1573- graphics_record_command ( self . entity , DrawCommand :: Point { x, y } )
1574- . map_err ( |e| PyRuntimeError :: new_err ( format ! ( "{e}" ) ) )
1592+ #[ pyo3( signature = ( x, y, z=0.0 ) ) ]
1593+ pub fn point ( & self , x : f32 , y : f32 , z : f32 ) -> PyResult < ( ) > {
1594+ graphics_record_command (
1595+ self . entity ,
1596+ DrawCommand :: Point {
1597+ at : Vec3 :: new ( x, y, z) ,
1598+ } ,
1599+ )
1600+ . map_err ( |e| PyRuntimeError :: new_err ( format ! ( "{e}" ) ) )
15751601 }
15761602
15771603 pub fn square ( & self , x : f32 , y : f32 , s : f32 ) -> PyResult < ( ) > {
@@ -1710,6 +1736,22 @@ impl Graphics {
17101736 . map_err ( |e| PyRuntimeError :: new_err ( format ! ( "{e}" ) ) )
17111737 }
17121738
1739+ /// Changes a renderer setting (Processing `hint`).
1740+ pub fn hint ( & self , which : & str ) -> PyResult < ( ) > {
1741+ use processing:: prelude:: constants as consts;
1742+ let perspective = match ( ) {
1743+ _ if which. eq_ignore_ascii_case ( consts:: ENABLE_STROKE_PERSPECTIVE ) => true ,
1744+ _ if which. eq_ignore_ascii_case ( consts:: DISABLE_STROKE_PERSPECTIVE ) => false ,
1745+ _ => {
1746+ return Err ( PyValueError :: new_err ( format ! (
1747+ "unsupported hint: {which:?}"
1748+ ) ) ) ;
1749+ }
1750+ } ;
1751+ graphics_record_command ( self . entity , DrawCommand :: StrokePerspective ( perspective) )
1752+ . map_err ( |e| PyRuntimeError :: new_err ( format ! ( "{e}" ) ) )
1753+ }
1754+
17131755 /// `IMAGE` reads `vertex()` texture coordinates in pixels of the texture, `NORMAL` from 0 to 1.
17141756 pub fn texture_mode ( & self , mode : & str ) -> PyResult < ( ) > {
17151757 let mode = processing:: prelude:: TextureMode :: parse ( mode)
0 commit comments