{"id":1053,"url":"https://patchwork.libcamera.org/api/1.1/patches/1053/?format=json","web_url":"https://patchwork.libcamera.org/patch/1053/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20190418141437.14014-7-laurent.pinchart@ideasonboard.com>","date":"2019-04-18T14:14:30","name":"[libcamera-devel,v3,06/13] libcamera: geometry: Add comparison operators to geometry classes","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"5bea4ddee08e19781d58104a215403b1b7895026","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/1.1/people/2/?format=json","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/1053/mbox/","series":[{"id":256,"url":"https://patchwork.libcamera.org/api/1.1/series/256/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=256","date":"2019-04-18T14:14:24","name":"Rockchip ISP pipeline handler","version":3,"mbox":"https://patchwork.libcamera.org/series/256/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/1053/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/1053/checks/","tags":{},"headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id F0C5160DC7\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 18 Apr 2019 16:14:56 +0200 (CEST)","from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi\n\t[81.175.216.236])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 83E28B85\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 18 Apr 2019 16:14:56 +0200 (CEST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1555596896;\n\tbh=5YdKs5SiFvFQkq7ZVXFBkrtwDRPewHOgP5TYywDlDIs=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=kqnCF5BZWAynBeEkXdJUbtupEKWX+IkHkiKu8pFv4czfmhx3v6XOQ6RujZkqaFpUx\n\tbyc2jEoK0WDXGwf3YZvfk/ANdYGt9lP/MmFcL/huGHWshp0O8cUjGdP65TogzYZHrh\n\tKV+ZtGP1r6sPjctJ9erVhJoBIlK/QpyPhhS+Uvjo=","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Thu, 18 Apr 2019 17:14:30 +0300","Message-Id":"<20190418141437.14014-7-laurent.pinchart@ideasonboard.com>","X-Mailer":"git-send-email 2.21.0","In-Reply-To":"<20190418141437.14014-1-laurent.pinchart@ideasonboard.com>","References":"<20190418141437.14014-1-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=UTF-8","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v3 06/13] libcamera: geometry: Add\n\tcomparison operators to geometry classes","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.23","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","X-List-Received-Date":"Thu, 18 Apr 2019 14:14:57 -0000"},"content":"Add equality and inequality comparison operators for the Rectangle, Size\nand SizeRange classes.\n\nFor the Size class, also add ordering operators. Sizes are first\ncompared on combined width and height, then on area, and finally on\nwidth only to achieve a stable ordering.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\nReviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\nReviewed-by: Jacopo Mondi <jacopo@jmondi.org>\n---\nChanges since v1:\n\n- Replace {left, right} hand size with \\a lhs and \\a rhs respectively\n---\n include/libcamera/geometry.h | 35 +++++++++++++\n src/libcamera/geometry.cpp   | 98 ++++++++++++++++++++++++++++++++++++\n 2 files changed, 133 insertions(+)","diff":"diff --git a/include/libcamera/geometry.h b/include/libcamera/geometry.h\nindex 80f79c6ba2d3..3dbbced5c76f 100644\n--- a/include/libcamera/geometry.h\n+++ b/include/libcamera/geometry.h\n@@ -21,6 +21,12 @@ struct Rectangle {\n \tconst std::string toString() const;\n };\n \n+bool operator==(const Rectangle &lhs, const Rectangle &rhs);\n+static inline bool operator!=(const Rectangle &lhs, const Rectangle &rhs)\n+{\n+\treturn !(lhs == rhs);\n+}\n+\n struct Size {\n \tSize()\n \t\t: Size(0, 0)\n@@ -36,6 +42,29 @@ struct Size {\n \tunsigned int height;\n };\n \n+bool operator==(const Size &lhs, const Size &rhs);\n+bool operator<(const Size &lhs, const Size &rhs);\n+\n+static inline bool operator!=(const Size &lhs, const Size &rhs)\n+{\n+\treturn !(lhs == rhs);\n+}\n+\n+static inline bool operator<=(const Size &lhs, const Size &rhs)\n+{\n+\treturn lhs < rhs || lhs == rhs;\n+}\n+\n+static inline bool operator>(const Size &lhs, const Size &rhs)\n+{\n+\treturn !(lhs <= rhs);\n+}\n+\n+static inline bool operator>=(const Size &lhs, const Size &rhs)\n+{\n+\treturn !(lhs < rhs);\n+}\n+\n struct SizeRange {\n \tSizeRange()\n \t{\n@@ -51,6 +80,12 @@ struct SizeRange {\n \tSize max;\n };\n \n+bool operator==(const SizeRange &lhs, const SizeRange &rhs);\n+static inline bool operator!=(const SizeRange &lhs, const SizeRange &rhs)\n+{\n+\treturn !(lhs == rhs);\n+}\n+\n } /* namespace libcamera */\n \n #endif /* __LIBCAMERA_GEOMETRY_H__ */\ndiff --git a/src/libcamera/geometry.cpp b/src/libcamera/geometry.cpp\nindex c1c7daed7259..d14c925aaad2 100644\n--- a/src/libcamera/geometry.cpp\n+++ b/src/libcamera/geometry.cpp\n@@ -6,6 +6,7 @@\n  */\n \n #include <sstream>\n+#include <stdint.h>\n \n #include <libcamera/geometry.h>\n \n@@ -62,6 +63,22 @@ const std::string Rectangle::toString() const\n \treturn ss.str();\n }\n \n+/**\n+ * \\brief Compare rectangles for equality\n+ * \\return True if the two rectangles are equal, false otherwise\n+ */\n+bool operator==(const Rectangle &lhs, const Rectangle &rhs)\n+{\n+\treturn lhs.x == rhs.x && lhs.y == rhs.y &&\n+\t       lhs.w == rhs.w && lhs.h == rhs.h;\n+}\n+\n+/**\n+ * \\fn bool operator!=(const Rectangle &lhs, const Rectangle &rhs)\n+ * \\brief Compare rectangles for inequality\n+ * \\return True if the two rectangles are not equal, false otherwise\n+ */\n+\n /**\n  * \\struct Size\n  * \\brief Describe a two-dimensional size\n@@ -91,6 +108,72 @@ const std::string Rectangle::toString() const\n  * \\brief The Size height\n  */\n \n+/**\n+ * \\brief Compare sizes for equality\n+ * \\return True if the two sizes are equal, false otherwise\n+ */\n+bool operator==(const Size &lhs, const Size &rhs)\n+{\n+\treturn lhs.width == rhs.width && lhs.height == rhs.height;\n+}\n+\n+/**\n+ * \\brief Compare sizes for smaller than order\n+ *\n+ * Sizes are compared on three criteria, in the following order.\n+ *\n+ * - A size with smaller width and smaller height is smaller.\n+ * - A size with smaller area is smaller.\n+ * - A size with smaller width is smaller.\n+ *\n+ * \\return True if \\a lhs is smaller than \\a rhs, false otherwise\n+ */\n+bool operator<(const Size &lhs, const Size &rhs)\n+{\n+\tif (lhs.width < rhs.width && lhs.height < rhs.height)\n+\t\treturn true;\n+\telse if (lhs.width >= rhs.width && lhs.height >= rhs.height)\n+\t\treturn false;\n+\n+\tuint64_t larea = static_cast<uint64_t>(lhs.width) *\n+\t\t\t static_cast<uint64_t>(lhs.height);\n+\tuint64_t rarea = static_cast<uint64_t>(rhs.width) *\n+\t\t\t static_cast<uint64_t>(rhs.height);\n+\tif (larea < rarea)\n+\t\treturn true;\n+\telse if (larea > rarea)\n+\t\treturn false;\n+\n+\treturn lhs.width < rhs.width;\n+}\n+\n+/**\n+ * \\fn bool operator!=(const Size &lhs, const Size &rhs)\n+ * \\brief Compare sizes for inequality\n+ * \\return True if the two sizes are not equal, false otherwise\n+ */\n+\n+/**\n+ * \\fn bool operator<=(const Size &lhs, const Size &rhs)\n+ * \\brief Compare sizes for smaller than or equal to order\n+ * \\return True if \\a lhs is smaller than or equal to \\a rhs, false otherwise\n+ * \\sa bool operator<(const Size &lhs, const Size &rhs)\n+ */\n+\n+/**\n+ * \\fn bool operator>(const Size &lhs, const Size &rhs)\n+ * \\brief Compare sizes for greater than order\n+ * \\return True if \\a lhs is greater than \\a rhs, false otherwise\n+ * \\sa bool operator<(const Size &lhs, const Size &rhs)\n+ */\n+\n+/**\n+ * \\fn bool operator>=(const Size &lhs, const Size &rhs)\n+ * \\brief Compare sizes for greater than or equal to order\n+ * \\return True if \\a lhs is greater than or equal to \\a rhs, false otherwise\n+ * \\sa bool operator<(const Size &lhs, const Size &rhs)\n+ */\n+\n /**\n  * \\struct SizeRange\n  * \\brief Describe a range of sizes\n@@ -124,4 +207,19 @@ const std::string Rectangle::toString() const\n  * \\brief The maximum size\n  */\n \n+/**\n+ * \\brief Compare size ranges for equality\n+ * \\return True if the two size ranges are equal, false otherwise\n+ */\n+bool operator==(const SizeRange &lhs, const SizeRange &rhs)\n+{\n+\treturn lhs.min == rhs.min && lhs.max == rhs.max;\n+}\n+\n+/**\n+ * \\fn bool operator!=(const SizeRange &lhs, const SizeRange &rhs)\n+ * \\brief Compare size ranges for inequality\n+ * \\return True if the two size ranges are not equal, false otherwise\n+ */\n+\n } /* namespace libcamera */\n","prefixes":["libcamera-devel","v3","06/13"]}