Quantum Phenomena Explorer 7.9.8
Interactive quantum-phenomena Explorer Tutor — source documentation
Loading...
Searching...
No Matches
quantumpotentialeditor2d.cpp
Go to the documentation of this file.
1/**
2 * @file quantumpotentialeditor2d.cpp
3 * @brief Implements the quantumpotentialeditor2d visualization component used by QPE.
4 * @ingroup qpe_graphics
5 *
6 * Source: @c graphics/renderer/quantumpotentialeditor2d.cpp. This file is part of Quantum Phenomena Explorer (QPE),
7 * maintained by Officina Turini. See LICENSE_IT.txt / LICENSE.txt for the
8 * QPE freeware source-available terms and THIRD_PARTY_NOTICES.txt for
9 * third-party components.
10 */
11
13
14#include <algorithm>
15#include <cmath>
16
17namespace qpe {
18
19bool PotentialEditorShape::valid() const noexcept
20{
22 return std::isfinite(static_cast<double>(centerX)) &&
23 std::isfinite(static_cast<double>(centerY)) &&
24 std::isfinite(static_cast<double>(radius)) &&
25 radius > 0.0f;
26 }
27
28 return std::isfinite(static_cast<double>(centerX)) &&
29 std::isfinite(static_cast<double>(centerY)) &&
30 std::isfinite(static_cast<double>(width)) &&
31 std::isfinite(static_cast<double>(height)) &&
32 width > 0.0f && height > 0.0f;
33}
34
36 float y1,
37 float x2,
38 float y2,
39 float minimumWidth,
40 float minimumHeight) noexcept
41{
44 shape.centerX = 0.5f * (x1 + x2);
45 shape.centerY = 0.5f * (y1 + y2);
46 shape.width = std::max(std::abs(x2 - x1), std::max(minimumWidth, 0.0f));
47 shape.height = std::max(std::abs(y2 - y1), std::max(minimumHeight, 0.0f));
48 return shape;
49}
50
52 float centerY,
53 float edgeX,
54 float edgeY,
55 float minimumRadius) noexcept
56{
59 shape.centerX = centerX;
60 shape.centerY = centerY;
61 const float dx = edgeX - centerX;
62 const float dy = edgeY - centerY;
63 shape.radius = std::max(std::sqrt(dx * dx + dy * dy), std::max(minimumRadius, 0.0f));
64 return shape;
65}
66
67} // namespace qpe
static PotentialEditorShape circleFromDrag(float centerX, float centerY, float edgeX, float edgeY, float minimumRadius) noexcept
Performs circle from drag.
static PotentialEditorShape rectangleFromDrag(float x1, float y1, float x2, float y2, float minimumWidth, float minimumHeight) noexcept
Performs rectangle from drag.
Declares the quantumpotentialeditor2d visualization component used by QPE.
Data structure used by the Potential Editor Shape component.
bool valid() const noexcept
Performs valid.