@@ -9,7 +9,7 @@ use crate::{
99use cxx:: UniquePtr ;
1010use glam:: { dvec2, dvec3, DVec3 } ;
1111use opencascade_sys as ffi;
12- use std:: path:: Path ;
12+ use std:: { path:: Path , pin :: Pin } ;
1313
1414pub struct Shape {
1515 pub ( crate ) inner : UniquePtr < ffi:: topo_ds:: TopoDS_Shape > ,
@@ -762,6 +762,51 @@ impl Shape {
762762 results
763763 }
764764
765+ /// Create a transformed copy of this shape using a `gp_Trsf` configured by `configure`.
766+ fn with_transform ( & self , configure : impl FnOnce ( Pin < & mut ffi:: gp:: gp_Trsf > ) ) -> Self {
767+ let mut transform = ffi:: gp:: new_transform ( ) ;
768+ configure ( transform. pin_mut ( ) ) ;
769+ let mut brep =
770+ ffi:: b_rep_builder_api:: BRepBuilderAPI_Transform_new ( & self . inner , & transform, true ) ;
771+ Self :: from_shape ( brep. pin_mut ( ) . Shape ( ) )
772+ }
773+
774+ /// Create a translated copy of this shape.
775+ #[ must_use]
776+ pub fn translated ( & self , offset : DVec3 ) -> Self {
777+ self . with_transform ( |trsf| {
778+ let translation_vec = make_vec ( offset) ;
779+ trsf. set_translation_vec ( & translation_vec) ;
780+ } )
781+ }
782+
783+ /// Create a rotated copy of this shape about an axis through the origin.
784+ #[ must_use]
785+ pub fn rotated ( & self , axis : DVec3 , angle : f64 ) -> Self {
786+ self . with_transform ( |trsf| {
787+ let axis_1 = make_axis_1 ( DVec3 :: ZERO , axis) ;
788+ trsf. SetRotation ( & axis_1, angle) ;
789+ } )
790+ }
791+
792+ /// Create a scaled copy of this shape about a point.
793+ #[ must_use]
794+ pub fn scaled ( & self , point : DVec3 , factor : f64 ) -> Self {
795+ self . with_transform ( |trsf| {
796+ let pnt = make_point ( point) ;
797+ trsf. SetScale ( & pnt, factor) ;
798+ } )
799+ }
800+
801+ /// Create a mirrored copy of this shape about an axis.
802+ #[ must_use]
803+ pub fn mirrored ( & self , origin : DVec3 , dir : DVec3 ) -> Self {
804+ self . with_transform ( |trsf| {
805+ let axis_1 = make_axis_1 ( origin, dir) ;
806+ trsf. set_mirror_axis ( & axis_1) ;
807+ } )
808+ }
809+
765810 #[ must_use]
766811 pub fn hollow < T : AsRef < Face > > (
767812 & self ,
0 commit comments