summaryrefslogtreecommitdiff
path: root/support/dktools/dk3bezcu.c
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2020-09-20 03:03:26 +0000
committerNorbert Preining <norbert@preining.info>2020-09-20 03:03:26 +0000
commit1f457376b478257b88d4a857f5ec1b6155442dd7 (patch)
tree2a06a60551dea362cf8cb0cb0ba66c78608717c4 /support/dktools/dk3bezcu.c
parentac690ca29ad5bf8a5203a65fd6252f7b564f4727 (diff)
CTAN sync 202009200303
Diffstat (limited to 'support/dktools/dk3bezcu.c')
-rw-r--r--support/dktools/dk3bezcu.c259
1 files changed, 197 insertions, 62 deletions
diff --git a/support/dktools/dk3bezcu.c b/support/dktools/dk3bezcu.c
index ecd25a27a9..cf1e26dc04 100644
--- a/support/dktools/dk3bezcu.c
+++ b/support/dktools/dk3bezcu.c
@@ -1,36 +1,14 @@
/*
- WARNING: This file was generated by dkct.
- Changes you make here will be lost if dkct is run again!
- You should modify the original source and run dkct on it.
- Original source: dk3bezcu.ctr
+Copyright (C) 2012-2020, Dirk Krause
+SPDX-License-Identifier: BSD-3-Clause
*/
/*
-Copyright (C) 2012-2017, Dirk Krause
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
-
-* Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
-* Redistributions in binary form must reproduce the above opyright notice,
- this list of conditions and the following disclaimer in the documentation
- and/or other materials provided with the distribution.
-* Neither the name of the author nor the names of contributors may be used
- to endorse or promote products derived from this software without specific
- prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-ARE DISCLAIMED.
-IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY
-DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
-THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ WARNING: This file was generated by the dkct program (see
+ http://dktools.sourceforge.net/ for details).
+ Changes you make here will be lost if dkct is run again!
+ You should modify the original source and run dkct on it.
+ Original source: dk3bezcu.ctr
*/
/** @file dk3bezcu.c The dk3bezcu module.
@@ -51,6 +29,40 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#if !(defined(isgreaterequal))
+#if DK3_HAVE_ISFINITE
+/** Test whether a is greater than or equal to b. */
+#define isgreaterequal(a,b) ((isfinite(a)) && (isfinite(b)) && (a >= b))
+#else
+#if DK3_HAVE__FINITE
+/** Test whether a is greater than or equal to b. */
+#define isgreaterequal(a,b) ((_finite(a)) && (_finite(b)) && (a >= b))
+#else
+/** Test whether a is greater than or equal to b. */
+#define isgreaterequal(a,b) (a >= b)
+#endif
+#endif
+#endif
+
+
+
+#if !(defined(islessequal))
+#if DK3_HAVE_ISFINITE
+/** Test whether a is less than or equal to b. */
+#define islessequal(a,b) ((isfinite(a)) && (isfinite(b)) && (a <= b))
+#else
+#if DK3_HAVE__FINITE
+/** Test whether a is less than or equal to b. */
+#define islessequal(a,b) ((_finite(a)) && (_finite(b)) && (a <= b))
+#else
+/** Test whether a is less than or equal to b. */
+#define islessequal(a,b) (a <= b)
+#endif
+#endif
+#endif
+
+
+
double
dk3bezier_value(
double x0, double xp, double xm, double x1, double t, int *ec
@@ -60,7 +72,7 @@ dk3bezier_value(
double back;
-#line 81 "dk3bezcu.ctr"
+#line 115 "dk3bezcu.ctr"
back = dk3ma_d_add_ok(
x0,
dk3ma_d_mul_ok(
@@ -107,13 +119,13 @@ dk3bezier_value(
&mec
);
-#line 126 "dk3bezcu.ctr"
+#line 160 "dk3bezcu.ctr"
if(mec) {
if(ec) { *ec = mec; }
}
-#line 130 "dk3bezcu.ctr"
+#line 164 "dk3bezcu.ctr"
return back;
}
@@ -150,12 +162,12 @@ dk3bezier_t_dimension(
int mec = 0;
-#line 165 "dk3bezcu.ctr"
+#line 199 "dk3bezcu.ctr"
if(tv > 0.0) {
if(tv < 1.0) {
val = dk3bezier_value(x0, xp, xm, x1, tv, &mec);
-#line 168 "dk3bezcu.ctr"
+#line 202 "dk3bezcu.ctr"
if(isy) {
if(!dk3bb_add_y_width(bb, val, ra)) { back = 0; }
} else {
@@ -165,12 +177,12 @@ dk3bezier_t_dimension(
}
if(mec) {
-#line 176 "dk3bezcu.ctr"
+#line 210 "dk3bezcu.ctr"
back = 0;
if(ec) { *ec = mec; }
}
-#line 179 "dk3bezcu.ctr"
+#line 213 "dk3bezcu.ctr"
return back;
}
@@ -209,21 +221,21 @@ dk3bezier_bb_dimension(
int mec = 0;
-#line 216 "dk3bezcu.ctr"
+#line 250 "dk3bezcu.ctr"
n = dk3ma_d_add_ok(
dk3ma_d_sub_ok(x1, x0, &mec),
dk3ma_d_mul_ok(3.0, dk3ma_d_sub_ok(xp, xm, &mec), &mec),
&mec
);
-#line 221 "dk3bezcu.ctr"
+#line 255 "dk3bezcu.ctr"
z1 = dk3ma_d_sub_ok(
dk3ma_d_sub_ok(dk3ma_d_mul_ok(2.0, xp, &mec), xm, &mec),
x0,
&mec
);
-#line 226 "dk3bezcu.ctr"
+#line 260 "dk3bezcu.ctr"
z2 = dk3ma_d_add_ok(
dk3ma_d_sub_ok(
xm,
@@ -234,7 +246,7 @@ dk3bezier_bb_dimension(
&mec
);
-#line 235 "dk3bezcu.ctr"
+#line 269 "dk3bezcu.ctr"
z2 = dk3ma_d_mul_ok(z2, z2, &mec);
z2 = dk3ma_d_sub_ok(
z2,
@@ -246,47 +258,48 @@ dk3bezier_bb_dimension(
&mec
);
-#line 245 "dk3bezcu.ctr"
+#line 279 "dk3bezcu.ctr"
if(z2 >= 0.0) {
z2 = sqrt(z2);
-#line 247 "dk3bezcu.ctr"
+#line 281 "dk3bezcu.ctr"
t = dk3ma_d_div_ok(
dk3ma_d_add_ok(z1, z2, &mec),
n,
&mec
);
-#line 252 "dk3bezcu.ctr"
+#line 286 "dk3bezcu.ctr"
if(!dk3bezier_t_dimension(bb, x0, xp, xm, x1, ra, t, isy, &mec)) {
back = 0;
}
-#line 255 "dk3bezcu.ctr"
+#line 289 "dk3bezcu.ctr"
t = dk3ma_d_div_ok(
dk3ma_d_sub_ok(z1, z2, &mec),
n,
&mec
);
-#line 260 "dk3bezcu.ctr"
+#line 294 "dk3bezcu.ctr"
if(!dk3bezier_t_dimension(bb, x0, xp, xm, x1, ra, t, isy, &mec)) {
back = 0;
}
-#line 263 "dk3bezcu.ctr"
+#line 297 "dk3bezcu.ctr"
}
if(mec) {
-#line 265 "dk3bezcu.ctr"
+#line 299 "dk3bezcu.ctr"
back = 0;
if(ec) { *ec = mec; }
}
-#line 268 "dk3bezcu.ctr"
+#line 302 "dk3bezcu.ctr"
return back;
}
#else
+#if VERSION_BEFORE_20170609
/** Apply one dimension to a bounding box.
@param bb Bounding box to modify.
@param x0 Start value.
@@ -320,21 +333,21 @@ dk3bezier_bb_dimension(
int testmec;
-#line 303 "dk3bezcu.ctr"
+#line 338 "dk3bezcu.ctr"
n = dk3ma_d_add_ok(
dk3ma_d_sub_ok(x1, x0, &mec),
dk3ma_d_mul_ok(3.0, dk3ma_d_sub_ok(xp, xm, &mec), &mec),
&mec
);
-#line 308 "dk3bezcu.ctr"
+#line 343 "dk3bezcu.ctr"
z1 = dk3ma_d_sub_ok(
dk3ma_d_sub_ok(dk3ma_d_mul_ok(2.0, xp, &mec), xm, &mec),
x0,
&mec
);
-#line 313 "dk3bezcu.ctr"
+#line 348 "dk3bezcu.ctr"
z2 = dk3ma_d_add_ok(
dk3ma_d_sub_ok(
xm,
@@ -345,7 +358,7 @@ dk3bezier_bb_dimension(
&mec
);
-#line 322 "dk3bezcu.ctr"
+#line 357 "dk3bezcu.ctr"
z2 = dk3ma_d_mul_ok(z2, z2, &mec);
z2 = dk3ma_d_sub_ok(
z2,
@@ -357,11 +370,11 @@ dk3bezier_bb_dimension(
&mec
);
-#line 332 "dk3bezcu.ctr"
+#line 367 "dk3bezcu.ctr"
if(z2 >= 0.0) {
z2 = sqrt(z2);
-#line 334 "dk3bezcu.ctr"
+#line 369 "dk3bezcu.ctr"
testmec = 0;
t = dk3ma_d_div_ok(
dk3ma_d_add_ok(z1, z2, &mec),
@@ -369,13 +382,13 @@ dk3bezier_bb_dimension(
&testmec
);
-#line 340 "dk3bezcu.ctr"
+#line 375 "dk3bezcu.ctr"
if(0 == testmec) {
if(!dk3bezier_t_dimension(bb, x0, xp, xm, x1, ra, t, isy, &mec)) {
back = 0;
}
-#line 344 "dk3bezcu.ctr"
+#line 379 "dk3bezcu.ctr"
}
testmec = 0;
t = dk3ma_d_div_ok(
@@ -384,25 +397,147 @@ dk3bezier_bb_dimension(
&testmec
);
-#line 351 "dk3bezcu.ctr"
+#line 386 "dk3bezcu.ctr"
if(0 == testmec) {
if(!dk3bezier_t_dimension(bb, x0, xp, xm, x1, ra, t, isy, &mec)) {
back = 0;
}
-#line 355 "dk3bezcu.ctr"
+#line 390 "dk3bezcu.ctr"
}
}
if(mec) {
-#line 358 "dk3bezcu.ctr"
+#line 393 "dk3bezcu.ctr"
back = 0;
if(ec) { *ec = mec; }
}
-#line 361 "dk3bezcu.ctr"
+#line 396 "dk3bezcu.ctr"
return back;
}
+#else
+/** Apply one dimension to a bounding box.
+ @param bb Bounding box to modify.
+ @param x0 Start value.
+ @param xp Control value for start.
+ @param xm Control value for end.
+ @param x1 End value.
+ @param ra Point radius (half line width).
+ @param isy Flag: Y direction.
+ @param ec Pointer to error code variable, may be NULL.
+ @return 1 on success, 0 on error.
+*/
+static
+int
+dk3bezier_bb_dimension(
+ dk3_bb_t *bb,
+ double x0,
+ double xp,
+ double xm,
+ double x1,
+ double ra,
+ int isy,
+ int *ec
+)
+{
+ double a;
+ double b;
+ double c;
+ double t1;
+ double t2;
+ double sqop;
+ double sqv;
+ double denom;
+ int back = 1;
+ int mec = 0;
+
+
+#line 434 "dk3bezcu.ctr"
+ a = x1 - 3.0 * xm + 3.0 * xp - x0;
+ b = 3.0 * x0 - 6.0 * xp + 3.0 * xm;
+ c = 3.0 * (xp - x0);
+ sqop = b * b - 3.0 * a * c;
+ sqv = sqrt(sqop);
+ denom = 3.0 * a;
+ t1 = (0.0 - b + sqv) / (denom);
+ t2 = (0.0 - b - sqv) / (denom);
+#if DK3_HAVE_ISFINITE
+ if ((isfinite(t1)) && (isfinite(t2)))
+#else
+#if DK3_HAVE__FINITE
+ if ((_finite(t1)) && (_finite(t2)))
+#else
+#error "Neither isfinite() nor _finite() available!"
+ if (1)
+#endif
+#endif
+ {
+
+#line 453 "dk3bezcu.ctr"
+ if ((isgreaterequal(t1, 0.0)) && (islessequal(t1, 1.0))) {
+ if(!dk3bezier_t_dimension(
+ bb, x0, xp, xm, x1, ra, t1, isy, &mec
+ )
+ ) {
+ back = 0;
+ }
+
+#line 460 "dk3bezcu.ctr"
+ }
+ if ((isgreaterequal(t2, 0.0)) && (islessequal(t2, 1.0))) {
+ if(!dk3bezier_t_dimension(
+ bb, x0, xp, xm, x1, ra, t2, isy, &mec
+ )
+ ) {
+ back = 0;
+ }
+
+#line 468 "dk3bezcu.ctr"
+ }
+ }
+ else {
+
+#line 471 "dk3bezcu.ctr"
+ t1 = (0.0 - c) / (2.0 * b);
+#if DK3_HAVE_ISFINITE
+ if (isfinite(t1))
+#else
+#if DK3_HAVE__FINITE
+ if (_finite(t1))
+#else
+#error "Neither isfinite() nor _finite() available!"
+ if (1)
+#endif
+#endif
+ {
+ if ((isgreaterequal(t1,0.0)) && (islessequal(t1,1.0))) {
+ if(!dk3bezier_t_dimension(
+ bb, x0, xp, xm, x1, ra, t1, isy, &mec
+ )
+ ) {
+ back = 0;
+ }
+
+#line 490 "dk3bezcu.ctr"
+ }
+ }
+#if TRACE_DEBUG
+ else {
+
+#line 494 "dk3bezcu.ctr"
+ }
+#endif
+ }
+ if (0 != mec) {
+ if (NULL != ec) { *ec = mec; }
+ back = 0;
+ }
+
+#line 501 "dk3bezcu.ctr"
+ return back;
+}
+#endif
#endif
@@ -425,7 +560,7 @@ dk3bezier_bb(
int mec = 0;
-#line 384 "dk3bezcu.ctr"
+#line 525 "dk3bezcu.ctr"
if(bb) {
back = 1;
if(!dk3bb_point_width(bb, x0, y0, ra)) {
@@ -448,7 +583,7 @@ dk3bezier_bb(
if(ec) { *ec = DK3_ERROR_INVALID_ARGS; }
}
-#line 405 "dk3bezcu.ctr"
+#line 546 "dk3bezcu.ctr"
return back;
}