Skip to content

Interactive 2D wave optics simulator. Turn any image into a refractive scene, add sources, watch waves refract, diffract and interfere. Probes, intensity maps, video export.

C#
1.9 KB
Raw Blame
// SPDX-License-Identifier: GPL-3.0-or-later
// Copyright (C) 2026 Alexander Graef <[email protected]>
//
// This file is part of WaveDude Next, a 2D wave simulator.
//
// Based on the work of
//   Jeroen Vleggaar (Huygens Optics), author of Wave Dude 2D, Copyright (C) 2026
//     <https://www.youtube.com/@HuygensOptics>, <https://www.huygensoptics.com>
//   0x23 (Diffraction Limited), author of WaveSimulator2D
//     <https://www.youtube.com/@DiffractionLimited>, <https://github.com/0x23/WaveSimulator2D>
//
// WaveDude Next is free software: you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free Software
// Foundation, either version 3 of the License, or (at your option) any later
// version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
// <https://www.gnu.org/licenses/>.

using System.Globalization;
using System.Windows.Data;
using WaveDudeNext.Model;

namespace WaveDudeNext.WPF.Converters;

/// <summary>
/// The edge thickness of a lens part as text ("5.6 px"), computed on a throw-away part so the model's own rule
/// (<see cref="LensPart.FitRadii"/>) decides. Inputs: the diameter, the centre thickness, R1, R2; re-evaluated on each edit.
/// </summary>
public sealed class LensEdgeConverter : IMultiValueConverter
{
	/// <inheritdoc/>
	public object? Convert(object?[] values, Type targetType, object? parameter, CultureInfo culture)
	{
		if (values.Length < 4 || values[0] is not int diameter || values[1] is not int thickness || values[2] is not double r1 || values[3] is not double r2)
		{
			return null;
		}
		var probe = new LensPart { Diameter = diameter, Thickness = thickness, R1 = r1, R2 = r2 };
		return string.Format(culture, "{0:0.#} px", probe.EdgeThickness);
	}

	/// <inheritdoc/>
	public object[] ConvertBack(object? value, Type[] targetTypes, object? parameter, CultureInfo culture) =>
		throw new NotSupportedException();
}