To determine that the geometry of the universe is flat, the physical size of sound waves $S$ at the surface of last scattering was found to match their predictedtheoretical size of 431,700 light-years (0.13236 megaparsecs). To perform this calculation both the angular size $\theta$ of the sound waves and their angular diameter distance $D$ was used, which can be demonstrated as follows:
$S = (\theta*D$) = $0.010414$ radians (0.5967 degrees) * $12.71 Mpc$ = $0.13236$ Mpc $(431,700$ $light-years)$
To make this calculation you need to know the angular diameter distance $D$, which itself is obtained from the following: $D=\frac{1}{1+z}\int_0^z \frac{cdz'}{H(z')}$.
However, solving this integral requires understanding the universe's expansion history, which depends on its shape and therefore its matter and energy composition—including dark energy—since the universe has been determined to have a flat geometry.
My question is this: If the angular diameter distance is required to calculate the physical size of the sound waves at the surface of last scattering, which is then used to determine the geometry of the universe (and consequently the existence of dark energy), but determining the angular diameter distance itself depends on knowing the universe's geometry (including its matter and energy composition, such as dark energy), doesn’t this create a circular argument?