From 69577eb0b7a6e446c9507a9d3e8266ab67e31b0b Mon Sep 17 00:00:00 2001
From: Petteri Aimonen <petteri.aimonen@espotel.com>
Date: Thu, 22 Sep 2016 11:09:06 -0600
Subject: [PATCH] libnx/nxglib: Fix handling of near-horizontal lines of width
 1 in nxgl_splitline().  Missing handling for degenerate condition caused
 width 1 lines such as (0, 0) - (100, 10) to have gaps in the drawing.

---
 fs/mount/fs_mount.c             |  2 +-
 libnx/nxglib/nxglib_splitline.c | 38 ++++++++++++++++++++++++++++++++-
 2 files changed, 38 insertions(+), 2 deletions(-)

diff --git a/fs/mount/fs_mount.c b/fs/mount/fs_mount.c
index 957e58f9c8..4442938481 100644
--- a/fs/mount/fs_mount.c
+++ b/fs/mount/fs_mount.c
@@ -287,7 +287,7 @@ int mount(FAR const char *source, FAR const char *target,
        * incremented.
        *
        * But is it a directory node (i.e., not a driver or other special
-       * node).
+       * node)?
        */
 
       if (INODE_IS_SPECIAL(mountpt_inode))
diff --git a/libnx/nxglib/nxglib_splitline.c b/libnx/nxglib/nxglib_splitline.c
index c63539b8c1..31b5d914bd 100644
--- a/libnx/nxglib/nxglib_splitline.c
+++ b/libnx/nxglib/nxglib_splitline.c
@@ -1,7 +1,7 @@
 /****************************************************************************
  * graphics/nxglib/nxglib_splitline.c
  *
- *   Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
+ *   Copyright (C) 2011-2012, 2016 Gregory Nutt. All rights reserved.
  *   Author: Gregory Nutt <gnutt@nuttx.org>
  *
  * Redistribution and use in source and binary forms, with or without
@@ -237,6 +237,42 @@ int nxgl_splitline(FAR struct nxgl_vector_s *vector,
 
       return 1;
     }
+  else if (linewidth == 1)
+    {
+      b16_t pixels_per_row;
+
+      /* Close to horizontal line of width 1 */
+
+      pixels_per_row  = itob16(line.pt2.x - line.pt1.x) /
+                        (line.pt2.y - line.pt1.y);
+
+      traps[1].top.x1 = itob16(line.pt1.x);
+      traps[1].top.x2 = traps[1].top.x1 + pixels_per_row;
+      traps[1].top.y  = line.pt1.y;
+
+      traps[1].bot.x2 = itob16(line.pt2.x);
+      traps[1].bot.x1 = traps[1].bot.x2 - pixels_per_row;
+      traps[1].bot.y  = line.pt2.y;
+
+      if (pixels_per_row < 0)
+        {
+          b16_t tmp;
+
+          tmp             = traps[1].top.x2;
+          traps[1].top.x2 = traps[1].top.x1;
+          traps[1].top.x1 = tmp;
+
+          tmp             = traps[1].bot.x2;
+          traps[1].bot.x2 = traps[1].bot.x1;
+          traps[1].bot.x1 = tmp;
+        }
+
+      ginfo("Horizontal traps[1]: (%08x,%08x,%d),(%08x,%08x, %d)\n",
+            traps[1].top.x1, traps[1].top.x2, traps[1].top.y,
+            traps[1].bot.x1, traps[1].bot.x2, traps[1].bot.y);
+
+      return 1;
+    }
 
   /* Okay, then what remains is interesting.
    *