Crate opticalc

Crate opticalc 

Source
Expand description

§opticalc

Rust utilities for common clinical optics calculations used in optometry and ophthalmic settings.

Features

  • Index conversion: Convert measured lens powers between assumed and actual refractive indices.
  • Rx conversion: Scale full sphero‑cyl prescriptions between indices while preserving axis.
  • Lensmeter simulation: Predict what a lensmeter would read for a true Rx at a different index.
  • Induced prism: Compute horizontal/vertical prism from decentration using the full power matrix.
  • Crossed cylinders and oblique meridian helpers.

§Examples

use opticalc::*;

// Convert a measured power from 1.523 to 1.586
let true_power = convert_power(-4.463, 1.523, 1.586);

// Convert a full sphero‑cyl Rx between indices
let measured = SpheroCyl { sphere: -2.00, cylinder: -1.00, axis_deg: 180.0 };
let true_rx = convert_rx(measured, 1.523, 1.586);

// Simulate what a lensmeter @1.523 would read for a true Rx @1.586
let reading = simulate_lensmeter_reading(true_rx, 1.523, 1.586);

Induced prism from decentration (Prentice’s rule, full toric matrix):

use opticalc::*;

let lens = SpheroCyl { sphere: 2.0, cylinder: -1.0, axis_deg: 25.0 };
let dec = Decentration { horizontal_mm: 2.0, vertical_mm: -1.0 };
let p = induced_prism(Eye::OD, lens, dec);

// Access signed or magnitude/base components
let h_signed = p.horizontal.signed();
let v_signed = p.vertical.signed();
let mag = p.magnitude();

Structs§

CombinedPrism
Represents combined horizontal and vertical prism components.
Decentration
Represents lens decentration relative to the optical center.
HorizontalPrism
Represents horizontal prism in prism diopters, with an explicit base direction.
SpheroCyl
Defines a sphero-cylinder lens.
VerticalPrism
Represents vertical prism in prism diopters, with an explicit base direction.

Enums§

Eye
Defines the eye.
HorizontalBase
Base direction for horizontal prism relative to the patient.
VerticalBase
Base direction for vertical prism.

Constants§

CROWN_GLASS_INDEX
Refractive index of Crown Glass (standard optical glass).
CR_39_INDEX
Refractive index of CR-39 (Columbia Resin #39).
HIGH_INDEX_160_INDEX
Refractive index of High-Index 1.60 plastic.
HIGH_INDEX_167_INDEX
Refractive index of High-Index 1.67 plastic.
HIGH_INDEX_174_INDEX
Refractive index of High-Index 1.74 plastic.
POLYCARBONATE_INDEX
Refractive index of Polycarbonate.
TRIVEX_INDEX
Refractive index of Trivex.

Functions§

convert_power
Convert a lens power measured under an assumed refractive index to the true power for the actual material index.
convert_rx
Convert a full sph-cyl-axis Rx measured under an assumed index to the true Rx at the actual index. Axis is returned unchanged.
crossed_cylinders
Calculate Obliquely Crossed Cylinders
induced_prism
Compute induced prism using the full sphero-cylinder power matrix, including toric cross-terms, with OD/OS handling, returning clinical base directions.
minimum_blank_size
Calculate the minimum blank size for a single vision lens.
oblique_meridian
Oblique Meridian Power
recommended_blank_size
Calculate the recommended blank size including working edge border.
simulate_lensmeter_reading
Inverse of convert_rx: given the true Rx at the actual index, compute what a lensmeter calibrated to the assumed index would read. Axis is unchanged.
transpose
Transpose a spherocylindrical lens prescription to the opposite cylinder form.