e2D 1.3.10__py3-none-any.whl → 1.3.11__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
e2D/__init__.py CHANGED
@@ -15,7 +15,7 @@ DOUBLE_PI = PI*2
15
15
  #
16
16
 
17
17
  class Vector2D:
18
- round_values_on_print :float= 1.0
18
+ round_values_on_print :int|float= 2
19
19
  def __init__(self:"V2|Vector2D", x:int|float=0.0, y:int|float=0.0) -> None:
20
20
  """
21
21
  # Initialize a 2D vector with the specified x and y components.
@@ -666,11 +666,25 @@ class Vector2D:
666
666
  other = self.__normalize__(other)
667
667
  return Vector2D(max(self.x, other.x), max(self.y, other.y))
668
668
 
669
+ def advanced_stringify(self:"V2|Vector2D", precision:float|None=None, use_scientific_notation:bool=False, return_as_list=False) -> str:
670
+ precision = self.round_values_on_print if precision == None else precision
671
+ def optimize(value) -> str:
672
+ abs_value = abs(value)
673
+ if abs_value < 1/10**precision and abs_value != 0:
674
+ return f"{value:.{precision}e}"
675
+ elif abs_value < 10**precision:
676
+ return f"{value:.{precision}f}".rstrip('0').rstrip('.')
677
+ else:
678
+ return f"{value:.{precision}e}"
679
+ if return_as_list:
680
+ return [optimize(self.x), optimize(self.y)] if use_scientific_notation else [f"{self.x:.{precision}f}" f"{self.y:.{precision}f}"]
681
+ return f"{optimize(self.x)}, {optimize(self.y)}" if use_scientific_notation else f"{self.x:.{precision}f}, {self.y:.{precision}f}"
682
+
669
683
  def __str__(self:"V2|Vector2D") -> str:
670
- return f"{self.x:{self.round_values_on_print}f}, {self.y:{self.round_values_on_print}f}"
684
+ return f"{self.x:.{self.round_values_on_print}f}, {self.y:.{self.round_values_on_print}f}"
671
685
 
672
686
  def __repr__(self:"V2|Vector2D") -> str:
673
- return f"x:{self.x:{self.round_values_on_print}f}\ty:{self.y:{self.round_values_on_print}f}"
687
+ return f"x:{self.x:.{self.round_values_on_print}f}\ty:{self.y:.{self.round_values_on_print}f}"
674
688
 
675
689
  def __call__(self:"V2|Vector2D", return_tuple=False) -> list|tuple:
676
690
  return (self.x, self.y) if return_tuple else [self.x, self.y]
@@ -1250,3 +1264,12 @@ def distance_line_point(line_point_a:Vector2D|V2, line_point_b:Vector2D|V2, poin
1250
1264
  The result is returned as a float representing the distance between the line segment and the point.
1251
1265
  """
1252
1266
  return float(_np.linalg.norm(_np.cross((line_point_b-line_point_a)(), (line_point_a-point_c)()))/_np.linalg.norm((line_point_b-line_point_a)()))
1267
+
1268
+ def optimize_value_string(value:int|float, precision:int) -> str:
1269
+ abs_value = abs(value)
1270
+ if abs_value < 1/10**precision and abs_value != 0:
1271
+ return f"{value:.{precision}e}"
1272
+ elif abs_value < 10**precision:
1273
+ return f"{value:.{precision}f}".rstrip('0').rstrip('.')
1274
+ else:
1275
+ return f"{value:.{precision}e}"
e2D/envs.py CHANGED
@@ -22,9 +22,9 @@ while not rootEnv.quit:
22
22
 
23
23
  pg.init()
24
24
  pg.font.init()
25
- font_arial_16 = pg.font.SysFont("Arial", 16)
26
- font_arial_32 = pg.font.SysFont("Arial", 32)
27
- font_arial_64 = pg.font.SysFont("Arial", 64)
25
+ FONT_ARIAL_16 = pg.font.SysFont("Arial", 16)
26
+ FONT_ARIAL_32 = pg.font.SysFont("Arial", 32)
27
+ FONT_ARIAL_64 = pg.font.SysFont("Arial", 64)
28
28
  create_arial_font_size = lambda size: pg.font.SysFont("Arial", size)
29
29
 
30
30
  TEXT_FIXED_SIDES_TOP_LEFT = 0
@@ -64,7 +64,7 @@ class RootEnv:
64
64
  def clear_rect(self, position:V2|Vector2D, size:V2|Vector2D) -> None:
65
65
  self.screen.fill(self.background_color, position() + size())
66
66
 
67
- def print(self, text:str, position:V2|Vector2D, color:tuple[float,float,float]=(255,255,255), fixed_sides=TEXT_FIXED_SIDES_TOP_LEFT, font:pg.font.Font=font_arial_32, bg_color:None|tuple[int,int,int]|list[int]=None, border_color:None|tuple[int,int,int]|list[int]=None, border_width:float=0, border_radius:int|list[int]|tuple[int,int,int,int]=-1, margin:V2|Vector2D=V2z, personalized_surface:pg.Surface|None=None) -> None:
67
+ def print(self, text:str, position:V2|Vector2D, color:tuple[float,float,float]=(255,255,255), fixed_sides=TEXT_FIXED_SIDES_TOP_LEFT, font:pg.font.Font=FONT_ARIAL_32, bg_color:None|tuple[int,int,int]|list[int]=None, border_color:None|tuple[int,int,int]|list[int]=None, border_width:float=0, border_radius:int|list[int]|tuple[int,int,int,int]=-1, margin:V2|Vector2D=V2z, personalized_surface:pg.Surface|None=None) -> None:
68
68
  text_box = font.render(text, True, color)
69
69
  size = V2(*text_box.get_size()) + margin * 2
70
70
  position = position - size * self.__fixed_sides_multiplier[fixed_sides] + margin
e2D/plots.py CHANGED
@@ -65,7 +65,7 @@ class PointsFunction(Function):
65
65
 
66
66
  def render(self) -> None:
67
67
  self.__layer_surface__.fill((0,0,0,0))
68
- if len(self.plot_points): pg.draw.lines(self.__layer_surface__, self.color, False, self.plot_points)
68
+ if len(self.plot_points)>=2: pg.draw.lines(self.__layer_surface__, self.color, False, self.plot_points)
69
69
  # for point in self.points:
70
70
  # pg.draw.circle(self.__layer_surface__,
71
71
  # self.points_color,
@@ -120,7 +120,6 @@ class __PlotSettings__:
120
120
  "distance_to_axis_for_scalar_zoom" : 10,
121
121
 
122
122
  # cursor
123
- "show_cursor_coords" : False,
124
123
  "zoom_on_center" : False,
125
124
 
126
125
  # plot visual options
@@ -152,6 +151,9 @@ class __PlotSettings__:
152
151
  "show_pointer" : True,
153
152
  "pointer_radius" : 15,
154
153
  "pointer_color" : rgb(255, 255, 255),
154
+
155
+ # cursor
156
+ "show_cursor_coords" : False,
155
157
 
156
158
  #rect
157
159
  "render_bg" : True,
@@ -163,8 +165,9 @@ class __PlotSettings__:
163
165
 
164
166
  # info options
165
167
  "show_zoom_info": True,
166
- "top_left_info_position" : self.plot.position + V2(20, 100),
167
- "info_interline_space" : V2(0, 32),
168
+ "top_left_info_position" : self.plot.position + V2(15, 75),
169
+ "info_interline_space" : V2(0, 24),
170
+ "info_font" : create_arial_font_size(24),
168
171
  "info_precision" : 2,
169
172
  }
170
173
 
@@ -281,10 +284,10 @@ class Plot:
281
284
  pg.draw.circle(self.canvas, pointer_color, (self.size * .5)(), 15, 1) #type: ignore
282
285
 
283
286
  if self.settings.get("show_corners_coords"):
284
- self.rootEnv.print(str(self.top_left_plot_coord), V2z.copy(), bg_color=(0,0,0), border_color=(255,255,255), border_width=2, border_radius=15, margin=V2(10,10), personalized_surface=self.canvas)
285
- self.rootEnv.print(str(V2(self.top_left_plot_coord.x, self.bottom_right_plot_coord.y)), self.size * V2(0, 1), fixed_sides=TEXT_FIXED_SIDES_BOTTOM_LEFT, bg_color=(0,0,0), border_color=(255,255,255), border_width=2, border_radius=15, margin=V2(10,10), personalized_surface=self.canvas)
286
- self.rootEnv.print(str(self.bottom_right_plot_coord), self.size.copy(), fixed_sides=TEXT_FIXED_SIDES_BOTTOM_RIGHT, bg_color=(0,0,0), border_color=(255,255,255), border_width=2, border_radius=15, margin=V2(10,10), personalized_surface=self.canvas)
287
- self.rootEnv.print(str(V2(self.bottom_right_plot_coord.x, self.top_left_plot_coord.y)), self.size * V2(1, 0), fixed_sides=TEXT_FIXED_SIDES_TOP_RIGHT, bg_color=(0,0,0), border_color=(255,255,255), border_width=2, border_radius=15, margin=V2(10,10), personalized_surface=self.canvas)
287
+ self.rootEnv.print(self.top_left_plot_coord.advanced_stringify(4, True), V2z.copy(), bg_color=(0,0,0), border_color=(255,255,255), border_width=2, border_radius=15, margin=V2(10,10), personalized_surface=self.canvas)
288
+ self.rootEnv.print(V2(self.top_left_plot_coord.x, self.bottom_right_plot_coord.y).advanced_stringify(4, True), self.size * V2(0, 1), fixed_sides=TEXT_FIXED_SIDES_BOTTOM_LEFT, bg_color=(0,0,0), border_color=(255,255,255), border_width=2, border_radius=15, margin=V2(10,10), personalized_surface=self.canvas)
289
+ self.rootEnv.print(self.bottom_right_plot_coord.advanced_stringify(4, True), self.size.copy(), fixed_sides=TEXT_FIXED_SIDES_BOTTOM_RIGHT, bg_color=(0,0,0), border_color=(255,255,255), border_width=2, border_radius=15, margin=V2(10,10), personalized_surface=self.canvas)
290
+ self.rootEnv.print(V2(self.bottom_right_plot_coord.x, self.top_left_plot_coord.y).advanced_stringify(4, True), self.size * V2(1, 0), fixed_sides=TEXT_FIXED_SIDES_TOP_RIGHT, bg_color=(0,0,0), border_color=(255,255,255), border_width=2, border_radius=15, margin=V2(10,10), personalized_surface=self.canvas)
288
291
 
289
292
  def update(self) -> None:
290
293
  # update mouse and center positions
@@ -389,14 +392,17 @@ class Plot:
389
392
  if not render_axes_on_top: self.rootEnv.screen.blit(self.canvas, self.position())
390
393
 
391
394
  if self.is_mouse_in_rect and self.settings.get("show_cursor_coords"):
392
- self.rootEnv.print(str(self.plot_mouse_position), self.rootEnv.mouse.position, fixed_sides=TEXT_FIXED_SIDES_BOTTOM_MIDDLE) #type: ignore
395
+ self.rootEnv.print(self.plot_mouse_position.advanced_stringify(3, True), self.rootEnv.mouse.position, fixed_sides=TEXT_FIXED_SIDES_BOTTOM_MIDDLE) #type: ignore
396
+
393
397
 
398
+ current_real_zoom = (.5**(.1*self.current_zoom)).advanced_stringify(self.settings.get('info_precision'), True, True)
394
399
  data = [
395
400
  [f"ZOOM:", TEXT_FIXED_SIDES_TOP_LEFT, self.settings.get("show_zoom_info")],
396
- [f" x: {(.5**(.1*self.current_zoom.x)):.{self.settings.get('info_precision')}f};", TEXT_FIXED_SIDES_TOP_LEFT, self.settings.get("show_zoom_info")],
397
- [f" y: {(.5**(.1*self.current_zoom.y)):.{self.settings.get('info_precision')}f};", TEXT_FIXED_SIDES_TOP_LEFT, self.settings.get("show_zoom_info")],
401
+ [f" x: {current_real_zoom[0]};", TEXT_FIXED_SIDES_TOP_LEFT, self.settings.get("show_zoom_info")],
402
+ [f" y: {current_real_zoom[1]};", TEXT_FIXED_SIDES_TOP_LEFT, self.settings.get("show_zoom_info")],
403
+ [f" ratio: {optimize_value_string(self.current_zoom.x / self.current_zoom.y, 4)};", TEXT_FIXED_SIDES_TOP_LEFT, self.settings.get("show_zoom_info")],
398
404
  ]
399
405
 
400
406
  for i, (d, fixed_side, show) in enumerate(data):
401
407
  if show:
402
- self.rootEnv.print(d, self.settings.get("top_left_info_position") + self.settings.get("info_interline_space") * i, fixed_sides=fixed_side) #type: ignore
408
+ self.rootEnv.print(d, self.settings.get("top_left_info_position") + self.settings.get("info_interline_space") * i, fixed_sides=fixed_side, font=self.settings.get("info_font"))
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: e2D
3
- Version: 1.3.10
3
+ Version: 1.3.11
4
4
  Summary: Python library for 2D games. Streamlines dev with keyboard/mouse input, vector calculations, color manipulation, and collision detection. Simplify game creation and unleash creativity!
5
5
  Home-page: https://github.com/marick-py/e2D
6
6
  Author: Riccardo Mariani
@@ -0,0 +1,9 @@
1
+ e2D/__init__.py,sha256=5cJrfMFX1jhMADrf2PH8Rr1yL-ZgZVdRg3k_HLym2zs,57567
2
+ e2D/envs.py,sha256=ULXoK0yDM9_Z2iCQpMXEYo1Fr4NhKoDXFQXyG3CtOdU,4083
3
+ e2D/plots.py,sha256=xlkFJNDTeJEDVloMgyISOfS_oWHpJ7q9_3HkKGwydjA,23402
4
+ e2D/utils.py,sha256=hGO9WhvDvE6wDDw0vIEjVCis64aTOMgrssx-P0_znhI,5513
5
+ e2D-1.3.11.dist-info/LICENSE,sha256=wymkNVDvj3qmjdO_rAhkRPM4t5y3_SqffGsFdgfvznU,1066
6
+ e2D-1.3.11.dist-info/METADATA,sha256=sYCWrReK8vO260de8rdNeo0s9VhGDu8PJWgJGT__I3o,9609
7
+ e2D-1.3.11.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
8
+ e2D-1.3.11.dist-info/top_level.txt,sha256=3vKZ-CGzNlTCpzVMmM0Ht76krCofKw7hZ0wBf-dnKdM,4
9
+ e2D-1.3.11.dist-info/RECORD,,
@@ -1,9 +0,0 @@
1
- e2D/__init__.py,sha256=L4wmmedzo_SQUIcCwPYTMJTuqYi_lASRdCwL1q0Q2rw,56327
2
- e2D/envs.py,sha256=eZ2RfSKpMuRrx5XDOntWweevpnArVPBGp84HJmL9OQA,4083
3
- e2D/plots.py,sha256=jjc3p5qjSrYVmxSr3cJACiPNGVAhDwnWKD06YR61IB8,22960
4
- e2D/utils.py,sha256=hGO9WhvDvE6wDDw0vIEjVCis64aTOMgrssx-P0_znhI,5513
5
- e2D-1.3.10.dist-info/LICENSE,sha256=wymkNVDvj3qmjdO_rAhkRPM4t5y3_SqffGsFdgfvznU,1066
6
- e2D-1.3.10.dist-info/METADATA,sha256=S8r48k1ZI7AW3p6OplsD1sSMGyr9Qna_BnUJ9Q3Pung,9609
7
- e2D-1.3.10.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
8
- e2D-1.3.10.dist-info/top_level.txt,sha256=3vKZ-CGzNlTCpzVMmM0Ht76krCofKw7hZ0wBf-dnKdM,4
9
- e2D-1.3.10.dist-info/RECORD,,
File without changes
File without changes