[{"id":11387,"web_url":"https://patchwork.libcamera.org/comment/11387/","msgid":"<20200714212041.GC5854@pendragon.ideasonboard.com>","date":"2020-07-14T21:20:41","subject":"Re: [libcamera-devel] [PATCH 04/20] libcamera: geometry: Add\n\tisNull() function to Rectangle class","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Jacopo,\n\nThank you for the patch.\n\nOn Tue, Jul 14, 2020 at 12:41:56PM +0200, Jacopo Mondi wrote:\n> It's common for code to check if a rectangle is null. Add a helper function\n> to do so and test the function in test/geometry.cpp\n> \n> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>\n> ---\n>  include/libcamera/geometry.h | 1 +\n>  src/libcamera/geometry.cpp   | 6 ++++++\n>  test/geometry.cpp            | 6 ++++++\n>  3 files changed, 13 insertions(+)\n> \n> diff --git a/include/libcamera/geometry.h b/include/libcamera/geometry.h\n> index d217cfd50c86..98a919eb01f1 100644\n> --- a/include/libcamera/geometry.h\n> +++ b/include/libcamera/geometry.h\n> @@ -19,6 +19,7 @@ struct Rectangle {\n>  \tunsigned int width;\n>  \tunsigned int height;\n>  \n> +\tbool isNull() const { return !width && !height; }\n>  \tconst std::string toString() const;\n>  };\n>  \n> diff --git a/src/libcamera/geometry.cpp b/src/libcamera/geometry.cpp\n> index 4594f9ff435f..f79f769bf88e 100644\n> --- a/src/libcamera/geometry.cpp\n> +++ b/src/libcamera/geometry.cpp\n> @@ -49,6 +49,12 @@ namespace libcamera {\n>   * \\brief The distance between the top and bottom sides\n>   */\n>  \n> +/**\n> + * \\fn bool Rectangle::isNull() const\n> + * \\brief Check if the rectangle is null\n> + * \\return True if both the width and height are 0, or false otherwise\n> + */\n> +\n>  /**\n>   * \\brief Assemble and return a string describing the rectangle\n>   * \\return A string describing the Rectangle\n> diff --git a/test/geometry.cpp b/test/geometry.cpp\n> index fd0132c03b02..72d938b40e54 100644\n> --- a/test/geometry.cpp\n> +++ b/test/geometry.cpp\n> @@ -36,6 +36,12 @@ protected:\n>  \n>  \tint run()\n>  \t{\n> +\t\tRectangle r{};\n> +\t\tif (!r.isNull()) {\n> +\t\t\tcout << \"Null rectangle incorrectly reported as not null\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n\nLet's test the other case too. I think you can write this\n\n\t\tif (!Rectangle(0, 0, 0, 0).isNull() ||\n\t\t    !Rectangle(1, 1, 0, 0).isNull()) {\n\t\t\tcout << \"Null rectangle incorrectly reported as not null\" << endl;\n\t\t\treturn TestFail;\n\t\t}\n\n\t\tif (Rectangle(0, 0, 0, 1).isNull() ||\n\t\t    Rectangle(0, 0, 1, 0).isNull() ||\n\t\t    Rectangle(0, 0, 1, 1).isNull()) {\n\t\t\tcout << \"Non-null rectangle incorrectly reported as null\" << endl;\n\t\t\treturn TestFail;\n\t\t}\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> +\n>  \t\tif (!Size().isNull() || !Size(0, 0).isNull()) {\n>  \t\t\tcout << \"Null size incorrectly reported as not null\" << endl;\n>  \t\t\treturn TestFail;","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id D6D9FBD790\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 14 Jul 2020 21:20:50 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 6FC26605B0;\n\tTue, 14 Jul 2020 23:20:50 +0200 (CEST)","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 CBDDA605AC\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 14 Jul 2020 23:20:48 +0200 (CEST)","from pendragon.ideasonboard.com (81-175-216-236.bb.dnainternet.fi\n\t[81.175.216.236])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 425CD71D;\n\tTue, 14 Jul 2020 23:20:48 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"r3inmCg5\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1594761648;\n\tbh=PLyppDjrDW6+sgHpdYyNoPlV9X8uNIxUSb9d+qc2nH8=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=r3inmCg52tfl5FVlv83pe2Rot1Vvn9/nHt5MrGqsRKBb07u7JkUmbFY6YvWh0CywQ\n\tQj2uCbe7jBT4+Qj/vmwIz4tU5SFYekpbVGvtmFG+TESbDjbqFhj8xPuuUwjW5/etMl\n\trSR1DhXmaJVa3Ejcbquv3g7hBt0FStjovXmNG6dY=","Date":"Wed, 15 Jul 2020 00:20:41 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Jacopo Mondi <jacopo@jmondi.org>","Message-ID":"<20200714212041.GC5854@pendragon.ideasonboard.com>","References":"<20200714104212.48683-1-jacopo@jmondi.org>\n\t<20200714104212.48683-5-jacopo@jmondi.org>","MIME-Version":"1.0","Content-Disposition":"inline","In-Reply-To":"<20200714104212.48683-5-jacopo@jmondi.org>","Subject":"Re: [libcamera-devel] [PATCH 04/20] libcamera: geometry: Add\n\tisNull() function to Rectangle class","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","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>","Cc":"libcamera-devel@lists.libcamera.org","Content-Type":"text/plain; charset=\"utf-8\"","Content-Transfer-Encoding":"base64","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]