@@ -694,12 +694,85 @@ def get_boundbox_lines(self, xmin, xmax, ymin, ymax, zmin, zmax):
694694 ]
695695
696696
697- class Point3DBox (PointBox ):
697+ class Cylinder3DBox (_Graphics3DElement ):
698+ """
699+ Internal Python class used when Boxing a 'Cylinder' object.
700+ """
701+
702+ def init (self , graphics , style , item ):
703+ super (Cylinder3DBox , self ).init (graphics , item , style )
704+
705+ self .edge_color , self .face_color = style .get_style (_Color , face_element = True )
706+
707+ if len (item .leaves ) != 2 :
708+ raise BoxConstructError
709+
710+ points = item .leaves [0 ].to_python ()
711+ if not all (
712+ len (point ) == 3 and all (isinstance (p , numbers .Real ) for p in point )
713+ for point in points
714+ ):
715+ raise BoxConstructError
716+
717+ self .points = [Coords3D (graphics , pos = point ) for point in points ]
718+ self .radius = item .leaves [1 ].to_python ()
719+
720+ def to_asy (self ):
721+ # l = self.style.get_line_width(face_element=True)
722+
723+ if self .face_color is None :
724+ face_color = (1 , 1 , 1 )
725+ else :
726+ face_color = self .face_color .to_js ()
727+
728+ rgb = f"rgb({ face_color [0 ]} , { face_color [1 ]} , { face_color [2 ]} )"
729+ return "" .join (
730+ f"draw(surface(cylinder({ tuple (coord .pos ()[0 ])} , { self .radius } , { self .height } )), { rgb } );"
731+ for coord in self .points
732+ )
733+
734+ def to_json (self ):
735+ face_color = self .face_color
736+ if face_color is not None :
737+ face_color = face_color .to_js ()
738+ return [
739+ {
740+ "type" : "cylinder" ,
741+ "coords" : [coords .pos () for coords in self .points ],
742+ "radius" : self .radius ,
743+ "faceColor" : face_color ,
744+ }
745+ ]
746+
747+ def extent (self ):
748+ result = []
749+ # FIXME: instead of `coords.add(±self.radius, ±self.radius, ±self.radius)` we should do:
750+ # coords.add(transformation_vector.x * ±self.radius, transformation_vector.y * ±self.radius, transformation_vector.z * ±self.radius)
751+ result .extend (
752+ [
753+ coords .add (self .radius , self .radius , self .radius ).pos ()[0 ]
754+ for coords in self .points
755+ ]
756+ )
757+ result .extend (
758+ [
759+ coords .add (- self .radius , - self .radius , - self .radius ).pos ()[0 ]
760+ for coords in self .points
761+ ]
762+ )
763+ return result
764+
765+ def _apply_boxscaling (self , boxscale ):
766+ # TODO
767+ pass
768+
769+
770+ class Line3DBox (LineBox ):
698771 def init (self , * args , ** kwargs ):
699- super (Point3DBox , self ).init (* args , ** kwargs )
772+ super (Line3DBox , self ).init (* args , ** kwargs )
700773
701774 def process_option (self , name , value ):
702- super (Point3DBox , self ).process_option (name , value )
775+ super (Line3DBox , self ).process_option (name , value )
703776
704777 def extent (self ):
705778 result = []
@@ -715,12 +788,12 @@ def _apply_boxscaling(self, boxscale):
715788 coords .scale (boxscale )
716789
717790
718- class Line3DBox ( LineBox ):
791+ class Point3DBox ( PointBox ):
719792 def init (self , * args , ** kwargs ):
720- super (Line3DBox , self ).init (* args , ** kwargs )
793+ super (Point3DBox , self ).init (* args , ** kwargs )
721794
722795 def process_option (self , name , value ):
723- super (Line3DBox , self ).process_option (name , value )
796+ super (Point3DBox , self ).process_option (name , value )
724797
725798 def extent (self ):
726799 result = []
@@ -805,9 +878,10 @@ def _apply_boxscaling(self, boxscale):
805878# FIXME: GLOBALS3D is a horrible name.
806879GLOBALS3D .update (
807880 {
808- "System`Polygon3DBox " : Polygon3DBox ,
881+ "System`Cylinder3DBox " : Cylinder3DBox ,
809882 "System`Line3DBox" : Line3DBox ,
810883 "System`Point3DBox" : Point3DBox ,
884+ "System`Polygon3DBox" : Polygon3DBox ,
811885 "System`Sphere3DBox" : Sphere3DBox ,
812886 }
813887)
0 commit comments