diff --git a/.gitignore b/.gitignore
index da6ed1a..0c289a1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,2 @@
-# Project exclude paths
+# Project exclude paths
/cmake-build-debug/
\ No newline at end of file
diff --git a/.idea/.gitignore b/.idea/.gitignore
index 13566b8..1c2fda5 100644
--- a/.idea/.gitignore
+++ b/.idea/.gitignore
@@ -1,8 +1,8 @@
-# Default ignored files
-/shelf/
-/workspace.xml
-# Editor-based HTTP Client requests
-/httpRequests/
-# Datasource local storage ignored files
-/dataSources/
-/dataSources.local.xml
+# Default ignored files
+/shelf/
+/workspace.xml
+# Editor-based HTTP Client requests
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml
diff --git a/.idea/PhysicsFormula.iml b/.idea/PhysicsFormula.iml
index f08604b..6d70257 100644
--- a/.idea/PhysicsFormula.iml
+++ b/.idea/PhysicsFormula.iml
@@ -1,2 +1,2 @@
-
+
\ No newline at end of file
diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml
index a55e7a1..df5f35d 100644
--- a/.idea/codeStyles/codeStyleConfig.xml
+++ b/.idea/codeStyles/codeStyleConfig.xml
@@ -1,5 +1,5 @@
-
-
-
-
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
index 79b3c94..f1c67df 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -1,4 +1,4 @@
-
-
-
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
index 68962e0..ee276c7 100644
--- a/.idea/modules.xml
+++ b/.idea/modules.xml
@@ -1,8 +1,8 @@
-
-
-
-
-
-
-
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
index 94a25f7..9661ac7 100644
--- a/.idea/vcs.xml
+++ b/.idea/vcs.xml
@@ -1,6 +1,6 @@
-
-
-
-
-
+
+
+
+
+
\ No newline at end of file
diff --git a/Angle.cpp b/Angle.cpp
index 01467bf..dcdca8b 100644
--- a/Angle.cpp
+++ b/Angle.cpp
@@ -1,65 +1,65 @@
-//
-// Created by Ryan.Zurrin001 on 12/16/2021.
-//
-#include
-
-#include "Angle.h"
-
-//float rez::AngleLines2D( const Line2d& l1, const Line2d l2)
-//{
-// auto mag_l1 = l1.direction().magnitude();
-// auto mag_l2 = l2.direction().magnitude();
-// auto dot = dotProduct(l1.direction(), l2.direction());
-//
-// auto theta = acos( fabs(dot) / (mag_l1 * mag_l2));
-// return RadianceToDegrees(theta);
-//}
-
-//float rez::AngleLines3D(const Line& l1, const Line& l2)
-//{
-// auto mag_l1 = l1.direction().magnitude();
-// auto mag_l2 = l2.direction().magnitude();
-// auto dot = dotProduct(l1.direction(), l2.direction());
-//
-// auto theta = acos(fabs(dot) / (mag_l1 * mag_l2));
-// return RadianceToDegrees(theta);
-//}
-
-//float rez::AngleLinePlane(const Line& l, const Planef p)
-//{
-// auto dot = dotProduct(l.direction(), p.getNormal());
-// auto theta = acos(fabs(dot));
-// theta = RadianceToDegrees(theta);
-// return 90- theta;
-//}
-
-using namespace rez;
-
-template
-static float getAngle(rez::Vector v1, rez::Vector v2)
-{
- auto dot = dotProduct(v1, v2);
- auto theta = acos(fabs(dot));
- return RadianceToDegrees(theta);
-}
-
-float rez::AngleLines2D(const Line2d& l1, const Line2d l2)
-{
- return getAngle(l1.direction(), l2.direction());
-}
-
-float rez::AngleLines3D(const Line& l1, const Line& l2)
-{
- return getAngle(l1.direction(), l2.direction());
-}
-
-float rez::AngleLinePlane(const Line& l, const Planef p)
-{
- auto theta = getAngle(l.direction(), p.getNormal());
- return 90 - theta;
-}
-
-float rez::AnglePlanes(const Planef p1, const Planef p2)
-{
- return getAngle(p1.getNormal(), p2.getNormal());
-}
+//
+// Created by Ryan.Zurrin001 on 12/16/2021.
+//
+#include
+
+#include "Angle.h"
+
+//float rez::AngleLines2D( const Line2d& l1, const Line2d l2)
+//{
+// auto mag_l1 = l1.direction().magnitude();
+// auto mag_l2 = l2.direction().magnitude();
+// auto dot = dotProduct(l1.direction(), l2.direction());
+//
+// auto theta = acos( fabs(dot) / (mag_l1 * mag_l2));
+// return RadianceToDegrees(theta);
+//}
+
+//float rez::AngleLines3D(const Line& l1, const Line& l2)
+//{
+// auto mag_l1 = l1.direction().magnitude();
+// auto mag_l2 = l2.direction().magnitude();
+// auto dot = dotProduct(l1.direction(), l2.direction());
+//
+// auto theta = acos(fabs(dot) / (mag_l1 * mag_l2));
+// return RadianceToDegrees(theta);
+//}
+
+//float rez::AngleLinePlane(const Line& l, const Planef p)
+//{
+// auto dot = dotProduct(l.direction(), p.getNormal());
+// auto theta = acos(fabs(dot));
+// theta = RadianceToDegrees(theta);
+// return 90- theta;
+//}
+
+using namespace rez;
+
+template
+static float getAngle(rez::Vector v1, rez::Vector v2)
+{
+ auto dot = dotProduct(v1, v2);
+ auto theta = acos(fabs(dot));
+ return RadianceToDegrees(theta);
+}
+
+float rez::AngleLines2D(const Line2d& l1, const Line2d l2)
+{
+ return getAngle(l1.direction(), l2.direction());
+}
+
+float rez::AngleLines3D(const Line& l1, const Line& l2)
+{
+ return getAngle(l1.direction(), l2.direction());
+}
+
+float rez::AngleLinePlane(const Line& l, const Planef p)
+{
+ auto theta = getAngle(l.direction(), p.getNormal());
+ return 90 - theta;
+}
+
+float rez::AnglePlanes(const Planef p1, const Planef p2)
+{
+ return getAngle(p1.getNormal(), p2.getNormal());
+}
diff --git a/Angle.h b/Angle.h
index d05e23e..e727268 100644
--- a/Angle.h
+++ b/Angle.h
@@ -1,19 +1,19 @@
-//
-// Created by Ryan.Zurrin001 on 12/15/2021.
-//
-
-#ifndef PHYSICSFORMULA_ANGLE_H
-#define PHYSICSFORMULA_ANGLE_H
-#include "Line.h"
-#include "Plane.h"
-
-namespace rez {
- float AngleLines2D(const Line2d& l1, const Line2d l2);
-
- float AngleLines3D(const Line& l1, const Line& l2);
-
- float AngleLinePlane(const Line& l, const Planef p);
-
- float AnglePlanes(const Planef p1, const Planef p2);
-};
-#endif //PHYSICSFORMULA_ANGLE_H
+//
+// Created by Ryan.Zurrin001 on 12/15/2021.
+//
+
+#ifndef PHYSICSFORMULA_ANGLE_H
+#define PHYSICSFORMULA_ANGLE_H
+#include "Line.h"
+#include "Plane.h"
+
+namespace rez {
+ float AngleLines2D(const Line2d& l1, const Line2d l2);
+
+ float AngleLines3D(const Line& l1, const Line& l2);
+
+ float AngleLinePlane(const Line& l, const Planef p);
+
+ float AnglePlanes(const Planef p1, const Planef p2);
+};
+#endif //PHYSICSFORMULA_ANGLE_H
diff --git a/AtomicPhysics.h b/AtomicPhysics.h
index ac8138b..cca561b 100644
--- a/AtomicPhysics.h
+++ b/AtomicPhysics.h
@@ -1,429 +1,429 @@
-//
-// Created by Ryan.Zurrin001 on 12/15/2021.
-//
-
-#ifndef PHYSICSFORMULA_ATOMICPHYSICS_H
-#define PHYSICSFORMULA_ATOMICPHYSICS_H
-
-#include "ElectricCharge.h"
-#include "PeriodicElements.h"
-// speed of light in a vacuum is 299792458 m/s
-constexpr auto _LIGHT_SPEED_ = 2.99792458e8;//2.9979*10^8
-
-
-///
-/// the Rydberg constant is expressed for either hydrogen as R_H or at the limit
-/// of infinite nuclear mass as R_∞. In either case, the constant is used to
-/// express the limiting value of the highest wave number (inverse wavelength)
-/// of any photon that can be emitted from an atom, or, alternatively,
-/// the wave number of the lowest-energy photon capable of ionizing an atom from
-/// its ground state. The hydrogen spectral series can be expressed simply in
-/// terms of the Rydberg constant for hydrogen R_H and the Rydberg formula.
-///
-constexpr auto _RYDBERG_ = 1.09678e7;
-constexpr auto _R_H_ = _RYDBERG_;
-
-///
-/// The Bohr radius is a physical constant, equal to the most probable distance
-/// between the nucleus and the electron in a hydrogen atom in its ground state.
-/// It is named after Niels Bohr, due to its role in the Bohr model of an atom.
-/// Its value is 5.29177210903×10⁻¹¹
-///
-constexpr auto _BOHR_RADIUS_ = 5.29177210903e-11;
-constexpr auto _A_B_ = (_PLANKS_J_*_PLANKS_J_)/(4.0*(_PI_*_PI_)*_ELECTRON_MASS_*_k_*(_PROTON_CHARGE_*_PROTON_CHARGE_));
-
-///
-/// After performing an uncertainty analysis, it was found that the electron
-/// charge to mass ratio is most accurately reported as 1.71×10¹¹ ± 5.9×10^9 C/kg
-///
-constexpr auto _Q2M_E_ = _ELECTRON_CHARGE_/_ELECTRON_MASS_;
-
-///
-/// The Proton Charge to Mass ratio is 95788335.8 C/kg.
-///
-constexpr auto _Q2M_P_ = _PROTON_CHARGE_/_PROTON_MASS_;
-
-///
-/// The atomic physics object count
-///
-static int atomicPhysics_objectCount = 0;
-
-static struct HydrogenSpectralSeries
-{
- HydrogenSpectralSeries()
- {}
- HydrogenSpectralSeries(int further )
- {
- FURTHER = further;
- }
- const long double LYMAN = 1.0;
- const long double BALMER = 2.0;
- const long double PASCHEN = 3.0;
- const long double BRACKETT = 4.0;
- const long double PFUND = 5.0;
- const long double HUMPHREYS = 6.0;
- long double FURTHER = 7.0; // FURTHER >6
-
-}n_f;
-
-//α=224,ß=225,π=227,Σ=228,σ=229,µ=230,τ=231,Φ=232,Θ=233
-//Ω=234,δ=235,∞=236,φ=237,ε=238,∩=239,≡=240,Γ=226,γ, σ, ϑ, Å, Ώ, λ, γ, Δ
-/**
- * @class AtomicPhysics
- * @details class of static methods that relate to chapter 30 of the
- * open-stax college physics text book.
- * @author Ryan Zurrin
- * dateBuilt 6/8/2021
- * lastEdit 6/8/2021
- */
-class AtomicPhysics
-{
-
- long double atomPhysicsVar;
- static auto countIncrease() { atomicPhysics_objectCount += 1; }
- static auto countDecrease() { atomicPhysics_objectCount -= 1; }
-public:
- AtomicPhysics()
- {
-
- atomPhysicsVar = 0.0;
- countIncrease();
- }
-
- /**
- * @brief copy constructor
- */
- AtomicPhysics(const AtomicPhysics& t)
- {
- atomPhysicsVar = t.atomPhysicsVar;
- countIncrease();
- }
- /**
- * #brief move constructor
- */
- AtomicPhysics(AtomicPhysics&& t) noexcept
- {
- atomPhysicsVar = t.atomPhysicsVar;
- countIncrease();
- }
- /**
- * @brief copy assignment operator
- */
- AtomicPhysics& operator=(AtomicPhysics&& t) noexcept
- {
- if (this != &t)
- {
- std::swap(atomPhysicsVar, t.atomPhysicsVar);
- countIncrease();
- }
- return *this;
- }
-
- /**
- * @brief user-defined copy assignment (copy-and-swap idiom)
- */
- AtomicPhysics& operator=(AtomicPhysics other)
- {
- std::swap(atomPhysicsVar, other.atomPhysicsVar);
- return *this;
- }
-
- static void show_objectCount() { std::cout << "\n atomic physics object count: "
- << atomicPhysics_objectCount << std::endl; }
- static int get_objectCount() { return atomicPhysics_objectCount; }
-
- auto setTemplateVar(long double var) { atomPhysicsVar = var; }
- [[nodiscard]] auto getTemplateVar() const { return atomPhysicsVar; }
-
-
- ///
- /// Rutherford found the size of the nucleus to be about 10−15 m .
- /// This implied a huge density. Calculate what would this density be for some
- /// other element such as gold.
- ///
- /// The element mass.
- ///
- template
- static constexpr auto elementDensityFromNucleusSize(const T elementMass);
-
- ///
- /// In Millikan’s oil-drop experiment, one looks at a small oil drop held
- /// motionless between two plates. Take the voltage between the plates to
- /// be 2033 V, and the plate separation to be 2.00 cm. The oil drop
- /// (of density 0.81 g/cm3) has a diameter of 4.0×10−6 m . Calculate the
- /// charge on the drop, in terms of electron units
- ///
- /// The volts.
- /// The plate separation distance.
- /// The density.
- /// The diameter
- /// charge on the oil drop
- template
- static constexpr auto chargeOnDrop(const V volts, const D d, const P p, const A diameter);
-
- ///
- /// An aspiring physicist wants to build a scale model of a hydrogen atom
- /// for her science fair project. If the atom is d m in diameter,
- /// how big should she try to make the nucleus
- ///
- /// The diameter.
- /// size of nucleus on model
- template
- static constexpr auto toScale(const D d);
-
- ///
- /// calculate the wavelength within the hydrogen spectrum using the Rydberg
- /// constant and this formula. n_i and n_f are integer values where n_i is
- /// always at least one larger then n_f.
- ///
- /// positive integer larger then > n_f
- /// The positive integer associated with some series..
- /// wavelength of hydrogen spectrum element
- template
- static constexpr auto hydrogenSpectrum_wavelength(const NI n_i, const NF n_f);
-
- ///
- /// If a hydrogen atom has its electron in the n=4 state,
- /// Calculate how much energy in eV is needed to ionize it.
- ///
- /// The state.
- /// The e 0.
- ///
- template
- static constexpr auto energyToIonizedState(const N state, const E E_0);
-
- ///
- /// A hydrogen atom in an excited state can be ionized with less energy
- /// than when it is in its ground state(e_0). What is n for a hydrogen atom if
- /// 0.850 eV(e_i) of energy can ionize it
- ///
- /// The e 0.
- /// The e i.
- ///
- template
- static constexpr auto stateOfExcitedAtom(const E0 e_0, const EI e_i);
-
- ///
- /// How much energy in eV is needed to ionize the ion from this excited state?
- ///
- /// The e 0.
- /// The atomic weight or mass (z).
- /// The excited state the atom is in now.
- /// energy needed to ionize atom from excited state
- template
- static constexpr auto energyNeededToIonizeAtom(const E0 e_0, const Z z, const N n);
-
- ///
- /// Find the radius of a hydrogen atom in the n=2 state according to Bohr’s
- /// theory.
- ///
- /// The n.
- /// The z.
- ///
- template
- static constexpr auto atomRadius_nState(const N n, const Z z);
-
- ///
- /// What is the smallest-wavelength line in the Balmer series? Is it in the
- /// visible part of the spectrum?
- ///
- /// The n f.
- ///
- template
- static constexpr auto smallest_wavelength(const NF n_f);
-
- ///
- /// A wavelength of 4.653 μm is observed in a hydrogen spectrum for a
- /// transition that ends in the nf=5 level. What was ni for the initial
- /// level of the electron
- ///
- /// The theta.
- /// The n f.
- ///
- template
- static constexpr auto initialEnergyLevel(const W theta, const NF n_f);
-
- ///
- /// Atoms can be ionized by thermal collisions, such as at the high
- /// temperatures found in the solar corona. One such ion is C^+5(z), a carbon
- /// atom with only a single electron. What is the wavelength of the first
- /// line(n_f) in this ion’s Paschen series(n_i)
- ///
- /// The ground state.
- /// The atomic number z.
- /// The initial electron orbit.
- /// The final electron orbit.
- ///
- template
- static constexpr auto wavelength_nLineInIonsSeries(
- const E0 e_0, const Z z, const N n_i, const N n_f);
-
- ///
- /// Calculate the shortest-wavelength x-ray radiation that can be generated
- /// in an x-ray tube with an applied voltage of 50.0 kV(volts)
- ///
- /// The volts.
- /// shortest wavelength
- template
- static constexpr auto shortestWavelength_xRayTubeAppliedVoltage(const V volts);
-
- ///
- /// Calculate the photon energy in eV
- ///
- /// The theta.
- /// energy in eV
- template
- static constexpr auto photonEnergy_eV(const W theta);
-
- ///
- /// What are the approximate energies of the Kα x-rays for copper(z)
- ///
- /// The e 0.
- /// The z.
- /// energy of x-ray for Kα transition
- template
- static constexpr auto energyK_alphaTransition(const E0 e_0, const Z z);
-
- ///
- /// What are the approximate energies of the Kβ x-rays for copper(z)
- ///
- /// The e 0.
- /// The z.
- /// energy of x-ray for Kβ transition
- template
- static constexpr auto energyK_betaTransition(const E0 e_0, const Z z);
-
- ///
- /// A helium-neon laser is pumped by electric discharge. Calculate the wavelength
- /// the electromagnetic radiation would need to be to pump it if it was
- /// being energized by 20.61eV(volts).
- ///
- /// The energy supplied.
- /// wavelength
- template
- static constexpr auto wavelengthNeededToPumpLaserTo_evState(const E energy);
-
- ///
- /// Calculate the magnitude of the angular momentum for an l=1(l) electron.
- ///
- /// The l.
- /// magnitude of angular momentum
- template
- static constexpr auto magnitudeAngularMomentum(const L l);
-
-
-
- ~AtomicPhysics() = default;
-
-
-
-
-};
-#endif //PHYSICSFORMULA_ATOMICPHYSICS_H
-
-template
-constexpr auto AtomicPhysics::elementDensityFromNucleusSize(const T elementMass)
-{
- return elementMass / ((4.0 / 3.0) * _PI_ * (pow((1e-15/2.0), 3)));
-}
-
-template
-constexpr auto AtomicPhysics::chargeOnDrop(const V volts, const D d, const P p, const A diameter)
-{
- return ((d * _PI_ * pow(diameter, 3) * p * _Ga_) / (6.0 * volts))* (1/_PROTON_CHARGE_);
-}
-
-template
-constexpr auto AtomicPhysics::toScale(const D d)
-{
- return (d * 1e-15) / 1e-10;
-}
-
-template
-constexpr auto AtomicPhysics::hydrogenSpectrum_wavelength(const NI n_i, const NF n_f)
-{
- return 1.0 / (_RYDBERG_ * ((1.0 / (n_f * n_f)) - (1.0 / (n_i * n_i))));
-}
-
-template
-constexpr auto AtomicPhysics::energyToIonizedState(const N state, const E E_0)
-{
- return E_0 / pow(state, 2);
-}
-
-template
-constexpr auto AtomicPhysics::stateOfExcitedAtom(const E0 e_0, const EI e_i)
-{
- return sqrt(-e_0 / -e_i);
-}
-
-template
-constexpr auto AtomicPhysics::energyNeededToIonizeAtom(const E0 e_0, const Z z, const N n)
-{
-
- return -(e_0 * ((z*z)/(n*n)));
-}
-
-template
-constexpr auto AtomicPhysics::atomRadius_nState(const N n, const Z z)
-{
- return ((n * n) / z) * _A_B_;
-}
-
-template
-constexpr auto AtomicPhysics::smallest_wavelength(const NF n_f)
-{
- return (n_f * n_f) / _RYDBERG_;
-}
-
-template
-constexpr auto AtomicPhysics::initialEnergyLevel(const W theta, const NF n_f)
-{
- return n_f * sqrt((theta * _RYDBERG_) / ((_RYDBERG_ * theta) - (n_f * n_f)));
-}
-
-template
-constexpr auto AtomicPhysics::wavelength_nLineInIonsSeries(const E0 e_0, const Z z, const N n_i, const N n_f)
-{
- auto E_i = energyNeededToIonizeAtom(e_0, z, n_i);
- auto E_f = energyNeededToIonizeAtom(e_0, z, n_f);
- return _PLANKS_C_ / (E_i - E_f);
-}
-
-template
-constexpr auto AtomicPhysics::shortestWavelength_xRayTubeAppliedVoltage(const V volts)
-{
- return (_PLANKS_J_*_LIGHT_SPEED_) / (_PROTON_CHARGE_ * volts);
-}
-
-template
-constexpr auto AtomicPhysics::photonEnergy_eV(const W theta)
-{
- return _PLANKS_C_ / theta;
-}
-
-template
-constexpr auto AtomicPhysics::energyK_alphaTransition(const E0 e_0, const Z z)
-{
- return e_0 * (z * z) * (1.0 - (1.0 / (2.0 * 2.0)));
-}
-
-template
-constexpr auto AtomicPhysics::energyK_betaTransition(const E0 e_0, const Z z)
-{
- return e_0 * (z * z) * (1.0 - (1.0 / (3.0 * 3.0)));
-}
-
-template
-constexpr auto AtomicPhysics::wavelengthNeededToPumpLaserTo_evState(const E energy)
-{
- return _PLANKS_C_ / energy;
-}
-
-template
-constexpr auto AtomicPhysics::magnitudeAngularMomentum(const L l)
-{
- return sqrt(l * (l + 1.0)) * (_PLANKS_J_ / (2.0 * _PI_));
-}
-
-
+//
+// Created by Ryan.Zurrin001 on 12/15/2021.
+//
+
+#ifndef PHYSICSFORMULA_ATOMICPHYSICS_H
+#define PHYSICSFORMULA_ATOMICPHYSICS_H
+
+#include "ElectricCharge.h"
+#include "PeriodicElements.h"
+// speed of light in a vacuum is 299792458 m/s
+constexpr auto _LIGHT_SPEED_ = 2.99792458e8;//2.9979*10^8
+
+
+///
+/// the Rydberg constant is expressed for either hydrogen as R_H or at the limit
+/// of infinite nuclear mass as R_∞. In either case, the constant is used to
+/// express the limiting value of the highest wave number (inverse wavelength)
+/// of any photon that can be emitted from an atom, or, alternatively,
+/// the wave number of the lowest-energy photon capable of ionizing an atom from
+/// its ground state. The hydrogen spectral series can be expressed simply in
+/// terms of the Rydberg constant for hydrogen R_H and the Rydberg formula.
+///
+constexpr auto _RYDBERG_ = 1.09678e7;
+constexpr auto _R_H_ = _RYDBERG_;
+
+///
+/// The Bohr radius is a physical constant, equal to the most probable distance
+/// between the nucleus and the electron in a hydrogen atom in its ground state.
+/// It is named after Niels Bohr, due to its role in the Bohr model of an atom.
+/// Its value is 5.29177210903×10⁻¹¹
+///
+constexpr auto _BOHR_RADIUS_ = 5.29177210903e-11;
+constexpr auto _A_B_ = (_PLANKS_J_*_PLANKS_J_)/(4.0*(_PI_*_PI_)*_ELECTRON_MASS_*_k_*(_PROTON_CHARGE_*_PROTON_CHARGE_));
+
+///
+/// After performing an uncertainty analysis, it was found that the electron
+/// charge to mass ratio is most accurately reported as 1.71×10¹¹ ± 5.9×10^9 C/kg
+///
+constexpr auto _Q2M_E_ = _ELECTRON_CHARGE_/_ELECTRON_MASS_;
+
+///
+/// The Proton Charge to Mass ratio is 95788335.8 C/kg.
+///
+constexpr auto _Q2M_P_ = _PROTON_CHARGE_/_PROTON_MASS_;
+
+///
+/// The atomic physics object count
+///
+static int atomicPhysics_objectCount = 0;
+
+static struct HydrogenSpectralSeries
+{
+ HydrogenSpectralSeries()
+ {}
+ HydrogenSpectralSeries(int further )
+ {
+ FURTHER = further;
+ }
+ const long double LYMAN = 1.0;
+ const long double BALMER = 2.0;
+ const long double PASCHEN = 3.0;
+ const long double BRACKETT = 4.0;
+ const long double PFUND = 5.0;
+ const long double HUMPHREYS = 6.0;
+ long double FURTHER = 7.0; // FURTHER >6
+
+}n_f;
+
+//α=224,ß=225,π=227,Σ=228,σ=229,µ=230,τ=231,Φ=232,Θ=233
+//Ω=234,δ=235,∞=236,φ=237,ε=238,∩=239,≡=240,Γ=226,γ, σ, ϑ, Å, Ώ, λ, γ, Δ
+/**
+ * @class AtomicPhysics
+ * @details class of static methods that relate to chapter 30 of the
+ * open-stax college physics text book.
+ * @author Ryan Zurrin
+ * dateBuilt 6/8/2021
+ * lastEdit 6/8/2021
+ */
+class AtomicPhysics
+{
+
+ long double atomPhysicsVar;
+ static auto countIncrease() { atomicPhysics_objectCount += 1; }
+ static auto countDecrease() { atomicPhysics_objectCount -= 1; }
+public:
+ AtomicPhysics()
+ {
+
+ atomPhysicsVar = 0.0;
+ countIncrease();
+ }
+
+ /**
+ * @brief copy constructor
+ */
+ AtomicPhysics(const AtomicPhysics& t)
+ {
+ atomPhysicsVar = t.atomPhysicsVar;
+ countIncrease();
+ }
+ /**
+ * #brief move constructor
+ */
+ AtomicPhysics(AtomicPhysics&& t) noexcept
+ {
+ atomPhysicsVar = t.atomPhysicsVar;
+ countIncrease();
+ }
+ /**
+ * @brief copy assignment operator
+ */
+ AtomicPhysics& operator=(AtomicPhysics&& t) noexcept
+ {
+ if (this != &t)
+ {
+ std::swap(atomPhysicsVar, t.atomPhysicsVar);
+ countIncrease();
+ }
+ return *this;
+ }
+
+ /**
+ * @brief user-defined copy assignment (copy-and-swap idiom)
+ */
+ AtomicPhysics& operator=(AtomicPhysics other)
+ {
+ std::swap(atomPhysicsVar, other.atomPhysicsVar);
+ return *this;
+ }
+
+ static void show_objectCount() { std::cout << "\n atomic physics object count: "
+ << atomicPhysics_objectCount << std::endl; }
+ static int get_objectCount() { return atomicPhysics_objectCount; }
+
+ auto setTemplateVar(long double var) { atomPhysicsVar = var; }
+ [[nodiscard]] auto getTemplateVar() const { return atomPhysicsVar; }
+
+
+ ///
+ /// Rutherford found the size of the nucleus to be about 10−15 m .
+ /// This implied a huge density. Calculate what would this density be for some
+ /// other element such as gold.
+ ///
+ /// The element mass.
+ ///
+ template
+ static constexpr auto elementDensityFromNucleusSize(const T elementMass);
+
+ ///
+ /// In Millikan’s oil-drop experiment, one looks at a small oil drop held
+ /// motionless between two plates. Take the voltage between the plates to
+ /// be 2033 V, and the plate separation to be 2.00 cm. The oil drop
+ /// (of density 0.81 g/cm3) has a diameter of 4.0×10−6 m . Calculate the
+ /// charge on the drop, in terms of electron units
+ ///
+ /// The volts.
+ /// The plate separation distance.
+ /// The density.
+ /// The diameter
+ /// charge on the oil drop
+ template
+ static constexpr auto chargeOnDrop(const V volts, const D d, const P p, const A diameter);
+
+ ///
+ /// An aspiring physicist wants to build a scale model of a hydrogen atom
+ /// for her science fair project. If the atom is d m in diameter,
+ /// how big should she try to make the nucleus
+ ///
+ /// The diameter.
+ /// size of nucleus on model
+ template
+ static constexpr auto toScale(const D d);
+
+ ///
+ /// calculate the wavelength within the hydrogen spectrum using the Rydberg
+ /// constant and this formula. n_i and n_f are integer values where n_i is
+ /// always at least one larger then n_f.
+ ///
+ /// positive integer larger then > n_f
+ /// The positive integer associated with some series..
+ /// wavelength of hydrogen spectrum element
+ template
+ static constexpr auto hydrogenSpectrum_wavelength(const NI n_i, const NF n_f);
+
+ ///
+ /// If a hydrogen atom has its electron in the n=4 state,
+ /// Calculate how much energy in eV is needed to ionize it.
+ ///
+ /// The state.
+ /// The e 0.
+ ///
+ template
+ static constexpr auto energyToIonizedState(const N state, const E E_0);
+
+ ///
+ /// A hydrogen atom in an excited state can be ionized with less energy
+ /// than when it is in its ground state(e_0). What is n for a hydrogen atom if
+ /// 0.850 eV(e_i) of energy can ionize it
+ ///
+ /// The e 0.
+ /// The e i.
+ ///
+ template
+ static constexpr auto stateOfExcitedAtom(const E0 e_0, const EI e_i);
+
+ ///
+ /// How much energy in eV is needed to ionize the ion from this excited state?
+ ///
+ /// The e 0.
+ /// The atomic weight or mass (z).
+ /// The excited state the atom is in now.
+ /// energy needed to ionize atom from excited state
+ template
+ static constexpr auto energyNeededToIonizeAtom(const E0 e_0, const Z z, const N n);
+
+ ///
+ /// Find the radius of a hydrogen atom in the n=2 state according to Bohr’s
+ /// theory.
+ ///
+ /// The n.
+ /// The z.
+ ///
+ template
+ static constexpr auto atomRadius_nState(const N n, const Z z);
+
+ ///
+ /// What is the smallest-wavelength line in the Balmer series? Is it in the
+ /// visible part of the spectrum?
+ ///
+ /// The n f.
+ ///
+ template
+ static constexpr auto smallest_wavelength(const NF n_f);
+
+ ///
+ /// A wavelength of 4.653 μm is observed in a hydrogen spectrum for a
+ /// transition that ends in the nf=5 level. What was ni for the initial
+ /// level of the electron
+ ///
+ /// The theta.
+ /// The n f.
+ ///
+ template
+ static constexpr auto initialEnergyLevel(const W theta, const NF n_f);
+
+ ///
+ /// Atoms can be ionized by thermal collisions, such as at the high
+ /// temperatures found in the solar corona. One such ion is C^+5(z), a carbon
+ /// atom with only a single electron. What is the wavelength of the first
+ /// line(n_f) in this ion’s Paschen series(n_i)
+ ///
+ /// The ground state.
+ /// The atomic number z.
+ /// The initial electron orbit.
+ /// The final electron orbit.
+ ///
+ template
+ static constexpr auto wavelength_nLineInIonsSeries(
+ const E0 e_0, const Z z, const N n_i, const N n_f);
+
+ ///
+ /// Calculate the shortest-wavelength x-ray radiation that can be generated
+ /// in an x-ray tube with an applied voltage of 50.0 kV(volts)
+ ///
+ /// The volts.
+ /// shortest wavelength
+ template
+ static constexpr auto shortestWavelength_xRayTubeAppliedVoltage(const V volts);
+
+ ///
+ /// Calculate the photon energy in eV
+ ///
+ /// The theta.
+ /// energy in eV
+ template
+ static constexpr auto photonEnergy_eV(const W theta);
+
+ ///
+ /// What are the approximate energies of the Kα x-rays for copper(z)
+ ///
+ /// The e 0.
+ /// The z.
+ /// energy of x-ray for Kα transition
+ template
+ static constexpr auto energyK_alphaTransition(const E0 e_0, const Z z);
+
+ ///
+ /// What are the approximate energies of the Kβ x-rays for copper(z)
+ ///
+ /// The e 0.
+ /// The z.
+ /// energy of x-ray for Kβ transition
+ template
+ static constexpr auto energyK_betaTransition(const E0 e_0, const Z z);
+
+ ///
+ /// A helium-neon laser is pumped by electric discharge. Calculate the wavelength
+ /// the electromagnetic radiation would need to be to pump it if it was
+ /// being energized by 20.61eV(volts).
+ ///
+ /// The energy supplied.
+ /// wavelength
+ template
+ static constexpr auto wavelengthNeededToPumpLaserTo_evState(const E energy);
+
+ ///
+ /// Calculate the magnitude of the angular momentum for an l=1(l) electron.
+ ///
+ /// The l.
+ /// magnitude of angular momentum
+ template
+ static constexpr auto magnitudeAngularMomentum(const L l);
+
+
+
+ ~AtomicPhysics() = default;
+
+
+
+
+};
+#endif //PHYSICSFORMULA_ATOMICPHYSICS_H
+
+template
+constexpr auto AtomicPhysics::elementDensityFromNucleusSize(const T elementMass)
+{
+ return elementMass / ((4.0 / 3.0) * _PI_ * (pow((1e-15/2.0), 3)));
+}
+
+template
+constexpr auto AtomicPhysics::chargeOnDrop(const V volts, const D d, const P p, const A diameter)
+{
+ return ((d * _PI_ * pow(diameter, 3) * p * _Ga_) / (6.0 * volts))* (1/_PROTON_CHARGE_);
+}
+
+template
+constexpr auto AtomicPhysics::toScale(const D d)
+{
+ return (d * 1e-15) / 1e-10;
+}
+
+template
+constexpr auto AtomicPhysics::hydrogenSpectrum_wavelength(const NI n_i, const NF n_f)
+{
+ return 1.0 / (_RYDBERG_ * ((1.0 / (n_f * n_f)) - (1.0 / (n_i * n_i))));
+}
+
+template
+constexpr auto AtomicPhysics::energyToIonizedState(const N state, const E E_0)
+{
+ return E_0 / pow(state, 2);
+}
+
+template
+constexpr auto AtomicPhysics::stateOfExcitedAtom(const E0 e_0, const EI e_i)
+{
+ return sqrt(-e_0 / -e_i);
+}
+
+template
+constexpr auto AtomicPhysics::energyNeededToIonizeAtom(const E0 e_0, const Z z, const N n)
+{
+
+ return -(e_0 * ((z*z)/(n*n)));
+}
+
+template
+constexpr auto AtomicPhysics::atomRadius_nState(const N n, const Z z)
+{
+ return ((n * n) / z) * _A_B_;
+}
+
+template
+constexpr auto AtomicPhysics::smallest_wavelength(const NF n_f)
+{
+ return (n_f * n_f) / _RYDBERG_;
+}
+
+template
+constexpr auto AtomicPhysics::initialEnergyLevel(const W theta, const NF n_f)
+{
+ return n_f * sqrt((theta * _RYDBERG_) / ((_RYDBERG_ * theta) - (n_f * n_f)));
+}
+
+template
+constexpr auto AtomicPhysics::wavelength_nLineInIonsSeries(const E0 e_0, const Z z, const N n_i, const N n_f)
+{
+ auto E_i = energyNeededToIonizeAtom(e_0, z, n_i);
+ auto E_f = energyNeededToIonizeAtom(e_0, z, n_f);
+ return _PLANKS_C_ / (E_i - E_f);
+}
+
+template
+constexpr auto AtomicPhysics::shortestWavelength_xRayTubeAppliedVoltage(const V volts)
+{
+ return (_PLANKS_J_*_LIGHT_SPEED_) / (_PROTON_CHARGE_ * volts);
+}
+
+template
+constexpr auto AtomicPhysics::photonEnergy_eV(const W theta)
+{
+ return _PLANKS_C_ / theta;
+}
+
+template
+constexpr auto AtomicPhysics::energyK_alphaTransition(const E0 e_0, const Z z)
+{
+ return e_0 * (z * z) * (1.0 - (1.0 / (2.0 * 2.0)));
+}
+
+template
+constexpr auto AtomicPhysics::energyK_betaTransition(const E0 e_0, const Z z)
+{
+ return e_0 * (z * z) * (1.0 - (1.0 / (3.0 * 3.0)));
+}
+
+template
+constexpr auto AtomicPhysics::wavelengthNeededToPumpLaserTo_evState(const E energy)
+{
+ return _PLANKS_C_ / energy;
+}
+
+template
+constexpr auto AtomicPhysics::magnitudeAngularMomentum(const L l)
+{
+ return sqrt(l * (l + 1.0)) * (_PLANKS_J_ / (2.0 * _PI_));
+}
+
+
diff --git a/BinarySearchTree.h b/BinarySearchTree.h
index 804e7d1..2667fa9 100644
--- a/BinarySearchTree.h
+++ b/BinarySearchTree.h
@@ -1,373 +1,373 @@
-//
-// Created by Ryan.Zurrin001 on 12/15/2021.
-//
-
-#ifndef PHYSICSFORMULA_BINARYSEARCHTREE_H
-#define PHYSICSFORMULA_BINARYSEARCHTREE_H
-// TODO Implement the BST, Braided Search tree and Randomized Search tree as well
-
-#include
-#include
-#include
-#include
-using namespace std;
-
-
-namespace rez {
-
- template< class KType, class VType, class Compare = std::less>
- class BST {
-
- struct BSTNode {
- KType key = {};
- VType value = {};
- BSTNode* left = nullptr;
- BSTNode* right = nullptr;
- BSTNode* parent = nullptr;
-
- public:
- BSTNode() {}
-
- BSTNode(KType& _key, VType& _value, BSTNode* _left = nullptr, BSTNode* _right = nullptr, BSTNode* _parent = nullptr) :
- key(_key), value(_value), left(_left), right(_right), parent(_parent) {}
- };
-
- BSTNode* root = nullptr;
- Compare comp;
-
- BSTNode* find(KType& _key);
- void transplant(BSTNode* u, BSTNode* v);
- BSTNode* treeMin(BSTNode* branch_root);
- BSTNode* treeMax(BSTNode* branch_root);
- BSTNode* findSplitNode(KType& _min, KType& _max);
- bool isLeaf(BSTNode* _node);
- void addTreeToAList(BSTNode* _node, std::list&, bool addFront = false);
-
- public:
- BST(KType& _key, VType& _value) {
- root = new BSTNode(_key, _value);
- }
-
- BST(std::list>& _data, const unsigned int _root_index = 0) {
- root = new BSTNode(_data[_root_index].first, _data[_root_index].second);
- for (size_t i = 0; i < _data.size(); i++) {
- if (i != _root_index) {
- insert(_data[i]);
- }
- }
- }
-
- void insert(const KType& _value);
- void insert(std::list&);
- void remove(const KType& _value);
- void find(const KType&, const KType&, std::list&);
- std::pair predecessor(const KType& _value);
- std::pair successor(const KType& _value);
-
- std::pair minimum(BSTNode* _node = nullptr);
- std::pair maximum(BSTNode* _node = nullptr);
- bool isEmpty() {
- if (root)
- return true;
- return false;
- }
-
- void inOrderTraverse(BSTNode*, std::list&);
- void inOrderTraverse();
- void inOrderHelper(BSTNode* root);
- void preOrderTraverse(BSTNode*, std::list&);
- void postOrderTraverse(BSTNode*, std::list&);
- };
-#endif //PHYSICSFORMULA_BINARYSEARCHTREE_H
-
-
- template
- typename BST::BSTNode* BST::find(KType& _key) {
- BSTNode* current = root;
- while (current && current->key != _key) {
- if (comp(current->key, _key))
- current = current->right_child;
- else
- current = current->left_child;
- }
-
- // Given key is not found in this tree
- return current;
- }
-
- template
- void BST::transplant(BSTNode* u, BSTNode* v)
- {
- if (!u->parent)
- root = v;
- else if (u == u->parent->left_child)
- u->parent->left_child = v;
- else
- u->parent->right_child = v;
-
- if (v)
- v->parent = u->parent;
- }
-
- template
- typename BST::BSTNode* BST::treeMin(BSTNode* _branch_root)
- {
- BSTNode* temp_node = _branch_root;
- while (temp_node && temp_node->left_child) {
- temp_node = temp_node->left_child;
- }
- temp_node;
- }
-
- template
- typename BST::BSTNode* BST::treeMax(BSTNode* _branch_root) {
- BSTNode* temp_node = _branch_root;
- while (temp_node && temp_node->right_child) {
- temp_node = temp_node->right_child;
- }
-
- return temp_node;
- }
-
- template
- typename BST::BSTNode* BST::findSplitNode(KType& _min, KType& _max) {
- auto v = root;
- while (!isLeaf(v) && (_max <= v->key || _min > v->key)) {
- if (_max <= v->key)
- v = v->left;
- else
- v = v->right;
- }
- return v;
- }
-
- template
- bool BST::isLeaf(BSTNode* _node)
- {
- if (_node && _node->left && _node->right)
- return true;
- return false;
- }
-
- template
- void BST::addTreeToAList(BSTNode* _node, std::list& _list, bool addFront) {
- std::list values;
- inOrderTravers(_node, values);
- if (addFront)
- _list.insert(_list.begin(), values.begin(), values.end());
- else
- _list.insert(_list.end(), values.begin(), values.end());
- }
-
- template
- void BST::insert(const KType& _value) {
- if (!root) {
- root = new BSTNode(_value);
- return;
- }
- else {
- BSTNode* temp = root;
- while (true) {
- if (comp(temp->key, _value)) {
- if (temp->left)
- temp = temp->left;
- else {
- temp->left = new BSTNode(_value);
- temp->left->parent = temp;
- break;
- }
- }
- else {
- if (temp->right)
- temp = temp->right;
- else {
- temp->right = new BSTNode(_value);
- temp->right->parent = temp;
- break;
- }
- }
- }
- }
- }
-
- template
- void BST::insert(std::list& _list) {
- for (const auto& key : _list) {
- insert(key);
- }
- }
-
- template
- void BST::remove(const KType& _value) {
- BSTNode* current_node = find(_value);
-
- if (current_node) {
- BSTNode* current_left = current_node->left_child;
- BSTNode* current_right = current_node->right_child;
-
- if (isLeaf(current_node))
- transplant(current_node, nullptr);
-
- if (!current_left) {
- transplant(current_node, current_right);
- }
- else if (!current_right) {
- transplant(current_node, current_left);
- }
- else {
- BSTNode* right_min = treeMin(current_right);
- if (right_min->parent != current_node) {
- transplant(right_min, right_min->right_child);
- right_min->right_child = current_node->right_child;
- right_min->right_child->parent = right_min;
- }
-
- transplant(current_node, right_min);
- right_min->left_child = current_node->left_child;
- right_min->left_child->parent = right_min;
- }
- }
- }
-
- template
- void BST::find(const KType& _min, const KType& _max, std::list& _list)
- {
- auto v_split = findSplitNode(_min, _max);
- if (isLeaf(v_split)) {
- if (v_split->key >= _min && v_split->key < _max)
- _list.insert(_list.push_front(v_split->key));
- }
- else {
- //Follow the path to left boundary
- auto v = v_split->left;
- while (!isLeaf(v)) {
- if (_min <= v->key) {
- addTreeToAList(v->right, _list, true);
- _list.push_front(v->key);
- v = v->left;
- }
- else
- v = v->right;
- }
- if (v->key >= _min)
- _list.insert(_list.push_front(v->key));
-
- v = v_split->right;
- while (!isLeaf(v)) {
- if (_max >= v->key) {
- addTreeToAList(v->left, _list);
- v = v->right;
- }
- else
- v = v->left;
- }
- if (v->key <= _max)
- _list.insert(_list.push_back(v->key));
- }
- }
-
- template
- std::pair BST::predecessor(const KType& _value) {
- //BSTNode* current_node = find(_value);
- //if (current_node){
- // BSTNode* max_left = nullptr;
- // max_left = treeMax(current_node->left_child);
- // if (max_left)
- // return max_left->key;
- // else {
- // auto parent = current_node->parent;
- // while (parent && parent->parent){
- // parent = parent->parent;
- // if (parent->left)
- // return parent->key;
- // }
- // }
- //}
- //return _value;
- }
-
- template
- std::pair BST::successor(const KType& _value) {
- //BSTNode* current_node = find(_value);
- //if (current_node){
- // BSTNode* min_right = nullptr;
- // min_right = treeMax(current_node->right_child);
- // if (min_right)
- // return min_right->key;
- // else {
- // auto parent = current_node->parent;
- // while (parent && parent->parent) {
- // parent = parent->parent;
- // if (parent->right)
- // return parent->key;
- // }
- // }
- //}
- //return _value;
- }
-
- template
- void BST::inOrderTraverse(BSTNode* _node, std::list& _list) {
- if (!_node)
- return;
- inOrderTravers(_node->left, _list);
- _list.push_back(_node->value);
- inOrderTravers(_node->right, _list);
- }
-
- template
- inline void BST::inOrderTraverse()
- {
- BSTNode* curr = root;
- if (!curr)
- return;
- inOrderHelper(curr);
- }
-
- template
- inline void BST::inOrderHelper(BSTNode* root)
- {
- inOrderHelper(root->left);
- std::cout << root->key << " ";
- inOrderHelper(root->right);
- }
-
- template
- void BST::preOrderTraverse(BSTNode* _node, std::list& _list) {
- if (!_node)
- return;
- _list.push_back(_node->value);
- inOrderTravers(_node->left, _list);
- inOrderTravers(_node->right, _list);
- }
-
- template
- void BST::postOrderTraverse(BSTNode* _node, std::list& _list) {
- if (!_node)
- return;
- inOrderTravers(_node->left, _list);
- inOrderTravers(_node->right, _list);
- _list.push_back(_node->value);
- }\
-
- template
- std::pair BST::minimum(BSTNode* _node) {
- if (!_node)
- _node = root;
- auto temp = _node;
- while (temp->left)
- temp = temp->left;
- return std::pair(temp->key, temp->value);
- }
-
- template
- std::pair BST::maximum(BSTNode* _node) {
- if (!_node)
- _node = root;
- auto temp = _node;
- while (temp->right)
- temp = temp->right;
- return std::pair(temp->key, temp->value);
- }
-}
-
+//
+// Created by Ryan.Zurrin001 on 12/15/2021.
+//
+
+#ifndef PHYSICSFORMULA_BINARYSEARCHTREE_H
+#define PHYSICSFORMULA_BINARYSEARCHTREE_H
+// TODO Implement the BST, Braided Search tree and Randomized Search tree as well
+
+#include
+#include
+#include
+#include
+using namespace std;
+
+
+namespace rez {
+
+ template< class KType, class VType, class Compare = std::less>
+ class BST {
+
+ struct BSTNode {
+ KType key = {};
+ VType value = {};
+ BSTNode* left = nullptr;
+ BSTNode* right = nullptr;
+ BSTNode* parent = nullptr;
+
+ public:
+ BSTNode() {}
+
+ BSTNode(KType& _key, VType& _value, BSTNode* _left = nullptr, BSTNode* _right = nullptr, BSTNode* _parent = nullptr) :
+ key(_key), value(_value), left(_left), right(_right), parent(_parent) {}
+ };
+
+ BSTNode* root = nullptr;
+ Compare comp;
+
+ BSTNode* find(KType& _key);
+ void transplant(BSTNode* u, BSTNode* v);
+ BSTNode* treeMin(BSTNode* branch_root);
+ BSTNode* treeMax(BSTNode* branch_root);
+ BSTNode* findSplitNode(KType& _min, KType& _max);
+ bool isLeaf(BSTNode* _node);
+ void addTreeToAList(BSTNode* _node, std::list&, bool addFront = false);
+
+ public:
+ BST(KType& _key, VType& _value) {
+ root = new BSTNode(_key, _value);
+ }
+
+ BST(std::list>& _data, const unsigned int _root_index = 0) {
+ root = new BSTNode(_data[_root_index].first, _data[_root_index].second);
+ for (size_t i = 0; i < _data.size(); i++) {
+ if (i != _root_index) {
+ insert(_data[i]);
+ }
+ }
+ }
+
+ void insert(const KType& _value);
+ void insert(std::list&);
+ void remove(const KType& _value);
+ void find(const KType&, const KType&, std::list&);
+ std::pair predecessor(const KType& _value);
+ std::pair successor(const KType& _value);
+
+ std::pair minimum(BSTNode* _node = nullptr);
+ std::pair maximum(BSTNode* _node = nullptr);
+ bool isEmpty() {
+ if (root)
+ return true;
+ return false;
+ }
+
+ void inOrderTraverse(BSTNode*, std::list&);
+ void inOrderTraverse();
+ void inOrderHelper(BSTNode* root);
+ void preOrderTraverse(BSTNode*, std::list&);
+ void postOrderTraverse(BSTNode*, std::list&);
+ };
+#endif //PHYSICSFORMULA_BINARYSEARCHTREE_H
+
+
+ template
+ typename BST::BSTNode* BST::find(KType& _key) {
+ BSTNode* current = root;
+ while (current && current->key != _key) {
+ if (comp(current->key, _key))
+ current = current->right_child;
+ else
+ current = current->left_child;
+ }
+
+ // Given key is not found in this tree
+ return current;
+ }
+
+ template
+ void BST::transplant(BSTNode* u, BSTNode* v)
+ {
+ if (!u->parent)
+ root = v;
+ else if (u == u->parent->left_child)
+ u->parent->left_child = v;
+ else
+ u->parent->right_child = v;
+
+ if (v)
+ v->parent = u->parent;
+ }
+
+ template
+ typename BST::BSTNode* BST::treeMin(BSTNode* _branch_root)
+ {
+ BSTNode* temp_node = _branch_root;
+ while (temp_node && temp_node->left_child) {
+ temp_node = temp_node->left_child;
+ }
+ temp_node;
+ }
+
+ template
+ typename BST::BSTNode* BST::treeMax(BSTNode* _branch_root) {
+ BSTNode* temp_node = _branch_root;
+ while (temp_node && temp_node->right_child) {
+ temp_node = temp_node->right_child;
+ }
+
+ return temp_node;
+ }
+
+ template
+ typename BST::BSTNode* BST::findSplitNode(KType& _min, KType& _max) {
+ auto v = root;
+ while (!isLeaf(v) && (_max <= v->key || _min > v->key)) {
+ if (_max <= v->key)
+ v = v->left;
+ else
+ v = v->right;
+ }
+ return v;
+ }
+
+ template
+ bool BST::isLeaf(BSTNode* _node)
+ {
+ if (_node && _node->left && _node->right)
+ return true;
+ return false;
+ }
+
+ template
+ void BST::addTreeToAList(BSTNode* _node, std::list& _list, bool addFront) {
+ std::list values;
+ inOrderTravers(_node, values);
+ if (addFront)
+ _list.insert(_list.begin(), values.begin(), values.end());
+ else
+ _list.insert(_list.end(), values.begin(), values.end());
+ }
+
+ template
+ void BST::insert(const KType& _value) {
+ if (!root) {
+ root = new BSTNode(_value);
+ return;
+ }
+ else {
+ BSTNode* temp = root;
+ while (true) {
+ if (comp(temp->key, _value)) {
+ if (temp->left)
+ temp = temp->left;
+ else {
+ temp->left = new BSTNode(_value);
+ temp->left->parent = temp;
+ break;
+ }
+ }
+ else {
+ if (temp->right)
+ temp = temp->right;
+ else {
+ temp->right = new BSTNode(_value);
+ temp->right->parent = temp;
+ break;
+ }
+ }
+ }
+ }
+ }
+
+ template
+ void BST::insert(std::list& _list) {
+ for (const auto& key : _list) {
+ insert(key);
+ }
+ }
+
+ template
+ void BST::remove(const KType& _value) {
+ BSTNode* current_node = find(_value);
+
+ if (current_node) {
+ BSTNode* current_left = current_node->left_child;
+ BSTNode* current_right = current_node->right_child;
+
+ if (isLeaf(current_node))
+ transplant(current_node, nullptr);
+
+ if (!current_left) {
+ transplant(current_node, current_right);
+ }
+ else if (!current_right) {
+ transplant(current_node, current_left);
+ }
+ else {
+ BSTNode* right_min = treeMin(current_right);
+ if (right_min->parent != current_node) {
+ transplant(right_min, right_min->right_child);
+ right_min->right_child = current_node->right_child;
+ right_min->right_child->parent = right_min;
+ }
+
+ transplant(current_node, right_min);
+ right_min->left_child = current_node->left_child;
+ right_min->left_child->parent = right_min;
+ }
+ }
+ }
+
+ template
+ void BST::find(const KType& _min, const KType& _max, std::list& _list)
+ {
+ auto v_split = findSplitNode(_min, _max);
+ if (isLeaf(v_split)) {
+ if (v_split->key >= _min && v_split->key < _max)
+ _list.insert(_list.push_front(v_split->key));
+ }
+ else {
+ //Follow the path to left boundary
+ auto v = v_split->left;
+ while (!isLeaf(v)) {
+ if (_min <= v->key) {
+ addTreeToAList(v->right, _list, true);
+ _list.push_front(v->key);
+ v = v->left;
+ }
+ else
+ v = v->right;
+ }
+ if (v->key >= _min)
+ _list.insert(_list.push_front(v->key));
+
+ v = v_split->right;
+ while (!isLeaf(v)) {
+ if (_max >= v->key) {
+ addTreeToAList(v->left, _list);
+ v = v->right;
+ }
+ else
+ v = v->left;
+ }
+ if (v->key <= _max)
+ _list.insert(_list.push_back(v->key));
+ }
+ }
+
+ template
+ std::pair BST::predecessor(const KType& _value) {
+ //BSTNode* current_node = find(_value);
+ //if (current_node){
+ // BSTNode* max_left = nullptr;
+ // max_left = treeMax(current_node->left_child);
+ // if (max_left)
+ // return max_left->key;
+ // else {
+ // auto parent = current_node->parent;
+ // while (parent && parent->parent){
+ // parent = parent->parent;
+ // if (parent->left)
+ // return parent->key;
+ // }
+ // }
+ //}
+ //return _value;
+ }
+
+ template
+ std::pair BST::successor(const KType& _value) {
+ //BSTNode* current_node = find(_value);
+ //if (current_node){
+ // BSTNode* min_right = nullptr;
+ // min_right = treeMax(current_node->right_child);
+ // if (min_right)
+ // return min_right->key;
+ // else {
+ // auto parent = current_node->parent;
+ // while (parent && parent->parent) {
+ // parent = parent->parent;
+ // if (parent->right)
+ // return parent->key;
+ // }
+ // }
+ //}
+ //return _value;
+ }
+
+ template
+ void BST::inOrderTraverse(BSTNode* _node, std::list& _list) {
+ if (!_node)
+ return;
+ inOrderTravers(_node->left, _list);
+ _list.push_back(_node->value);
+ inOrderTravers(_node->right, _list);
+ }
+
+ template
+ inline void BST::inOrderTraverse()
+ {
+ BSTNode* curr = root;
+ if (!curr)
+ return;
+ inOrderHelper(curr);
+ }
+
+ template
+ inline void BST::inOrderHelper(BSTNode* root)
+ {
+ inOrderHelper(root->left);
+ std::cout << root->key << " ";
+ inOrderHelper(root->right);
+ }
+
+ template
+ void BST::preOrderTraverse(BSTNode* _node, std::list& _list) {
+ if (!_node)
+ return;
+ _list.push_back(_node->value);
+ inOrderTravers(_node->left, _list);
+ inOrderTravers(_node->right, _list);
+ }
+
+ template
+ void BST::postOrderTraverse(BSTNode* _node, std::list& _list) {
+ if (!_node)
+ return;
+ inOrderTravers(_node->left, _list);
+ inOrderTravers(_node->right, _list);
+ _list.push_back(_node->value);
+ }\
+
+ template
+ std::pair BST::minimum(BSTNode* _node) {
+ if (!_node)
+ _node = root;
+ auto temp = _node;
+ while (temp->left)
+ temp = temp->left;
+ return std::pair(temp->key, temp->value);
+ }
+
+ template
+ std::pair BST::maximum(BSTNode* _node) {
+ if (!_node)
+ _node = root;
+ auto temp = _node;
+ while (temp->right)
+ temp = temp->right;
+ return std::pair(temp->key, temp->value);
+ }
+}
+
diff --git a/BinarySpacePartition.h b/BinarySpacePartition.h
index cae6105..5ca5820 100644
--- a/BinarySpacePartition.h
+++ b/BinarySpacePartition.h
@@ -1,328 +1,328 @@
-//
-// Created by Ryan.Zurrin001 on 12/15/2021.
-//
-
-#ifndef PHYSICSFORMULA_BINARYSPACEPARTITION_H
-#define PHYSICSFORMULA_BINARYSPACEPARTITION_H
-#pragma once
-
-#include "Core.h"
-#include "Vector.h"
-#include "Line.h"
-#include "Point.h"
-#include "GeoUtils.h"
-#include "Intersection.h"
-
-#include
-#include
-#include
-
-namespace rez {
-#define MIN_ELEMENTS_PER_PARTITION 4
-
- enum class SEG_TYPES {
- POSITIVE,
- NEGATIVE,
- INTERSECT
- };
-
- //TODO : Remove this class asap
- class BSP2D {
- struct BSP2DNode {
- BSP2DNode* neg = nullptr;
- BSP2DNode* pos = nullptr;
- rez::Line2dStd split_line;
- std::vector points_list;
-
- BSP2DNode(std::vector _points) : points_list(_points) {
- }
-
- BSP2DNode(rez::Line2dStd _line,
- BSP2DNode* _neg = nullptr, BSP2DNode* _pos = nullptr)
- : split_line(_line), neg(_neg), pos(_pos) {
- }
-
- BSP2DNode(std::vector _points, rez::Line2dStd _line,
- BSP2DNode* _neg = nullptr, BSP2DNode* _pos = nullptr)
- : points_list(_points), split_line(_line), neg(_neg), pos(_pos)
- {}
- };
-
- BSP2DNode* root = nullptr;
-
- rez::Line2dStd getSplitLine(std::vector& _points_list, rez::Line2dStd* _prev_line);
-
- bool isALeaf(BSP2DNode* _node);
-
- BSP2DNode* constructBSP2D(std::vector& _points_list, rez::Line2dStd* _prev_line);
-
- void getSplitLineList(BSP2DNode* _node, std::vector& _points_list);
-
- public:
- BSP2D(std::vector& _points_list) {
- root = constructBSP2D(_points_list, nullptr);
- }
-
- void getSplitLines(std::vector& _lines_list);
- };
-
-#endif //PHYSICSFORMULA_BINARYSPACEPARTITION_H
-
- bool BSP2D::isALeaf(BSP2DNode* _node)
- {
- if (_node && (_node->neg || _node->pos))
- return false;
- return true;
- }
-
- rez::Line2dStd BSP2D::getSplitLine(std::vector& _points_list, rez::Line2dStd* _prev_line)
- {
- const uint32_t size = _points_list.size();
- std::sort(_points_list.begin(), _points_list.end());
- rez::Point2d p1, p2;
- rez::Line2dStd line;
-
- if (!_prev_line) {
- p1.assign(X, (_points_list[0][X] + _points_list[1][X]) / 2);
- p1.assign(Y, (_points_list[0][Y] + _points_list[1][Y]) / 2);
- p2.assign(X, (_points_list[size - 1][X] + _points_list[size - 2][X]) / 2);
- p2.assign(Y, (_points_list[size - 1][Y] + _points_list[size - 2][Y]) / 2);
- line = rez::Line2dStd(p1, p2, true);
- }
- else if (false) {
-
- float nxy = 0.0, x_sum = 0.0, y_sum = 0.0, n_x_sqr_sum = 0.0;
-
- for (const auto& point : _points_list)
- {
- nxy += point[X] * point[Y];
- x_sum += point[X];
- y_sum += point[Y];
- n_x_sqr_sum += x_sum * x_sum;
- }
-
- nxy *= size;
- n_x_sqr_sum *= size;
-
- auto slope = (nxy - (x_sum) * (y_sum)) / (n_x_sqr_sum - x_sum * x_sum);
- auto intercept = (size * y_sum - slope * x_sum) / size;
-
- srand((unsigned)time(0));
- auto s = rand() % 50;
- s /= 25.0;
- p2.assign(X, -slope * s);
- p2.assign(Y, 1 + s);
-
- line = rez::Line2dStd(p1, p2, false);
- }
- else {
- float x_sum = 0.0, y_sum = 0.0;
- for (const auto& point : _points_list)
- {
- x_sum += point[X];
- y_sum += point[Y];
- }
- p1.assign(X, x_sum / size);
- p1.assign(Y, y_sum / size);
-
- p2.assign(X, -_prev_line->getDir()[Y] + 0.2);
- p2.assign(Y, _prev_line->getDir()[X] + 0.2);
-
- line = rez::Line2dStd(p1, p2, false);
- }
-
- Vector2f normal(-line.getDir()[Y], line.getDir()[X]);
- auto d = dotProduct(normal, p2);
- line.setD(d);
- return line;
- }
-
- BSP2D::BSP2DNode* BSP2D::constructBSP2D(std::vector& _points_list,
- rez::Line2dStd* _prev_line)
- {
- const uint32_t size = _points_list.size();
- if (size <= MIN_ELEMENTS_PER_PARTITION) {
-
- return new BSP2DNode(_points_list);
- }
- rez::Line2dStd split_line = getSplitLine(_points_list, _prev_line);
-
- std::vector pos_vec;
- std::vector neg_vec;
-
- std::copy_if(_points_list.begin(), _points_list.end(),
- std::back_inserter(neg_vec),
- [&](const rez::Point2d& point)
- {
- return rez::left(split_line, point);
- });
-
- std::copy_if(_points_list.begin(), _points_list.end(),
- std::back_inserter(pos_vec),
- [&](const rez::Point2d& point)
- {
- return !rez::left(split_line, point);
- });
-
- auto left = constructBSP2D(neg_vec, &split_line);
- auto right = constructBSP2D(pos_vec, &split_line);
-
- return new BSP2DNode(split_line, left, right);
- }
-
- void BSP2D::getSplitLineList(BSP2DNode* _node, std::vector& _lines_list)
- {
- if (!isALeaf(_node)) {
- _lines_list.push_back(_node->split_line);
- getSplitLineList(_node->neg, _lines_list);
- getSplitLineList(_node->pos, _lines_list);
- }
- }
-
- void BSP2D::getSplitLines(std::vector& _lines_list) {
- getSplitLineList(root, _lines_list);
- }
-
- class BSP2DSegments {
- struct BSP2DSegNode {
- BSP2DSegNode* neg = nullptr;
- BSP2DSegNode* pos = nullptr;
- rez::Line2d split_line;
- rez::Segment2d segment;
-
- BSP2DSegNode(rez::Segment2d _segment) : segment(_segment) {
- }
-
- BSP2DSegNode(rez::Line2d _line,
- BSP2DSegNode* _neg = nullptr, BSP2DSegNode* _pos = nullptr)
- : split_line(_line), neg(_neg), pos(_pos) {
- }
-
- BSP2DSegNode(rez::Segment2d _segment, rez::Line2d _line,
- BSP2DSegNode* _neg = nullptr, BSP2DSegNode* _pos = nullptr)
- : segment(_segment), split_line(_line), neg(_neg), pos(_pos)
- {}
- };
-
- BSP2DSegNode* constructBSP2D(std::vector& _seg_list);
- rez::Line2d getSplitLine(std::vector& _seg_list, int& _index);
- SEG_TYPES classifySegmenetToLine(rez::Segment2d& _seg, rez::Line2d& _line, rez::Segment2d& _pos_seg,
- rez::Segment2d& _neg_seg);
-
- BSP2DSegNode* root;
-
- void printNode(BSP2DSegNode*, int depth);
-
- public:
- BSP2DSegments(std::vector& _segment_list) {
- root = constructBSP2D(_segment_list);
- }
-
- void print();
- };
-
- BSP2DSegments::BSP2DSegNode* rez::BSP2DSegments::constructBSP2D(std::vector& _seg_list)
- {
- int size = _seg_list.size();
- if (size > 1) {
- int split_seg_index = -1;
- std::vector pos_list, neg_list;
- rez::Segment2d pos_seg, neg_seg;
- rez::Line2d split_line = getSplitLine(_seg_list, split_seg_index);
-
- for (size_t i = 0; i < size; i++) {
- if (i != split_seg_index) {
- switch (classifySegmenetToLine(_seg_list[i], split_line, pos_seg, neg_seg))
- {
- case SEG_TYPES::INTERSECT:
- pos_list.push_back(pos_seg);
- neg_list.push_back(neg_seg);
- break;
- case SEG_TYPES::POSITIVE:
- pos_list.push_back(pos_seg);
- break;
- default:
- neg_list.push_back(pos_seg);
- break;
- }
- }
- }
-
- BSP2DSegNode* left = constructBSP2D(pos_list);
- BSP2DSegNode* right = constructBSP2D(neg_list);
- return new BSP2DSegNode(_seg_list[split_seg_index], split_line, left, right);
- }
- }
-
- inline rez::Line2d BSP2DSegments::getSplitLine(std::vector& _seg_list, int& _index)
- {
- int min_intersections = INT_MAX;
- Line2d min_intersect_line;
-
- for (size_t i = 0; i < _seg_list.size(); i++) {
- auto seg = _seg_list[i];
- Vector2f dir = seg.p2 - seg.p1;
- Line2d line(seg.p1, dir);
- int this_intersections = 0;
-
- for (size_t j = 0; j < _seg_list.size(); j++) {
- if (i != j)
- if (rez::intersect(line, _seg_list[j]))
- this_intersections++;
- }
-
- if (this_intersections < min_intersections) {
- min_intersect_line = line;
- _index = i;
- }
- }
- return min_intersect_line;
- }
-
- inline SEG_TYPES BSP2DSegments::classifySegmenetToLine(rez::Segment2d& _seg, rez::Line2d& _line,
- rez::Segment2d& _pos_seg, rez::Segment2d& _neg_seg)
- {
- rez::Point2d intersect_point;
- bool is_intersect = rez::intersect(_line, _seg, intersect_point);
- if (is_intersect) {
- if (left(_line, _seg.p1)) {
- _pos_seg.p1 = _seg.p1;
- _pos_seg.p2 = intersect_point;
- _neg_seg.p1 = intersect_point;
- _neg_seg.p2 = _seg.p2;
- }
- else {
- _pos_seg.p1 = _seg.p2;
- _pos_seg.p2 = intersect_point;
- _neg_seg.p1 = intersect_point;
- _neg_seg.p2 = _seg.p1;
- }
- return SEG_TYPES::INTERSECT;
- }
- else if (left(_line, _seg.p1)) {
- return SEG_TYPES::POSITIVE;
- }
-
- return SEG_TYPES::NEGATIVE;
- }
-
- void BSP2DSegments::printNode(BSP2DSegNode* _node, int depth) {
- if (!_node)
- return;
-
- printNode(_node->pos, depth + 1);
-
- int space = 0;
- while (space < depth)
- std::cout << " ";
- std::cout << "< (" << _node->segment.p1[X] << "," << _node->segment.p1[Y] << ") - ("
- << _node->segment.p2[X] << "," << _node->segment.p2[Y] << ")\n";
-
- printNode(_node->neg, depth + 1);
- }
-
- void BSP2DSegments::print() {
- printNode(root, 0);
- }
-}
-
+//
+// Created by Ryan.Zurrin001 on 12/15/2021.
+//
+
+#ifndef PHYSICSFORMULA_BINARYSPACEPARTITION_H
+#define PHYSICSFORMULA_BINARYSPACEPARTITION_H
+#pragma once
+
+#include "Core.h"
+#include "Vector.h"
+#include "Line.h"
+#include "Point.h"
+#include "GeoUtils.h"
+#include "Intersection.h"
+
+#include
+#include
+#include
+
+namespace rez {
+#define MIN_ELEMENTS_PER_PARTITION 4
+
+ enum class SEG_TYPES {
+ POSITIVE,
+ NEGATIVE,
+ INTERSECT
+ };
+
+ //TODO : Remove this class asap
+ class BSP2D {
+ struct BSP2DNode {
+ BSP2DNode* neg = nullptr;
+ BSP2DNode* pos = nullptr;
+ rez::Line2dStd split_line;
+ std::vector points_list;
+
+ BSP2DNode(std::vector _points) : points_list(_points) {
+ }
+
+ BSP2DNode(rez::Line2dStd _line,
+ BSP2DNode* _neg = nullptr, BSP2DNode* _pos = nullptr)
+ : split_line(_line), neg(_neg), pos(_pos) {
+ }
+
+ BSP2DNode(std::vector