From 18ae4f7bd786bfc4a777ef0af0f6788b73ed36d8 Mon Sep 17 00:00:00 2001 From: Benign X <1341398182@qq.com> Date: Wed, 13 Nov 2024 00:57:51 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=9B=A0=EF=B8=8F(CommonVecOp):=20add=20pus?= =?UTF-8?q?h=20and=20pop=20transformation=20commands?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added `CommonOpPushTrans` and `CommonOpPopTrans` to manage a stack of local transformations. These commands allow pushing a new 3x3 transformation matrix onto the stack and popping the most recent one, respectively. The `GenerateCtx` struct now includes a `local_trans` field to store these matrices. Signed-off-by: Benign X <1341398182@qq.com> --- src/common_vec_op/gen.rs | 62 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/src/common_vec_op/gen.rs b/src/common_vec_op/gen.rs index 4f329d7..f22a3c4 100644 --- a/src/common_vec_op/gen.rs +++ b/src/common_vec_op/gen.rs @@ -59,6 +59,7 @@ impl IVisData for VecLineData { struct GenerateCtx { grouping: bool, cursor: PlotPoint, + local_trans: Vec<[[f64; 3]; 3]>, } #[derive(Debug, Clone)] @@ -81,6 +82,7 @@ impl IVisDataGenerator for VecLineGen { let mut gen_ctx = AnyData::new(GenerateCtx { grouping: false, cursor: PlotPoint::new(0.0, 0.0), + local_trans: vec![], }); let mut points_total = vec![]; let mut points: Vec> = vec![]; @@ -148,6 +150,10 @@ struct CommonOpCUBI; struct CommonOpEND; +struct CommonOpPushTrans; + +struct CommonOpPopTrans; + impl ICommandDescription for CommonOpMOVE { fn name(&self) -> Vec<&str> { ["MOVE"].into() @@ -273,6 +279,60 @@ impl ICommandDescription for CommonOpCUBI { } } +impl ICommandDescription for CommonOpPushTrans { + fn name(&self) -> Vec<&str> { + ["PUSH_TRANS"].into() + } + + fn argc(&self) -> usize { + 9 + } + + fn operate(&self, ctx: &mut AnyData, argv: Rc>) -> Vec { + let ctx = ctx.cast_mut::(); + let trans_matrix: [[f64; 3]; 3] = [ + [ + *argv[0].cast_ref(), + *argv[1].cast_ref(), + *argv[2].cast_ref(), + ], + [ + *argv[3].cast_ref(), + *argv[4].cast_ref(), + *argv[5].cast_ref(), + ], + [ + *argv[6].cast_ref(), + *argv[7].cast_ref(), + *argv[8].cast_ref(), + ], + ]; + + ctx.local_trans.push(trans_matrix); + + vec![] + } +} + +impl ICommandDescription for CommonOpPopTrans { + fn name(&self) -> Vec<&str> { + ["POP_TRANS"].into() + } + + fn argc(&self) -> usize { + 0 + } + + fn operate(&self, ctx: &mut AnyData, _argv: Rc>) -> Vec { + let ctx = ctx.cast_mut::(); + if ctx.local_trans.is_empty() { + return vec![]; + } + ctx.local_trans.pop(); + vec![] + } +} + impl ICommandDescription for CommonOpEND { fn name(&self) -> Vec<&str> { ["END", "CLOSE"].into() @@ -299,6 +359,8 @@ impl ICommandSyntax for CommonVecOpSyntax { &CommonOpQUAD {}, &CommonOpCUBI {}, &CommonOpEND {}, + &CommonOpPushTrans {}, + &CommonOpPopTrans {}, ] } }