use ruststep::{ ast::DataSection, tables::{EntityTable, Holder}, }; use std::{ f64::consts::PI, fmt::{Debug, Display}, str::FromStr, }; use truck::*; use truck_geometry::prelude as truck; use truck_polymesh::PolylineCurve; use truck_stepio::{out::*, r#in::*}; fn oitest(t: Truck) where StepHolder: Holder, Truck: for<'a> From<&'a StepHolder::Owned> + Debug + PartialEq, for<'a> StepDisplay<&'a Truck>: Display, Table: EntityTable, { let step_display = StepDisplay::new(&t, 1); let step = format!("DATA;\n{step_display}ENDSEC;"); println!("{step}"); itest::(t, &step); } fn oitest_tryfrom(t: Truck) where StepHolder: Holder
, Truck: for<'a> TryFrom<&'a StepHolder::Owned> + Debug + PartialEq, for<'a> >::Error: Debug, for<'a> StepDisplay<&'a Truck>: Display, Table: EntityTable, { let step_display = StepDisplay::new(&t, 1); let step = format!("DATA;\n{step_display}ENDSEC;"); println!("{step}"); itest_tryfrom::(t, &step); } fn itest(t: Truck, step: &str) where Truck: for<'a> From<&'a StepHolder::Owned> + Debug + PartialEq, StepHolder: Holder
, Table: EntityTable, { let data_section = DataSection::from_str(step).unwrap(); let table = Table::from_data_section(&data_section); let step_data: StepHolder::Owned = EntityTable::get_owned(&table, 1).unwrap(); let got = Truck::from(&step_data); assert_eq!(t, got); } fn itest_tryfrom(t: Truck, step: &str) where Truck: for<'a> TryFrom<&'a StepHolder::Owned> + Debug + PartialEq, for<'a> >::Error: Debug, StepHolder: Holder
, Table: EntityTable, { let data_section = DataSection::from_str(step).unwrap(); let table = Table::from_data_section(&data_section); let step_data: StepHolder::Owned = EntityTable::get_owned(&table, 1).unwrap(); let got = Truck::try_from(&step_data).unwrap(); assert_eq!(t, got); } #[test] fn oi() { oitest::(Point2::new(1.0, 2.0)); oitest::(Point3::new(1.0, 2.0, 3.0)); oitest::(Vector2::new(1.0, 2.0)); oitest::(Vector3::new(1.0, 2.0, 3.0)); oitest::, LineHolder>(truck::Line( Point2::new(0.0, 1.0), Point2::new(2.0, 3.0), )); oitest::, PolylineHolder>(PolylineCurve(vec![ Point2::origin(), Point2::new(1.0, 2.0), Point2::new(3.0, 4.0), ])); oitest_tryfrom::, BSplineCurveWithKnotsHolder>(BSplineCurve::new( KnotVec::uniform_knot(3, 4), vec![ Point2::new(1.0, 2.0), Point2::new(3.0, 4.0), Point2::new(5.0, 6.0), Point2::new(7.0, 8.0), Point2::new(9.0, 10.0), Point2::new(11.0, 12.0), Point2::new(13.0, 14.0), Point2::new(15.0, 16.0), ], )); itest_tryfrom::, BezierCurveHolder>( BSplineCurve::new( KnotVec::bezier_knot(2), vec![ Point2::new(0.0, 1.0), Point2::new(2.0, 3.0), Point2::new(4.0, 5.0), ], ), "DATA; #1 = BEZIER_CURVE('', 2, (#2, #3, #4), .UNSPECIFIED., .U., .U.); #2 = CARTESIAN_POINT('', (0.0, 1.0)); #3 = CARTESIAN_POINT('', (2.0, 3.0)); #4 = CARTESIAN_POINT('', (4.0, 5.0)); ENDSEC;", ); itest_tryfrom::, QuasiUniformCurveHolder>( BSplineCurve::new( KnotVec::from(vec![0.0, 0.0, 0.0, 1.0, 2.0, 2.0, 2.0]), vec![ Point2::new(0.0, 1.0), Point2::new(2.0, 3.0), Point2::new(4.0, 5.0), Point2::new(6.0, 7.0), ], ), "DATA; #1 = QUASI_UNIFORM_CURVE('', 2, (#2, #3, #4, #5), .UNSPECIFIED., .U., .U.); #2 = CARTESIAN_POINT('', (0.0, 1.0)); #3 = CARTESIAN_POINT('', (2.0, 3.0)); #4 = CARTESIAN_POINT('', (4.0, 5.0)); #5 = CARTESIAN_POINT('', (6.0, 7.0)); ENDSEC;", ); oitest_tryfrom::, RationalBSplineCurveHolder>(NurbsCurve::new( BSplineCurve::new( KnotVec::bezier_knot(3), vec![ Vector3::new(0.0, 1.0, 2.0), Vector3::new(3.0, 4.0, 5.0), Vector3::new(6.0, 7.0, 8.0), ], ), )); oitest_tryfrom::, CircleHolder>( Processor::new(TrimmedCurve::new(UnitCircle::new(), (0.0, 2.0 * PI))).transformed( Matrix3::from_cols( Vector3::new(0.0, 3.0, 0.0), Vector3::new(-3.0, 0.0, 0.0), Vector3::new(1.0, 2.0, 1.0), ), ), ); oitest_tryfrom::, EllipseHolder>( Processor::new(TrimmedCurve::new(UnitCircle::new(), (0.0, 2.0 * PI))).transformed( Matrix3::from_cols( Vector3::new(0.0, 3.0, 0.0), Vector3::new(-8.0, 0.0, 0.0), Vector3::new(1.0, 2.0, 1.0), ), ), ); oitest_tryfrom::, CircleHolder>( Processor::new(TrimmedCurve::new(UnitCircle::new(), (0.0, 2.0 * PI))).transformed( Matrix4::from_cols( Vector4::new(0.0, 3.0, 0.0, 0.0), Vector4::new(0.0, 0.0, 3.0, 0.0), Vector4::new(3.0, 0.0, 0.0, 0.0), Vector4::new(1.0, 2.0, 3.0, 1.0), ), ), ); oitest_tryfrom::, EllipseHolder>( Processor::new(TrimmedCurve::new(UnitCircle::new(), (0.0, 2.0 * PI))).transformed( Matrix4::from_cols( Vector4::new(0.0, 3.0, 0.0, 0.0), Vector4::new(0.0, 0.0, 8.0, 0.0), Vector4::new(3.0, 0.0, 0.0, 0.0), Vector4::new(1.0, 2.0, 3.0, 1.0), ), ), ); oitest_tryfrom::, HyperbolaHolder>( Processor::new(TrimmedCurve::new(UnitHyperbola::new(), (-1.0, 1.0))).transformed( Matrix3::from_cols( Vector3::new(0.0, 3.0, 0.0), Vector3::new(-8.0, 0.0, 0.0), Vector3::new(1.0, 2.0, 1.0), ), ), ); oitest_tryfrom::, HyperbolaHolder>( Processor::new(TrimmedCurve::new(UnitHyperbola::new(), (-1.0, 1.0))).transformed( Matrix4::from_cols( Vector4::new(0.0, 3.0, 0.0, 0.0), Vector4::new(0.0, 0.0, 8.0, 0.0), Vector4::new(3.0, 0.0, 0.0, 0.0), Vector4::new(1.0, 2.0, 3.0, 1.0), ), ), ); oitest_tryfrom::, ParabolaHolder>( Processor::new(TrimmedCurve::new(UnitParabola::new(), (-1.0, 1.0))).transformed( Matrix3::from_cols( Vector3::new(0.0, 2.0, 0.0), Vector3::new(-2.0, 0.0, 0.0), Vector3::new(1.0, 2.0, 1.0), ), ), ); oitest_tryfrom::, ParabolaHolder>( Processor::new(TrimmedCurve::new(UnitParabola::new(), (-1.0, 1.0))).transformed( Matrix4::from_cols( Vector4::new(0.0, 3.0, 0.0, 0.0), Vector4::new(0.0, 0.0, 3.0, 0.0), Vector4::new(3.0, 0.0, 0.0, 0.0), Vector4::new(1.0, 2.0, 3.0, 1.0), ), ), ); oitest::(truck::Plane::new( Point3::new(1.0, 2.0, 3.0), // The ISO regulations require that the coordinate axes of the Plane must be vertical; // on the truck side, the axes do not have to be vertical, // so the results will not necessarily match. Point3::new(2.0, 2.0, 3.0), Point3::new(1.0, 3.0, 3.0), )); oitest::, SphericalSurfaceHolder>( Processor::new(alias::Sphere(truck::Sphere::new( Point3::new(0.0, 0.0, 0.0), 15.0, ))) .transformed(Matrix4::from_cols( Vector4::new(0.0, 1.0, 0.0, 0.0), Vector4::new(-1.0, 0.0, 0.0, 0.0), Vector4::new(0.0, 0.0, 1.0, 0.0), Vector4::new(1.0, 2.0, 3.0, 1.0), )), ); oitest::, ToroidalSurfaceHolder>( Processor::new(Torus::new(Point3::new(0.0, 0.0, 0.0), 15.0, 9.0)).transformed( Matrix4::from_cols( Vector4::new(0.0, 1.0, 0.0, 0.0), Vector4::new(-1.0, 0.0, 0.0, 0.0), Vector4::new(0.0, 0.0, 1.0, 0.0), Vector4::new(1.0, 2.0, 3.0, 1.0), ), ), ); oitest_tryfrom::, Box>, PcurveHolder>(PCurve::new( Box::new(alias::Curve2D::Line(Line( Point2::new(0.0, 0.0), Point2::new(1.0, 1.0), ))), Box::new(alias::Surface::ElementarySurface(Box::new( alias::ElementarySurface::Plane(truck::Plane::new( Point3::new(1.0, 2.0, 3.0), Point3::new(1.0, 2.0, 4.0), Point3::new(1.0, 1.0, 3.0), )), ))), )); oitest_tryfrom::, BSplineSurfaceWithKnotsHolder>(BSplineSurface::new( (KnotVec::bezier_knot(3), KnotVec::bezier_knot(2)), vec![ vec![ Point3::new(0.0, 1.0, 2.0), Point3::new(3.0, 4.0, 5.0), Point3::new(6.0, 7.0, 8.0), ], vec![ Point3::new(0.0, 1.0, 2.0), Point3::new(3.0, 4.0, 5.0), Point3::new(6.0, 7.0, 8.0), ], vec![ Point3::new(0.0, 1.0, 2.0), Point3::new(3.0, 4.0, 5.0), Point3::new(6.0, 7.0, 8.0), ], vec![ Point3::new(0.0, 1.0, 2.0), Point3::new(3.0, 4.0, 5.0), Point3::new(6.0, 7.0, 8.0), ], ], )); }