"""Star symbol and overlay segments (EUSTAR, EUTEMP)."""
from __future__ import annotations
from ephemeris_tools.rendering.escher import (
EscherState,
EscherViewState,
esdraw,
esdump,
)
from ephemeris_tools.rendering.escher.ps_output import espl07
from ephemeris_tools.rendering.euclid.state import EuclidState
from ephemeris_tools.rendering.euclid.vec_math import _mtxv
[docs]
def eustar(
strpos: tuple[float, float, float],
nstars: int,
font: list[tuple[tuple[float, float], tuple[float, float]]],
fntsiz: int,
fntscl: float,
color: int,
euclid_state: EuclidState,
view_state: EscherViewState,
escher_state: EscherState,
) -> None:
"""Draw star/point markers with a line-segment font (port of EUSTAR).
Characters are scaled by fntscl times the display size so they do not
scale with zoom. Font is a list of ((x1,y1),(x2,y2)) segment endpoints.
Parameters:
strpos: Position of the point (e.g. star) in scene coordinates.
nstars: Number of points (unused; single point drawn).
font: Segment list for the marker; font[i] = ((x1,y1), (x2,y2)).
fntsiz: Number of segments to use.
fntscl: Scale factor (0-1) for marker size vs display.
color: Color code for drawing.
euclid_state: Euclid state.
view_state: Escher view state.
escher_state: Escher output state.
"""
_ = nstars
cam = euclid_state.camera
if cam is None:
return
star = _mtxv(cam, list(strpos))
if star[2] <= 0:
return
center_proj_x = -star[0] / star[2]
center_proj_y = -star[1] / star[2]
if abs(view_state._ux) < 1.0e-12 or abs(view_state._uy) < 1.0e-12:
return
left, right, bottom, top = espl07()
hspan = abs(view_state.view[1] - view_state.view[0])
vspan = abs(view_state.view[3] - view_state.view[2])
if hspan < 1.0e-12 or vspan < 1.0e-12:
raise ValueError(
f'Degenerate view_state.view: hspan={hspan}, vspan={vspan}, view={view_state.view}'
)
# ESSTAR maps glyph coordinates over a viewport-scaled box centered on the
# target point. The segment font is defined over a full-width range, so the
# viewport half-size factor is required for FORTRAN-equivalent glyph size.
dx_proj_scale = 0.5 * fntscl * hspan * abs(right - left) / abs(view_state._ux)
dy_proj_scale = 0.5 * fntscl * vspan * abs(top - bottom) / abs(view_state._uy)
for i in range(min(fntsiz, len(font))):
(fx1, fy1), (fx2, fy2) = font[i]
proj_x1 = center_proj_x + (fx1 * dx_proj_scale)
proj_y1 = center_proj_y + (fy1 * dy_proj_scale)
proj_x2 = center_proj_x + (fx2 * dx_proj_scale)
proj_y2 = center_proj_y + (fy2 * dy_proj_scale)
beg = (-proj_x1 * star[2], -proj_y1 * star[2], star[2])
end = (-proj_x2 * star[2], -proj_y2 * star[2], star[2])
esdraw(beg, end, color, view_state, escher_state)
esdump(view_state, escher_state)
[docs]
def eutemp(
xbegin: list[float],
ybegin: list[float],
xend: list[float],
yend: list[float],
nsegs: int,
color: int,
view_state: EscherViewState,
escher_state: EscherState,
) -> None:
"""Draw line-segment overlay on the image plane (port of EUTEMP).
Draws reference marks (e.g. angle scale) in image-plane coordinates.
Segment i has start (xbegin[i], ybegin[i]) and end (xend[i], yend[i]).
Parameters:
xbegin: x-coordinates of segment starts.
ybegin: y-coordinates of segment starts.
xend: x-coordinates of segment ends.
yend: y-coordinates of segment ends.
nsegs: Number of segments.
color: Color code for drawing.
view_state: Escher view state.
escher_state: Escher output state.
"""
for i in range(nsegs):
beg = (-xbegin[i], -ybegin[i], 1.0)
end = (-xend[i], -yend[i], 1.0)
esdraw(beg, end, color, view_state, escher_state)
esdump(view_state, escher_state)