Ë
    }D™j!  ã                   ó  — d Z ddlmZ ddlmZmZ ddlmZmZm	Z	 ddl
mZ ddlmZ ddlmZmZ dee   d	eeef   d
eeef   fd„Zdedededededefd„Zdee   dedefd„Z	 dedœdeeee	f   dee   deee   ee   f   defd„Zy)z6
This is part of Kerykeion (C) 2025 Giacomo Battaglia
é    )Údifdeg2n)ÚOptionalÚUnion)ÚAstrologicalSubjectModelÚCompositeSubjectModelÚPlanetReturnModel)ÚAspectMovementType)Ú$KerykeionSettingsCelestialPointModel)Ú!DEFAULT_CELESTIAL_POINTS_SETTINGSÚ_CelestialPointSettingÚaspects_settingsÚ	point_oneÚ	point_twoc                 ó  — t        t        ||«      «      }t        ||z
  «      }t        | «      D ].  \  }}|d   }|d   }||z
  |cxk  r	||z   k  sŒ"n Œ%|d   }	|}
d} n d}d}	d}
||	t        ||
z
  «      t        ||
z
  «      |
|dœS )	aI  
    Utility function to calculate the aspects between two points.

    Args:
        aspects_settings (dict): Dictionary containing aspect settings.
        point_one (Union[float, int]): First point.
        point_two (Union[float, int]): Second point.

    Returns:
        dict: Dictionary containing the aspect details.
    ÚdegreeÚorbÚnameTFNr   )Úverdictr   ÚorbitÚdistanceÚaspect_degreesÚdiff)Úabsr   Ú	enumerate)r   r   r   r   r   ÚaidÚaspectÚaspect_degreeÚ
aspect_orbr   r   r   s               úk/var/www/html/Astrologybackend/backend/venv/lib/python3.12/site-packages/kerykeion/aspects/aspects_utils.pyÚget_aspect_from_two_pointsr       sÀ   € ô  ”8˜I yÓ1Ó2€HÜˆy˜9Ñ$Ó%€Dä Ð!1Ó2ò ‰ˆˆVà˜xÑ(ˆØ˜E‘]ˆ
à˜JÑ&¨8ÔS¸È
Ñ8RÖSØ˜&‘>ˆDØ*ˆNØˆGÙðð ˆØˆØˆð ØÜ�X Ñ.Ó/Ü˜ >Ñ1Ó2Ø(Øñð ó    Úpoint_one_abs_posÚpoint_two_abs_posr   Úpoint_one_speedÚpoint_two_speedÚreturnc                 ó²  — d}d}d}|�|€t        d«      ‚d| cxk  rdk  rn nd|cxk  rdk  sn t        d| › d|› �«      ‚|dk  rt        d	|› �«      ‚t        ||z
  «      }||k  ry
dt        dt        dt        dt        fd„}	|dz  }
|
dkD  rd|
z
  }
 |	| ||
«      }| ||z  z   dz  }|||z  z   dz  } |	|||
«      }||z
  }t        |«      |k  ry
|dk  ryy)u.  
    Determine whether the aspect orb is decreasing (Applying), increasing
    (Separating), or not changing (Static).

    This implementation uses a "lookahead" approach:
    1. Calculate the current orb (deviation from exact aspect).
    2. Project positions forward by a small time step (dt).
    3. Calculate the future orb.
    4. Compare: if future_orb < current_orb => Applying, else Separating.

    The function handles edge cases including:
    - Retrograde motion (negative speeds)
    - Boundary crossings at 0Â°/360Â°
    - Aspects > 180Â° (normalized correctly)
    - Extreme speed differences (e.g., Ascendant vs slow planets)
    - Very small orbs and speed differences

    Args:
        point_one_abs_pos (float): Absolute position of point 1 (0-360).
        point_two_abs_pos (float): Absolute position of point 2 (0-360).
        aspect_degrees (float): The exact aspect angle (e.g., 0, 60, 90, 120, 180).
            Can be > 180Â° (will be normalized).
        point_one_speed (float): Speed of point 1 in degrees/day (negative for retrograde).
        point_two_speed (float): Speed of point 2 in degrees/day (negative for retrograde).

    Returns:
        AspectMovementType: "Applying", "Separating", or "Static".

    Raises:
        ValueError: If speed values are None or if positions/aspect are invalid.

    Notes:
        - Static is returned when relative speed is effectively zero (< EPSILON)
        - The function uses a small time step (dt) for numerical differentiation
        - Precision: Changes in orb < EPSILON are considered Static
    g•Ö&è.>g�íµ ÷Æ°>gü©ñÒMbP?zƒSpeed values for both points are required to compute aspect movement correctly. point_one_speed and point_two_speed cannot be None.r   ih  z,Positions must be in range [0, 360). Got p1=z, p2=z)Aspect degrees must be non-negative. Got ÚStaticÚp1Úp2r   r&   c                 óH   — t        t        | |«      «      }t        ||z
  «      S )a  
        Calculate the orb (deviation from exact aspect).

        Args:
            p1: Position of first point (0-360)
            p2: Position of second point (0-360)
            aspect: Normalized aspect angle (0-180)

        Returns:
            Absolute orb in degrees
        )r   r   )r)   r*   r   r   s       r   Úget_orbz*calculate_aspect_movement.<locals>.get_orb‡   s$   € ô ”8˜B Ó#Ó$ˆä�4˜&‘=Ó!Ð!r!   g     €v@g     €f@ÚApplyingÚ
Separating)Ú
ValueErrorr   Úfloat)r"   r#   r   r$   r%   ÚSPEED_EPSILONÚORB_EPSILONÚDTÚrelative_speedr,   Úaspect_normÚcurrent_orbÚ	p1_futureÚ	p2_futureÚ
future_orbÚ
orb_changes                   r   Úcalculate_aspect_movementr;   ;   s_  € ðZ €Mà€Kð 
€Bð Ð /Ð"9Üðó
ð 	
ð Ð"Ô( SÕ(°!Ð7HÔ2NÈ3Ô2NÜÐGÐHYÐGZÐZ_Ð`qÐ_rÐsÓtÐtð ˜ÒÜÐDÀ^ÐDTÐUÓVÐVô
 ˜¨?Ñ:Ó;€NØ˜Ò%Øð"”Eð "œuð "¬eð "¼ó "ð( ! 5Ñ(€KØ�UÒØ˜kÑ)ˆñ Ð+Ð->ÀÓL€Kð
 # _°rÑ%9Ñ9¸UÑB€IØ" _°rÑ%9Ñ9¸UÑB€Iá˜ I¨{Ó;€Jð ˜kÑ)€Jô ˆ:ƒ˜Ò$ØØ	�aŠàð r!   Úplanets_settingsr   c                 óf   — t        |«      }| D ]  }|d   |k(  sŒ|d   }|c S  t        d|› d�«      ‚)zs
    Check if the name of the planet is the same in the settings and return
    the correct id for the planet.
    r   ÚidzPlanet z not found in the settings)Ústrr/   )r<   r   Ústr_nameÚplanetÚresults        r   Úplanet_id_decoderrC   º   sM   € ô
 �4‹y€HØ"ò ˆØ�&‰>˜XÓ%Ø˜D‘\ˆFØŠMðô
 �w˜t˜fÐ$>Ð?Ó
@Ð@r!   N)Úcelestial_pointsÚsubjectÚactive_pointsrD   c                óz   — |€g }g }|D ]/  }|d   |v sŒ|j                  | |d   j                  «          «       Œ1 |S )aÉ  
    Given an astrological subject and the settings, return a list of the active points.

    Args:
        subject (AstrologicalSubject): The astrological subject to get the active points from.
        active_points (list, optional): List of active point names to filter. Defaults to None.
        celestial_points (Union[list[_CelestialPointSetting], list[dict]]): Settings for celestial points.

    Returns:
        list: List of the active points.
    r   )ÚappendÚlower)rE   rF   rD   Ú
point_listrA   s        r   Úget_active_points_listrK   È   sW   € ð" ÐØˆØ€JØ"ò ?ˆØ�&‰>˜]Ò*Ø×Ñ˜g f¨V¡n×&:Ñ&:Ó&<Ñ=Õ>ð?ð Ðr!   )N)Ú__doc__Úswissephr   Útypingr   r   Úkerykeion.schemas.kr_modelsr   r   r   Úkerykeion.schemas.kr_literalsr	   Ú!kerykeion.schemas.settings_modelsr
   Ú!kerykeion.settings.chart_defaultsr   r   ÚlistÚdictr0   Úintr    r;   r?   rC   rK   © r!   r   ú<module>rW      s#  ðñõ
 ß "ß jÑ jÝ <Ý Rß gð)Ø˜4‘jð)à�U˜C�ZÑ ð)ð �U˜C�ZÑ ó)ðX|Øð|àð|ð ð|ð ð	|ð
 ð|ð ó|ð~A¨Ð-QÑ(Rð AÐZ]ð AÐbeó Að  %)ðð Ijò	ØÐ+Ð-BÐDUÐUÑVðà˜D‘>ðð ˜DÐ!7Ñ8¸$¸t¹*ÐDÑEð	ð
 
ôr!   