aboutsummaryrefslogtreecommitdiff
path: root/svg-flatten/include/geom2d.hpp
diff options
context:
space:
mode:
authorjaseg <git@jaseg.de>2023-03-26 00:40:43 +0100
committerjaseg <git@jaseg.de>2023-03-26 00:40:43 +0100
commitb4753e66e29af0b6087f591838069deb9689b78f (patch)
tree65644a64eb79be75b70853fc132e38073eacf563 /svg-flatten/include/geom2d.hpp
parent6b0382ab776dd8abcaefa0103c855f16372f62c3 (diff)
downloadgerbolyze-b4753e66e29af0b6087f591838069deb9689b78f.tar.gz
gerbolyze-b4753e66e29af0b6087f591838069deb9689b78f.tar.bz2
gerbolyze-b4753e66e29af0b6087f591838069deb9689b78f.zip
WIP
Diffstat (limited to 'svg-flatten/include/geom2d.hpp')
-rw-r--r--svg-flatten/include/geom2d.hpp31
1 files changed, 30 insertions, 1 deletions
diff --git a/svg-flatten/include/geom2d.hpp b/svg-flatten/include/geom2d.hpp
index 47cf3be..9650575 100644
--- a/svg-flatten/include/geom2d.hpp
+++ b/svg-flatten/include/geom2d.hpp
@@ -113,9 +113,38 @@ namespace gerbolyze {
double doc2phys_skew(double dist_doc) {
/* https://math.stackexchange.com/a/3521141 */
+ /* https://stackoverflow.com/a/70381885 */
/* xx yx x0
* xy yy y0 */
- s_x = sqrt();
+ double s_x = sqrt(xx*xx + xy*xy);
+
+ if (xx == 0 && xy == 0) {
+ return std::numeric_limits<double>::infinity;
+ }
+
+ double theta = atan2(xy, xx);
+ double f = (xx*yy - xy*yx);
+
+ if (f == 0) {
+ return std::numeric_limits<double>::infinity;
+ }
+
+ double m = (xx*yx + yy*xy) / f;
+
+ double f = xx + m*xy;
+ double s_y = 0;
+
+ if (f == 0) {
+ f = m*xx - xy;
+ if (f == 0) {
+ return std::numeric_limits<double>::infinity;
+ }
+ s_y = yx*s_x / f;
+ } else {
+ s_y = yy*s_x / f;
+ }
+
+ return s_x - s_y >
}
double doc2phys_min(double dist_doc) {