[Bf-extensions-cvs] [d7333adb] master: Sun Position: cleanup

Damien Picard noreply at git.blender.org
Sun Jan 8 02:53:07 CET 2023


Commit: d7333adb72bc799166da49a2afd1ca83a5641197
Author: Damien Picard
Date:   Sat Jan 7 19:26:57 2023 +0100
Branches: master
https://developer.blender.org/rBAd7333adb72bc799166da49a2afd1ca83a5641197

Sun Position: cleanup

===================================================================

M	sun_position/draw.py
M	sun_position/sun_calc.py

===================================================================

diff --git a/sun_position/draw.py b/sun_position/draw.py
index c343df05..5c071641 100644
--- a/sun_position/draw.py
+++ b/sun_position/draw.py
@@ -52,11 +52,11 @@ else:
     shader = gpu.types.GPUShader(vertex_shader, fragment_shader)
 
     def draw_north_callback():
-        # ------------------------------------------------------------------
-        # Set up the compass needle using the current north offset angle
-        # less 90 degrees.  This forces the unit circle to begin at the
-        # 12 O'clock instead of 3 O'clock position.
-        # ------------------------------------------------------------------
+        """
+        Set up the compass needle using the current north offset angle
+        less 90 degrees.  This forces the unit circle to begin at the
+        12 O'clock instead of 3 O'clock position.
+        """
         sun_props = bpy.context.scene.sun_pos_properties
 
         color = (0.2, 0.6, 1.0, 0.7)
@@ -64,30 +64,25 @@ else:
         angle = -(sun_props.north_offset - math.pi / 2)
         x = math.cos(angle) * radius
         y = math.sin(angle) * radius
-
-        coords = Vector((x, y, 0)), Vector((0, 0, 0))   # Start & end of needle
-
-        batch = batch_for_shader(
-            shader, 'LINE_STRIP',
-            {"position": coords},
-        )
-        shader.bind()
+        coords = Vector((x, y, 0)), Vector((0, 0, 0))
+        batch = batch_for_shader(shader, 'LINE_STRIP', {"position": coords})
 
         matrix = bpy.context.region_data.perspective_matrix
         shader.uniform_float("u_ViewProjectionMatrix", matrix)
-        shader.uniform_float("u_Resolution", (bpy.context.region.width, bpy.context.region.height))
+        shader.uniform_float("u_Resolution", (bpy.context.region.width,
+                                              bpy.context.region.height))
         shader.uniform_float("u_Color", color)
         gpu.state.line_width_set(2.0)
         batch.draw(shader)
 
-    _handle = None
 
+    _north_handle = None
 
     def north_update(self, context):
-        global _handle
-        if self.show_north and _handle is None:
-            _handle = bpy.types.SpaceView3D.draw_handler_add(draw_north_callback, (), 'WINDOW', 'POST_VIEW')
-        elif _handle is not None:
-            bpy.types.SpaceView3D.draw_handler_remove(_handle, 'WINDOW')
-            _handle = None
+        global _north_handle
+        if self.show_north and _north_handle is None:
+            _north_handle = bpy.types.SpaceView3D.draw_handler_add(draw_north_callback, (), 'WINDOW', 'POST_VIEW')
+        elif _north_handle is not None:
+            bpy.types.SpaceView3D.draw_handler_remove(_north_handle, 'WINDOW')
+            _north_handle = None
         context.area.tag_redraw()
diff --git a/sun_position/sun_calc.py b/sun_position/sun_calc.py
index 39c8444e..b1ae46dd 100644
--- a/sun_position/sun_calc.py
+++ b/sun_position/sun_calc.py
@@ -9,14 +9,10 @@ import datetime
 from .geo import parse_position
 
 
-############################################################################
-#
-# SunClass is used for storing intermediate sun calculations.
-#
-############################################################################
-
 class SunClass:
-
+    """
+    SunClass is used for storing intermediate sun calculations.
+    """
     class TazEl:
         time = 0.0
         azimuth = 0.0
@@ -81,16 +77,11 @@ def sun_handler(scene):
     move_sun(bpy.context)
 
 
-############################################################################
-#
-# move_sun() will cycle through all the selected objects
-# and call set_sun_position and set_sun_rotations
-# to place them in the sky.
-#
-############################################################################
-
-
 def move_sun(context):
+    """
+    Cycle through all the selected objects and call set_sun_position and
+    set_sun_rotations to place them in the sky
+    """
     addon_prefs = context.preferences.addons[__package__].preferences
     sun_props = context.scene.sun_pos_properties
 
@@ -265,29 +256,23 @@ def format_lat_long(lat_long, is_latitude):
     return hh + "° " + mm + "' " + ss + '"' + coord_tag
 
 
-
-
-############################################################################
-#
-# Calculate the actual position of the sun based on input parameters.
-#
-# The sun positioning algorithms below are based on the National Oceanic
-# and Atmospheric Administration's (NOAA) Solar Position Calculator
-# which rely on calculations of Jean Meeus' book "Astronomical Algorithms."
-# Use of NOAA data and products are in the public domain and may be used
-# freely by the public as outlined in their policies at
-#               www.nws.noaa.gov/disclaimer.php
-#
-# The calculations of this script can be verified with those of NOAA's
-# using the Azimuth and Solar Elevation displayed in the SunPos_Panel.
-# NOAA's web site is:
-#               http://www.esrl.noaa.gov/gmd/grad/solcalc
-############################################################################
-
-
 def get_sun_position(local_time, latitude, longitude, north_offset,
                    utc_zone, month, day, year, distance):
-
+    """
+    Calculate the actual position of the sun based on input parameters.
+
+    The sun positioning algorithms below are based on the National Oceanic
+    and Atmospheric Administration's (NOAA) Solar Position Calculator
+    which rely on calculations of Jean Meeus' book "Astronomical Algorithms."
+    Use of NOAA data and products are in the public domain and may be used
+    freely by the public as outlined in their policies at
+                www.nws.noaa.gov/disclaimer.php
+
+    The calculations of this script can be verified with those of NOAA's
+    using the Azimuth and Solar Elevation displayed in the SunPos_Panel.
+    NOAA's web site is:
+                http://www.esrl.noaa.gov/gmd/grad/solcalc
+    """
     addon_prefs = bpy.context.preferences.addons[__package__].preferences
     sun_props = bpy.context.scene.sun_pos_properties
 
@@ -381,9 +366,7 @@ def set_sun_position(obj, distance):
     locY = math.sin(sun.theta) * math.cos(sun.phi) * distance
     locZ = math.cos(sun.theta) * distance
 
-    #----------------------------------------------
     # Update selected object in viewport
-    #----------------------------------------------
     obj.location = locX, locY, locZ
 
 
@@ -475,13 +458,12 @@ def calc_sunrise_sunset(rise):
         sun.sunset.azimuth = sun.azimuth
         sun.sunset.elevation = sun.elevation
 
-##########################################################################
-## Get the elapsed julian time since 1/1/2000 12:00 gmt
-## Y2k epoch (1/1/2000 12:00 gmt) is Julian day 2451545.0
-##########################################################################
-
 
 def julian_time_from_y2k(utc_time, year, month, day):
+    """
+    Get the elapsed julian time since 1/1/2000 12:00 gmt
+    Y2k epoch (1/1/2000 12:00 gmt) is Julian day 2451545.0
+    """
     century = 36525.0  # Days in Julian Century
     epoch = 2451545.0  # Julian Day for 1/1/2000 12:00 gmt
     jd = get_julian_day(year, month, day)



More information about the Bf-extensions-cvs mailing list