Browse Source

feat: automatically round numbers that are converted to points (#14604)

Fixes #14490
Samuel Attard 6 years ago
parent
commit
73a1a8b3f0

+ 3 - 2
atom/common/native_mate_converters/gfx_converter.cc

@@ -28,10 +28,11 @@ bool Converter<gfx::Point>::FromV8(v8::Isolate* isolate,
   mate::Dictionary dict;
   if (!ConvertFromV8(isolate, val, &dict))
     return false;
-  int x, y;
+  double x, y;
   if (!dict.Get("x", &x) || !dict.Get("y", &y))
     return false;
-  *out = gfx::Point(x, y);
+  *out = gfx::Point(static_cast<int>(std::round(x)),
+                    static_cast<int>(std::round(y)));
   return true;
 }
 

+ 4 - 0
docs/api/structures/point.md

@@ -2,3 +2,7 @@
 
 * `x` Number
 * `y` Number
+
+**Note:** Both `x` and `y` must be whole integers, when providing a point object
+as input to an Electron API we will automatically round your `x` and `y` values
+to the nearest whole integer.