From 73a1a8b3f010b592cdcbfa28a927e5892a3a91a5 Mon Sep 17 00:00:00 2001 From: Samuel Attard Date: Thu, 13 Sep 2018 23:28:56 +1000 Subject: [PATCH] feat: automatically round numbers that are converted to points (#14604) Fixes #14490 --- atom/common/native_mate_converters/gfx_converter.cc | 5 +++-- docs/api/structures/point.md | 4 ++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/atom/common/native_mate_converters/gfx_converter.cc b/atom/common/native_mate_converters/gfx_converter.cc index 7a7cfd39e061..45c4094f6a42 100644 --- a/atom/common/native_mate_converters/gfx_converter.cc +++ b/atom/common/native_mate_converters/gfx_converter.cc @@ -28,10 +28,11 @@ bool Converter::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(std::round(x)), + static_cast(std::round(y))); return true; } diff --git a/docs/api/structures/point.md b/docs/api/structures/point.md index 69b87cbdf9c4..34e85ef6e55e 100644 --- a/docs/api/structures/point.md +++ b/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.