First implementation of to_bytes/from_bytes for Vector,Point,Box,Polygon,SimplePolygon,Trans,CplxTrans,Text,Path,Edge,EdgePair and variants

This commit is contained in:
Matthias Koefferlein
2026-05-02 23:21:35 +02:00
parent 5ccf6260f1
commit fdaa93d234
28 changed files with 1658 additions and 36 deletions
+2
View File
@@ -41,6 +41,7 @@ class DBBox_TestClass < TestBase
a = RBA::DBox::new( -10, 21, 11, 17 )
assert_equal( a.to_s, "(-10,17;11,21)" )
assert_equal( RBA::DBox::from_s(a.to_s).to_s, a.to_s )
assert_equal( RBA::DBox::from_bytes(a.to_bytes).to_s, a.to_s )
assert_equal( (a*0.5).to_s, "(-5,8.5;5.5,10.5)" )
b = a
@@ -263,6 +264,7 @@ class DBBox_TestClass < TestBase
a = RBA::Box::new( -10, 21, 11, 17 )
assert_equal( a.to_s, "(-10,17;11,21)" )
assert_equal( RBA::Box::from_s(a.to_s).to_s, a.to_s )
assert_equal( RBA::Box::from_bytes(a.to_bytes).to_s, a.to_s )
assert_equal( (a*2).to_s, "(-20,34;22,42)" )
b = a
+6
View File
@@ -40,6 +40,9 @@ class DBEdgePair_TestClass < TestBase
assert_equal(ep.to_s, "(0,0;10,20)/(-10,0;-10,30)")
assert_equal(ep.bbox.to_s, "(-10,0;10,30)")
assert_equal(RBA::EdgePair::from_s(ep.to_s).to_s, ep.to_s)
assert_equal(RBA::EdgePair::from_bytes(ep.to_bytes).to_s, ep.to_s)
assert_equal(RBA::EdgePair::new(ep.first, ep.second).to_s, "(0,0;10,20)/(-10,0;-10,30)")
ep2 = RBA::EdgePair::new
@@ -91,6 +94,9 @@ class DBEdgePair_TestClass < TestBase
assert_equal(ep.to_s, "(0,0;10,20)/(-10,0;-10,30)")
assert_equal(ep.bbox.to_s, "(-10,0;10,30)")
assert_equal(RBA::DEdgePair::from_s(ep.to_s).to_s, ep.to_s)
assert_equal(RBA::DEdgePair::from_bytes(ep.to_bytes).to_s, ep.to_s)
assert_equal(RBA::DEdgePair::new(ep.first, ep.second).to_s, "(0,0;10,20)/(-10,0;-10,30)")
ep2 = RBA::DEdgePair::new
+2
View File
@@ -36,6 +36,7 @@ class DBEdge_TestClass < TestBase
a = RBA::DEdge::new( -1, 2, 15, -7 )
assert_equal( a.to_s, "(-1,2;15,-7)" )
assert_equal( RBA::DEdge::from_s(a.to_s).to_s, a.to_s )
assert_equal( RBA::DEdge::from_bytes(a.to_bytes).to_s, a.to_s )
assert_equal( (a*0.5).to_s, "(-0.5,1;7.5,-3.5)" )
d = RBA::Edge::new( a )
assert_equal( d.to_s, "(-1,2;15,-7)" )
@@ -156,6 +157,7 @@ class DBEdge_TestClass < TestBase
a = RBA::Edge::new( RBA::Point::new( -1, 2 ), RBA::Point::new( 15, -7 ) )
assert_equal( a.to_s, "(-1,2;15,-7)" )
assert_equal( RBA::Edge::from_s(a.to_s).to_s, a.to_s )
assert_equal( RBA::Edge::from_bytes(a.to_bytes).to_s, a.to_s )
assert_equal( (a*2).to_s, "(-2,4;30,-14)" )
d = RBA::DEdge::new( a )
assert_equal( d.to_s, "(-1,2;15,-7)" )
+6
View File
@@ -33,6 +33,7 @@ class DBPath_TestClass < TestBase
assert_equal( a.area.to_s, "0.0" )
assert_equal( a.length.to_s, "0.0" )
assert_equal( RBA::DPath::from_s(a.to_s).to_s, a.to_s )
assert_equal( RBA::DPath::from_bytes(a.to_bytes).to_s, a.to_s )
b = a.dup
a = RBA::DPath::new( [ RBA::DPoint::new( 0, 1 ), RBA::DPoint::new( 1, 5 ) ], 2.5 )
@@ -40,6 +41,7 @@ class DBPath_TestClass < TestBase
assert_equal( "%.3f" % a.area, "10.308" )
assert_equal( "%.3f" % a.length, "4.123" )
assert_equal( RBA::DPath::from_s(a.to_s).to_s, a.to_s )
assert_equal( RBA::DPath::from_bytes(a.to_bytes).to_s, a.to_s )
c = a.dup
assert_equal( a == b, false )
@@ -55,6 +57,7 @@ class DBPath_TestClass < TestBase
a = RBA::DPath::new( [ RBA::DPoint::new( 0, 1 ), RBA::DPoint::new( 1, 5 ) ], 2.5, -0.5, 1.5 )
assert_equal( a.to_s, "(0,1;1,5) w=2.5 bx=-0.5 ex=1.5 r=false" )
assert_equal( RBA::DPath::from_s(a.to_s).to_s, a.to_s )
assert_equal( RBA::DPath::from_bytes(a.to_bytes).to_s, a.to_s )
assert_equal( "%.3f" % a.length, "5.123" )
assert_equal( RBA::Path::new(a).to_s, "(0,1;1,5) w=3 bx=-1 ex=2 r=false" )
@@ -122,6 +125,7 @@ class DBPath_TestClass < TestBase
assert_equal( a.area.to_f.to_s, "0.0" )
assert_equal( a.length.to_s, "0" )
assert_equal( RBA::Path::from_s(a.to_s).to_s, a.to_s )
assert_equal( RBA::Path::from_bytes(a.to_bytes).to_s, a.to_s )
b = a.dup
a = RBA::Path::new( [ RBA::Point::new( 0, 10 ), RBA::Point::new( 10, 50 ) ], 25 )
@@ -129,6 +133,7 @@ class DBPath_TestClass < TestBase
assert_equal( a.area.to_f.to_s, "1025.0" )
assert_equal( a.length.to_s, "41" )
assert_equal( RBA::Path::from_s(a.to_s).to_s, a.to_s )
assert_equal( RBA::Path::from_bytes(a.to_bytes).to_s, a.to_s )
c = a.dup
assert_equal( a == b, false )
@@ -144,6 +149,7 @@ class DBPath_TestClass < TestBase
assert_equal( a.to_s, "(0,10;10,50) w=25 bx=-5 ex=15 r=false" )
assert_equal( a.length.to_s, "51" )
assert_equal( RBA::Path::from_s(a.to_s).to_s, a.to_s )
assert_equal( RBA::Path::from_bytes(a.to_bytes).to_s, a.to_s )
assert_equal( RBA::DPath::new(a).to_s, "(0,10;10,50) w=25 bx=-5 ex=15 r=false" )
a.bgn_ext = 5
+2
View File
@@ -34,6 +34,7 @@ class DBPoint_TestClass < TestBase
assert_equal( a.to_s, "1,-17" )
assert_equal( RBA::DPoint::from_s(a.to_s).to_s, a.to_s )
assert_equal( RBA::DPoint::from_bytes(a.to_bytes).to_s, a.to_s )
assert_equal( (-a).to_s, "-1,17" )
assert_equal( b.to_s, "0,0" )
assert_equal( c.to_s, "5,11" )
@@ -84,6 +85,7 @@ class DBPoint_TestClass < TestBase
assert_equal( a.to_s, "1,-17" )
assert_equal( RBA::Point::from_s(a.to_s).to_s, a.to_s )
assert_equal( RBA::Point::from_bytes(a.to_bytes).to_s, a.to_s )
assert_equal( (-a).to_s, "-1,17" )
assert_equal( b.to_s, "0,0" )
assert_equal( c.to_s, "5,11" )
+6
View File
@@ -31,6 +31,7 @@ class DBPolygon_TestClass < TestBase
a = RBA::DPolygon::new
assert_equal( a.to_s, "()" )
assert_equal( RBA::DPolygon::from_s(a.to_s).to_s, a.to_s )
assert_equal( RBA::DPolygon::from_bytes(a.to_bytes).to_s, a.to_s )
assert_equal( a.is_box?, false )
assert_equal( a.is_empty?, true )
assert_equal( a.is_rectilinear?, false )
@@ -41,6 +42,7 @@ class DBPolygon_TestClass < TestBase
assert_equal( a.to_s, "(0,1;1,5;5,5)" )
assert_equal( (a * 2).to_s, "(0,2;2,10;10,10)" )
assert_equal( RBA::DPolygon::from_s(a.to_s).to_s, a.to_s )
assert_equal( RBA::DPolygon::from_bytes(a.to_bytes).to_s, a.to_s )
assert_equal( a.is_box?, false )
assert_equal( a.num_points_hull, 3 )
assert_equal( a.is_empty?, false )
@@ -101,6 +103,7 @@ class DBPolygon_TestClass < TestBase
a.insert_hole( [ RBA::DPoint::new( 1, 2 ), RBA::DPoint::new( 2, 2 ), RBA::DPoint::new( 2, 6 ) ] )
assert_equal( a.to_s, "(0,1;1,5;1,1/1,2;2,2;2,6)" )
assert_equal( RBA::DPolygon::from_s(a.to_s).to_s, a.to_s )
assert_equal( RBA::DPolygon::from_bytes(a.to_bytes).to_s, a.to_s )
assert_equal( a.area, 0 )
assert_equal( a.num_points_hole(0), 3 )
assert_equal( a.holes, 1 )
@@ -172,6 +175,7 @@ class DBPolygon_TestClass < TestBase
a = RBA::Polygon::new
assert_equal( a.to_s, "()" )
assert_equal( RBA::Polygon::from_s(a.to_s).to_s, a.to_s )
assert_equal( RBA::Polygon::from_bytes(a.to_bytes).to_s, a.to_s )
assert_equal( a.is_box?, false )
b = a.dup
@@ -179,6 +183,7 @@ class DBPolygon_TestClass < TestBase
assert_equal( a.to_s, "(0,1;1,5;5,5)" )
assert_equal( (a * 2).to_s, "(0,2;2,10;10,10)" )
assert_equal( RBA::Polygon::from_s(a.to_s).to_s, a.to_s )
assert_equal( RBA::Polygon::from_bytes(a.to_bytes).to_s, a.to_s )
assert_equal( a.num_points_hull, 3 )
c = a.dup
@@ -226,6 +231,7 @@ class DBPolygon_TestClass < TestBase
a.insert_hole( [ RBA::Point::new( 1, 2 ), RBA::Point::new( 2, 2 ), RBA::Point::new( 2, 6 ) ] )
assert_equal( a.to_s, "(0,1;1,5;1,1/1,2;2,2;2,6)" )
assert_equal( RBA::Polygon::from_s(a.to_s).to_s, a.to_s )
assert_equal( RBA::Polygon::from_bytes(a.to_bytes).to_s, a.to_s )
assert_equal( a.area, 0 )
assert_equal( a.num_points_hole(0), 3 )
assert_equal( a.holes, 1 )
+4
View File
@@ -30,10 +30,12 @@ class DBText_TestClass < TestBase
a = RBA::DText::new( "hallo", 10.0, -15.0 )
assert_equal( RBA::DText::from_s(a.to_s).to_s, a.to_s )
assert_equal( RBA::DText::from_bytes(a.to_bytes).to_s, a.to_s )
assert_equal( a.to_s, "('hallo',r0 10,-15)" )
a = RBA::DText::new( RBA::Text::new( "itext", RBA::Trans::new( RBA::Trans::R270, RBA::Point::new( 100, -150 ))))
assert_equal( RBA::DText::from_s(a.to_s).to_s, a.to_s )
assert_equal( RBA::DText::from_bytes(a.to_bytes).to_s, a.to_s )
assert_equal( a.to_s, "('itext',r270 100,-150)" )
a = RBA::DText::new
@@ -124,6 +126,7 @@ class DBText_TestClass < TestBase
a = RBA::Text::new( "hallo", 10, -15 )
assert_equal( RBA::Text::from_s(a.to_s).to_s, a.to_s )
assert_equal( RBA::Text::from_bytes(a.to_bytes).to_s, a.to_s )
assert_equal( a.to_s, "('hallo',r0 10,-15)" )
a = RBA::Text::new( RBA::DText::new( "dtext", RBA::DTrans::new( RBA::DTrans::R270, RBA::DPoint::new( 100.0, -150.0 ))))
@@ -136,6 +139,7 @@ class DBText_TestClass < TestBase
a = RBA::Text::new( "hallo", RBA::Trans::new( RBA::Trans::R90, RBA::Point::new( 10, -15 )))
assert_equal( a.to_s, "('hallo',r90 10,-15)" )
assert_equal( RBA::Text::from_s(a.to_s).to_s, a.to_s )
assert_equal( RBA::Text::from_bytes(a.to_bytes).to_s, a.to_s )
c = a.dup
assert_equal( a == b, false )
+9
View File
@@ -38,6 +38,7 @@ class DBTrans_TestClass < TestBase
assert_equal( a.to_s, "r0 0,0" )
assert_equal( RBA::DTrans::from_s(a.to_s).to_s, a.to_s )
assert_equal( RBA::DTrans::from_bytes(a.to_bytes).to_s, a.to_s )
assert_equal( b.to_s, "m135 17,5" )
assert_equal( c.to_s, "m135 17,5" )
assert_equal( d.to_s, "r0 17,5" )
@@ -47,6 +48,7 @@ class DBTrans_TestClass < TestBase
assert_equal( RBA::DTrans::new( RBA::Trans::M135, RBA::DPoint::new( 1.2, 0.25 )).to_itype(0.001).to_s, "m135 1200,250" )
assert_equal( RBA::Trans::new( RBA::Trans::M135, RBA::Point::new( 1200, 250 )).to_dtype(0.001).to_s, "m135 1.2,0.25" )
assert_equal( RBA::DTrans::from_s(f.to_s).to_s, f.to_s )
assert_equal( RBA::DTrans::from_bytes(f.to_bytes).to_s, f.to_s )
assert_equal( b.trans( RBA::DPoint::new( 1, 0 )).to_s, "17,4" )
@@ -139,6 +141,7 @@ class DBTrans_TestClass < TestBase
assert_equal( i.to_s, "m135 *0.5 2.5,8.5" )
assert_equal( RBA::DCplxTrans::from_s(i.to_s).to_s, i.to_s )
assert_equal( RBA::DCplxTrans::from_bytes(i.to_bytes).to_s, i.to_s )
assert_equal( i * mb == u, true )
assert_equal( mb * i == u, true )
@@ -244,6 +247,7 @@ class DBTrans_TestClass < TestBase
assert_equal( a.to_s, "r0 0,0" )
assert_equal( RBA::Trans::from_s(a.to_s).to_s, a.to_s )
assert_equal( RBA::Trans::from_bytes(a.to_bytes).to_s, a.to_s )
assert_equal( b.to_s, "m135 17,5" )
assert_equal( c.to_s, "m135 17,5" )
assert_equal( d.to_s, "r0 17,5" )
@@ -251,6 +255,7 @@ class DBTrans_TestClass < TestBase
assert_equal( e2.to_s, "m135 0,0" )
assert_equal( f.to_s, "m135 17,5" )
assert_equal( RBA::Trans::from_s(f.to_s).to_s, f.to_s )
assert_equal( RBA::Trans::from_bytes(f.to_bytes).to_s, f.to_s )
assert_equal( b.trans( RBA::Point::new( 1, 0 )).to_s, "17,4" )
@@ -340,6 +345,7 @@ class DBTrans_TestClass < TestBase
c = RBA::CplxTrans::new( 5, -7 )
assert_equal( c.to_s, "r0 *1 5,-7" )
assert_equal( RBA::CplxTrans::from_s(c.to_s).to_s, c.to_s )
assert_equal( RBA::CplxTrans::from_bytes(c.to_bytes).to_s, c.to_s )
c = RBA::CplxTrans::new( RBA::CplxTrans::M135 )
assert_equal( c.to_s, "m135 *1 0,0" )
@@ -367,6 +373,7 @@ class DBTrans_TestClass < TestBase
c = RBA::CplxTrans::new( 0.75, 45, true, 2.5, -12.5 )
assert_equal( c.to_s, "m22.5 *0.75 2.5,-12.5" )
assert_equal( RBA::CplxTrans::from_s(c.to_s).to_s, c.to_s )
assert_equal( RBA::CplxTrans::from_bytes(c.to_bytes).to_s, c.to_s )
c = RBA::CplxTrans::new( 0.75, 45, true, RBA::DPoint::new( 2.5, -12.5 ) )
assert_equal( c.to_s, "m22.5 *0.75 2.5,-12.5" )
assert_equal( c.is_unity?, false )
@@ -436,6 +443,7 @@ class DBTrans_TestClass < TestBase
assert_equal( m.to_s, "r0 *1.1 0,0" )
assert_equal( RBA::DCplxTrans::from_s(m.to_s).to_s, m.to_s )
assert_equal( RBA::DCplxTrans::from_bytes(m.to_bytes).to_s, m.to_s )
assert_equal( m.trans( RBA::Point::new( 5, -7 )).to_s, "5.5,-7.7" )
im = RBA::ICplxTrans::new( a, 0.5 )
@@ -443,6 +451,7 @@ class DBTrans_TestClass < TestBase
assert_equal( im.to_s, "r0 *0.5 0,0" )
assert_equal( RBA::ICplxTrans::from_s(im.to_s).to_s, im.to_s )
assert_equal( RBA::ICplxTrans::from_bytes(im.to_bytes).to_s, im.to_s )
assert_equal( im.trans( RBA::Point::new( 5, -7 )).to_s, "3,-4" )
im = RBA::ICplxTrans::new(m)
+2
View File
@@ -34,6 +34,7 @@ class DBVector_TestClass < TestBase
assert_equal( a.to_s, "1,-17" )
assert_equal( RBA::DVector::from_s(a.to_s).to_s, a.to_s )
assert_equal( RBA::DVector::from_bytes(a.to_bytes).to_s, a.to_s )
assert_equal( (-a).to_s, "-1,17" )
assert_equal( b.to_s, "0,0" )
assert_equal( c.to_s, "5,11" )
@@ -88,6 +89,7 @@ class DBVector_TestClass < TestBase
assert_equal( a.to_s, "1,-17" )
assert_equal( RBA::Vector::from_s(a.to_s).to_s, a.to_s )
assert_equal( RBA::Vector::from_bytes(a.to_bytes).to_s, a.to_s )
assert_equal( (-a).to_s, "-1,17" )
assert_equal( b.to_s, "0,0" )
assert_equal( c.to_s, "5,11" )