]> granicus.if.org Git - graphviz/commitdiff
fix vcmpid and hcmpid with float_cmp
authorCosta Shulyupin <constantine.shulyupin@gmail.com>
Wed, 13 Apr 2022 05:57:58 +0000 (08:57 +0300)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 11 Jun 2022 18:29:45 +0000 (11:29 -0700)
Original functions misbehaved due to precision issues:
`1E-15 > 0` but it should be considered as equal.

fixes #14 - 8 years old bug!

CHANGELOG.md
lib/ortho/maze.c
tests/test_regression.py

index 34e4fec5fc82a213bcb158a453656d5199b44484..19fd5c7a51cfc2629b4813272371b93074cfde3c 100644 (file)
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
   `putstr` by `printf` has been reverted
 - graphviz-4.0.0: build error: cmd/tools/gvcolor.c:159: undefined reference to
   `fmax` #2246
+- Failed assertion in `chkSgraph` for twopi layout and ortho splines. #14
 
 ## [4.0.0] – 2022-05-29
 
index 4fa388abbd2dfeb8c07c51e388e36eabc65b8efc..78d7073ff39b43a30803fb2fbfba110391ae88e7 100644 (file)
@@ -18,6 +18,7 @@
 #include <stddef.h>
 #include <ortho/maze.h>
 #include <ortho/partition.h>
+#include <ortho/trap.h>
 #include <common/memory.h>
 #include <common/arith.h>
 
@@ -93,12 +94,11 @@ vcmpid(Dt_t* d, pointf* key1, pointf* key2, Dtdisc_t* disc)
 {
   (void)d;
   (void)disc;
-  if (key1->x > key2->x) return 1;
-  else if (key1->x < key2->x) return -1;
-  else if (key1->y > key2->y) return 1;
-  else if (key1->y < key2->y) return -1;
-  else return 0;
-}   
+  int dx = dfp_cmp(key1->x, key2->x);
+  if (dx != 0)
+    return dx;
+  return dfp_cmp(key1->y, key2->y);
+}
 
 /// compares points by Y and then by X
 
@@ -107,12 +107,11 @@ hcmpid(Dt_t* d, pointf* key1, pointf* key2, Dtdisc_t* disc)
 {
   (void)d;
   (void)disc;
-  if (key1->y > key2->y) return 1;
-  else if (key1->y < key2->y) return -1;
-  else if (key1->x > key2->x) return 1;
-  else if (key1->x < key2->x) return -1;
-  else return 0;
-}   
+  int dy = dfp_cmp(key1->y, key2->y);
+  if (dy != 0)
+    return dy;
+  return dfp_cmp(key1->x, key2->x);
+}
 
 typedef struct {
     snode*    np;
index fc46fe384c7f6e3918d59142300ab67b7d9f133a..138066febaf002b752f81249ff73e5411f855568 100644 (file)
@@ -68,7 +68,9 @@ def test_regression_failure():
 # FIXME: re-enable when all tests pass on all platforms
 #    assert result.returncode == 0
 
-@pytest.mark.xfail(strict=not is_ndebug_defined()) # FIXME
+@pytest.mark.xfail(platform.system() == "Windows",
+        reason="#56",
+        strict=not is_ndebug_defined()) # FIXME
 def test_14():
   """
   using ortho and twopi in combination should not cause an assertion failure