manim icon indicating copy to clipboard operation
manim copied to clipboard

VMobject has a lot of methods+attributes, decrease the number?

Open kolibril13 opened this issue 4 years ago • 8 comments

At the moment, VMobject has 319 methods+attributes. Most of them are quite useful, but what do you think about getting rid of some of them?

from manim import *
x = VMobject()
attrs_with_value = {attr: getattr(x, attr) for attr in dir(x)}
my_attrs = list(attrs_with_value.keys())
for i, obj in enumerate(my_attrs):
    print(i, obj)

0 Match_y (the capital letter is fixed in a current pr of mine) 1 abstractmethods 2 add 3 class 4 deepcopy 5 delattr 6 dict 7 dir 8 doc 9 eq 10 format 11 ge 12 getattr 13 getattribute 14 getitem 15 gt 16 hash 17 iadd 18 init 19 init_subclass 20 isub 21 iter 22 le 23 len 24 lt 25 module 26 ne 27 new 28 reduce 29 reduce_ex 30 repr 31 setattr 32 sizeof 33 slots 34 str 35 sub 36 subclasshook 37 weakref 38 _abc_impl 39 _gen_subpaths_from_points 40 add 41 add_background_rectangle 42 add_background_rectangle_to_family_members_with_points 43 add_background_rectangle_to_submobjects 44 add_cubic_bezier_curve 45 add_cubic_bezier_curve_to 46 add_line_to 47 add_n_more_submobjects 48 add_points_as_corners 49 add_quadratic_bezier_curve_to 50 add_smooth_curve_to 51 add_subpath 52 add_to_back 53 add_updater 54 align_data 55 align_on_border 56 align_points 57 align_points_with_larger 58 align_rgbas 59 align_submobjects 60 align_to 61 animate 62 append_points 63 append_vectorized_mobject 64 apply_complex_function 65 apply_function 66 apply_function_to_position 67 apply_function_to_submobject_positions 68 apply_matrix 69 apply_over_attr_arrays 70 apply_points_function 71 apply_points_function_about_point 72 apply_to_family 73 arrange 74 arrange_in_grid 75 arrange_submobjects 76 background_image_file 77 background_stroke_color 78 background_stroke_opacity 79 background_stroke_rgbas 80 background_stroke_width 81 become 82 center 83 change_anchor_mode 84 clear_points 85 clear_updaters 86 close_new_points 87 color 88 color_using_background_image 89 compute_bounding_box 90 consider_points_equals 91 consider_points_equals_2d 92 copy 93 data 94 depth 95 depth_test 96 dim 97 fade 98 fade_to 99 family 100 family_members_with_points 101 fill_color 102 fill_opacity 103 fill_rgbas 104 flip 105 force_direction 106 gen_cubic_bezier_tuples_from_points 107 gen_subpaths_from_points_2d 108 generate_points 109 generate_rgbas_array 110 generate_target 111 get_all_points 112 get_anchors 113 get_anchors_and_handles 114 get_arc_length 115 get_array_attrs 116 get_background_image_file 117 get_bottom 118 get_boundary_point 119 get_bounding_box 120 get_center 121 get_center_of_mass 122 get_color 123 get_coord 124 get_corner 125 get_critical_point 126 get_cubic_bezier_tuples 127 get_cubic_bezier_tuples_from_points 128 get_curve_functions 129 get_curve_functions_with_lengths 130 get_direction 131 get_edge_center 132 get_end 133 get_end_anchors 134 get_extremum_along_dim 135 get_family 136 get_family_updaters 137 get_fill_color 138 get_fill_colors 139 get_fill_opacities 140 get_fill_opacity 141 get_fill_rgbas 142 get_gradient_start_and_end_points 143 get_group_class 144 get_image 145 get_last_point 146 get_left 147 get_merged_array 148 get_nadir 149 get_nth_curve_function 150 get_nth_curve_function_with_length 151 get_nth_curve_points 152 get_num_curves 153 get_num_points 154 get_pieces 155 get_point_mobject 156 get_points 157 get_points_defining_boundary 158 get_right 159 get_sheen_direction 160 get_sheen_factor 161 get_start 162 get_start_anchors 163 get_start_and_end 164 get_stroke_color 165 get_stroke_colors 166 get_stroke_opacities 167 get_stroke_opacity 168 get_stroke_rgbas 169 get_stroke_width 170 get_style 171 get_subcurve 172 get_subpaths 173 get_subpaths_from_points 174 get_time_based_updaters 175 get_top 176 get_updaters 177 get_x 178 get_y 179 get_z 180 get_z_index_reference_point 181 get_zenith 182 gloss 183 has_new_path_started 184 has_no_points 185 has_points 186 has_time_based_updater 187 height 188 init_colors 189 init_gl_colors 190 init_gl_data 191 init_gl_points 192 insert_n_curves 193 insert_n_curves_to_point_list 194 interpolate 195 interpolate_color 196 invert 197 is_closed 198 is_fixed_in_frame 199 is_off_screen 200 length_over_dim 201 make_jagged 202 make_smooth 203 make_smooth_after_applying_functions 204 match_background_image_file 205 match_color 206 match_coord 207 match_depth 208 match_dim_size 209 match_height 210 match_style 211 match_updaters 212 match_width 213 match_x 214 match_z 215 move_to 216 n_points_per_cubic_curve 217 name 218 needs_new_bounding_box 219 next_to 220 nonempty_submobjects 221 null_point_align 222 parents 223 point_from_proportion 224 point_hash 225 points 226 pointwise_become_partial 227 pose_at_angle 228 pre_function_handle_to_anchor_scale_factor 229 push_self_into_submobjects 230 put_start_and_end_on 231 reduce_across_dimension 232 refresh_bounding_box 233 remove 234 remove_updater 235 repeat 236 repeat_submobject 237 replace 238 rescale_to_fit 239 reset_points 240 restore 241 resume_updating 242 reverse_direction 243 reverse_points 244 rotate 245 rotate_about_origin 246 rotate_in_place 247 save_image 248 save_state 249 scale 250 scale_about_point 251 scale_handle_to_anchor_distances 252 scale_in_place 253 scale_to_fit_depth 254 scale_to_fit_height 255 scale_to_fit_width 256 set 257 set_anchors_and_handles 258 set_background_stroke 259 set_color 260 set_color_by_gradient 261 set_colors_by_radial_gradient 262 set_coord 263 set_fill 264 set_opacity 265 set_points 266 set_points_as_corners 267 set_points_smoothly 268 set_shade_in_3d 269 set_sheen 270 set_sheen_direction 271 set_stroke 272 set_style 273 set_submobject_colors_by_gradient 274 set_submobject_colors_by_radial_gradient 275 set_x 276 set_y 277 set_z 278 set_z_index 279 set_z_index_by_z_coordinate 280 shade_in_3d 281 shadow 282 sheen_direction 283 sheen_factor 284 shift 285 shift_onto_screen 286 show 287 shuffle 288 shuffle_submobjects 289 sort 290 sort_submobjects 291 space_out_submobjects 292 split 293 start_new_path 294 stretch 295 stretch_about_point 296 stretch_in_place 297 stretch_to_fit_depth 298 stretch_to_fit_height 299 stretch_to_fit_width 300 stroke_color 301 stroke_opacity 302 stroke_rgbas 303 stroke_width 304 submobjects 305 surround 306 suspend_updating 307 target 308 throw_error_if_no_points 309 to_corner 310 to_edge 311 to_original_color 312 tolerance_for_point_equality 313 update 314 update_rgbas_array 315 updaters 316 updating_suspended 317 wag 318 width 319 z_index

kolibril13 avatar Apr 10 '21 07:04 kolibril13

I strongly agree with this.

Given that the vast majority of the methods that handle bezier curve logic only use one attribute of VMobject (points), it would make sense to move them elsewhere, by either creating a class BezierCurvesHandler (not sure about the name) and/or simply using "static" functions.

huguesdevimeux avatar Apr 10 '21 09:04 huguesdevimeux

Also we could make the helper methods "private". That way they also don't get added to the docs. ...btw, this way it is easier to enumerate attributes :upside_down_face:

for i, attr in enumerate(dir(VMobject())):
    print(i, attr)

AntonBallmaier avatar May 16 '21 00:05 AntonBallmaier

There's an issue here that both of your code snippets are picking up methods from Mobject (and methods that aren't explicitly defined, and just normal attributes), but yes, VMobject still has a lot of methods.

As for making methods not appear in the docs, I'm not a total fan of that. First of all it's still useful for developers to have things in the docs only intentionally meant for them, but also I feel like going out of the way to make methods private might end with making methods that are useful for internals private even though they could still be useful for users/it's not bad for users to be using them. Making stuff private should be done sparingly imo

friedkeenan avatar May 16 '21 02:05 friedkeenan

There was also recently the idea to have two documentations: A) user-docs. B) dev-docs

kolibril13 avatar May 16 '21 09:05 kolibril13

...dev-docs including all pages and private methods?

AntonBallmaier avatar May 16 '21 15:05 AntonBallmaier

Yes. And user docs only methods that are in the user interface.

kolibril13 avatar May 16 '21 15:05 kolibril13

I don't think it would be very practical to have yet another source of Information. Developers can read the docstrings of private methods anyways, I don't see a real benefit in having that rendered somewhere.

behackl avatar May 16 '21 15:05 behackl

okay, good point!

kolibril13 avatar May 16 '21 16:05 kolibril13