[{"id":31347,"web_url":"https://patchwork.libcamera.org/comment/31347/","msgid":"<d975583c-7f5d-4f5b-8e99-5cdc61396667@ideasonboard.com>","date":"2024-09-25T06:36:05","subject":"Re: [PATCH] libcamera: geometry: Rename Rectangle's top-left corner","submitter":{"id":86,"url":"https://patchwork.libcamera.org/api/people/86/","name":"Umang Jain","email":"umang.jain@ideasonboard.com"},"content":"Hi Jacopo\n\nThank you for the patch\n\nOn 24/09/24 6:15 pm, Jacopo Mondi wrote:\n> The libcamera::Rectangle class should allow defining rectangles\n> regardless of the reference system where an instance is used in.\n>\n> However the class documentation assumes the reference system origin\n> point to be in the visual top-left side and that rectangles are\n> constructed by specifying the top-left corner position and sizes.\n>\n> However this is ambiguous when using a different reference system as,\n> in example, constructing a rectangle (x, y, w, h) in the following\n> scenario, with the origin corner in the top-left position, would require\n> a negative decrement along the y-axis.\n>\n>           ^\n>           |\n>          y|      o------------------\n>           |      |                 | h\n>           |      |                 |\n>           |      -------------------\n>           |               w\n>            ------------------------------->\n>           (0,0)  x\n>\n> To remove ambiguities, drop references to the visual top-left corner and\n> define the rectangle's origin corner as the corner closer to the\n> reference system origin point, and specify the horizontal and vertical\n> dimensions always increment along their respective axis, as in the\n> following example.\n>\n>           ^\n>           |\n>           |      -------------------\n>           |      ^                 | h\n>           |      |                 |\n>          y|      o---->-------------\n>           |               w\n>            ------------------------------->\n>           (0,0)  x\n>\n>           (0,0)  x\n>             ------------------------------>\n>            |              w\n>           y|     o---->-------------\n>            |     |                 | h\n>            |     v                 |\n>            |     -------------------\n>            |\n>            V\n>\n> Also rename for consistency the Rectangle::topLeft() function to\n> Rectangle::origin() and update its in-tree users.\n>\n> Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n> ---\n>   include/libcamera/geometry.h                  |  2 +-\n>   src/ipa/ipu3/algorithms/af.cpp                |  2 +-\n>   src/libcamera/geometry.cpp                    | 85 ++++++++++++++-----\n>   .../pipeline/rpi/common/pipeline_base.cpp     |  4 +-\n>   src/py/libcamera/py_geometry.cpp              |  2 +-\n>   test/geometry.cpp                             |  8 +-\n>   6 files changed, 75 insertions(+), 28 deletions(-)\n>\n> diff --git a/include/libcamera/geometry.h b/include/libcamera/geometry.h\n> index 3e6f0f5d7fab..07cb0a7866fe 100644\n> --- a/include/libcamera/geometry.h\n> +++ b/include/libcamera/geometry.h\n> @@ -277,7 +277,7 @@ public:\n>   \t\treturn { width, height };\n>   \t}\n>\n> -\tPoint topLeft() const\n> +\tPoint origin() const\n>   \t{\n>   \t\treturn { x, y };\n>   \t}\n> diff --git a/src/ipa/ipu3/algorithms/af.cpp b/src/ipa/ipu3/algorithms/af.cpp\n> index cf68fb59c49b..1b707e9dd9ab 100644\n> --- a/src/ipa/ipu3/algorithms/af.cpp\n> +++ b/src/ipa/ipu3/algorithms/af.cpp\n> @@ -155,7 +155,7 @@ int Af::configure(IPAContext &context, const IPAConfigInfo &configInfo)\n>   \t * - Return the AF ROI as metadata in the Request\n>   \t */\n>   \tRectangle roi = gridSize.centeredTo(bds.center());\n> -\tPoint start = roi.topLeft();\n> +\tPoint start = roi.origin();\n>\n>   \t/* x_start and y_start should be even */\n>   \tgrid.x_start = utils::alignDown(start.x, 2);\n> diff --git a/src/libcamera/geometry.cpp b/src/libcamera/geometry.cpp\n> index 000151364c7f..45ba81a99920 100644\n> --- a/src/libcamera/geometry.cpp\n> +++ b/src/libcamera/geometry.cpp\n> @@ -593,11 +593,39 @@ std::ostream &operator<<(std::ostream &out, const SizeRange &sr)\n>    * \\brief Describe a rectangle's position and dimensions\n>    *\n>    * Rectangles are used to identify an area of an image. They are specified by\n> - * the coordinates of top-left corner and their horizontal and vertical size.\n> + * the coordinates of the corner closer to the reference system's origin point\n> + * and by horizontal and vertical increments from there.\n>    *\n> - * The measure unit of the rectangle coordinates and size, as well as the\n> - * reference point from which the Rectangle::x and Rectangle::y displacements\n> - * refers to, are defined by the context were rectangle is used.\n> + * The corner closer to the reference system's origin point is the rectangle's\n> + * origin corner.\n> + *\n> + * \\verbatim\n> +\n> +  o = origin corner\n> +\n> +         ^\n> +         |\n> +         |      -------------------\n> +         |      ^                 |\n> +         |      |                 |\n> +         |      o---->-------------\n> +         |\n> +          ------------------------------->\n> +         (0,0)\n> +\n> +         (0,0)\n> +           ------------------------------->\n> +          |\n> +          |      o---->-------------\n> +          |      |                 |\n> +          |      v                 |\n> +          |      -------------------\n> +          |\n> +          V\n> +   \\endverbatim\n> + *\n> + * The measure unit of the rectangle coordinates and size are defined by the\n> + * context were the rectangle is used.\n>    */\n>\n>   /**\n> @@ -608,35 +636,50 @@ std::ostream &operator<<(std::ostream &out, const SizeRange &sr)\n>   /**\n>    * \\fn Rectangle::Rectangle(int x, int y, const Size &size)\n>    * \\brief Construct a Rectangle with the given position and size\n> - * \\param[in] x The horizontal coordinate of the top-left corner\n> - * \\param[in] y The vertical coordinate of the top-left corner\n> + * \\param[in] x The horizontal coordinate of the origin corner\n> + * \\param[in] y The vertical coordinate of the origin corner\n>    * \\param[in] size The size\n> + *\n> + * The rectangle's origin corner is the corner closer to the reference system\n> + * origin point (0, 0).\n>    */\n>\n>   /**\n>    * \\fn Rectangle::Rectangle(int x, int y, unsigned int width, unsigned int height)\n>    * \\brief Construct a Rectangle with the given position and size\n> - * \\param[in] x The horizontal coordinate of the top-left corner\n> - * \\param[in] y The vertical coordinate of the top-left corner\n> + * \\param[in] x The horizontal coordinate of the origin corner\n> + * \\param[in] y The vertical coordinate of the origin corner\n>    * \\param[in] width The width\n>    * \\param[in] height The height\n> + *\n> + * The rectangle's origin corner is the corner closer to the reference system\n> + * origin point (0, 0).\n>    */\n>\n>   /**\n>    * \\fn Rectangle::Rectangle(const Size &size)\n> - * \\brief Construct a Rectangle of \\a size with its top left corner located\n> + * \\brief Construct a Rectangle of \\a size with its origin corner located\n>    * at (0,0)\n>    * \\param[in] size The desired Rectangle size\n> + *\n> + * The rectangle's origin corner is the corner closer to the reference system\n> + * origin point (0, 0).\n>    */\n>\n>   /**\n>    * \\var Rectangle::x\n> - * \\brief The horizontal coordinate of the rectangle's top-left corner\n> + * \\brief The horizontal coordinate of the rectangle's origin corner\n> + *\n> + * The rectangle's origin corner is the corner closer to the reference system\n> + * origin point (0, 0).\n>    */\n>\n>   /**\n>    * \\var Rectangle::y\n> - * \\brief The vertical coordinate of the rectangle's top-left corner\n> + * \\brief The vertical coordinate of the rectangle's origin corner\n> + *\n> + * The rectangle's origin corner is the corner closer to the reference system\n> + * origin point (0, 0).\n>    */\n>\n>   /**\n> @@ -683,9 +726,13 @@ Point Rectangle::center() const\n>    */\n>\n>   /**\n> - * \\fn Point Rectangle::topLeft() const\n> - * \\brief Retrieve the coordinates of the top left corner of this Rectangle\n> - * \\return The Rectangle's top left corner\n> + * \\fn Point Rectangle::origin() const\n> + * \\brief Retrieve the coordinates of the origin corner of this Rectangle\n> + *\n> + * The rectangle's origin corner is the corner closer to the reference system\n> + * origin point (0, 0).\n> + *\n> + * \\return The Rectangle's origin corner\n\nI think you can drop \"corner\" from \"origin corner\"\n\nProbably throughout the patch:\n     s/origin corner/origin/\n\nOtherwise, LGTM\n\nReviewed-by: Umang Jain <umang.jain@ideasonboard.com>\n>    */\n>\n>   /**\n> @@ -740,15 +787,15 @@ Rectangle &Rectangle::translateBy(const Point &point)\n>    */\n>   Rectangle Rectangle::boundedTo(const Rectangle &bound) const\n>   {\n> -\tint topLeftX = std::max(x, bound.x);\n> -\tint topLeftY = std::max(y, bound.y);\n> +\tint originX = std::max(x, bound.x);\n> +\tint originY = std::max(y, bound.y);\n>   \tint bottomRightX = std::min<int>(x + width, bound.x + bound.width);\n>   \tint bottomRightY = std::min<int>(y + height, bound.y + bound.height);\n>\n> -\tunsigned int newWidth = std::max(bottomRightX - topLeftX, 0);\n> -\tunsigned int newHeight = std::max(bottomRightY - topLeftY, 0);\n> +\tunsigned int newWidth = std::max(bottomRightX - originX, 0);\n> +\tunsigned int newHeight = std::max(bottomRightY - originY, 0);\n>\n> -\treturn { topLeftX, topLeftY, newWidth, newHeight };\n> +\treturn { originX, originY, newWidth, newHeight };\n>   }\n>\n>   /**\n> diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n> index 3041fd1ed9fd..8d2440026689 100644\n> --- a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n> +++ b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n> @@ -1289,7 +1289,7 @@ Rectangle CameraData::scaleIspCrop(const Rectangle &ispCrop) const\n>   \t */\n>   \tRectangle nativeCrop = ispCrop.scaledBy(sensorInfo_.analogCrop.size(),\n>   \t\t\t\t\t\tsensorInfo_.outputSize);\n> -\tnativeCrop.translateBy(sensorInfo_.analogCrop.topLeft());\n> +\tnativeCrop.translateBy(sensorInfo_.analogCrop.origin());\n>   \treturn nativeCrop;\n>   }\n>\n> @@ -1303,7 +1303,7 @@ void CameraData::applyScalerCrop(const ControlList &controls)\n>   \t\t\tnativeCrop = { 0, 0, 1, 1 };\n>\n>   \t\t/* Create a version of the crop scaled to ISP (camera mode) pixels. */\n> -\t\tRectangle ispCrop = nativeCrop.translatedBy(-sensorInfo_.analogCrop.topLeft());\n> +\t\tRectangle ispCrop = nativeCrop.translatedBy(-sensorInfo_.analogCrop.origin());\n>   \t\tispCrop.scaleBy(sensorInfo_.outputSize, sensorInfo_.analogCrop.size());\n>\n>   \t\t/*\n> diff --git a/src/py/libcamera/py_geometry.cpp b/src/py/libcamera/py_geometry.cpp\n> index c7e303609427..8dee365b25dd 100644\n> --- a/src/py/libcamera/py_geometry.cpp\n> +++ b/src/py/libcamera/py_geometry.cpp\n> @@ -105,7 +105,7 @@ void init_py_geometry(py::module &m)\n>   \t\t.def_property_readonly(\"is_null\", &Rectangle::isNull)\n>   \t\t.def_property_readonly(\"center\", &Rectangle::center)\n>   \t\t.def_property_readonly(\"size\", &Rectangle::size)\n> -\t\t.def_property_readonly(\"topLeft\", &Rectangle::topLeft)\n> +\t\t.def_property_readonly(\"origin\", &Rectangle::origin)\n>   \t\t.def(\"scale_by\", &Rectangle::scaleBy)\n>   \t\t.def(\"translate_by\", &Rectangle::translateBy)\n>   \t\t.def(\"bounded_to\", &Rectangle::boundedTo)\n> diff --git a/test/geometry.cpp b/test/geometry.cpp\n> index 64169206ad16..a4ee6f6e167a 100644\n> --- a/test/geometry.cpp\n> +++ b/test/geometry.cpp\n> @@ -363,16 +363,16 @@ protected:\n>   \t\t\treturn TestFail;\n>   \t\t}\n>\n> -\t\t/* Rectangle::size(), Rectangle::topLeft() and Rectangle::center() tests */\n> +\t\t/* Rectangle::size(), Rectangle::origin() and Rectangle::center() tests */\n>   \t\tif (Rectangle(-1, -2, 3, 4).size() != Size(3, 4) ||\n>   \t\t    Rectangle(0, 0, 100000, 200000).size() != Size(100000, 200000)) {\n>   \t\t\tcout << \"Rectangle::size() test failed\" << endl;\n>   \t\t\treturn TestFail;\n>   \t\t}\n>\n> -\t\tif (Rectangle(1, 2, 3, 4).topLeft() != Point(1, 2) ||\n> -\t\t    Rectangle(-1, -2, 3, 4).topLeft() != Point(-1, -2)) {\n> -\t\t\tcout << \"Rectangle::topLeft() test failed\" << endl;\n> +\t\tif (Rectangle(1, 2, 3, 4).origin() != Point(1, 2) ||\n> +\t\t    Rectangle(-1, -2, 3, 4).origin() != Point(-1, -2)) {\n> +\t\t\tcout << \"Rectangle::origin() test failed\" << endl;\n>   \t\t\treturn TestFail;\n>   \t\t}\n>\n> --\n> 2.46.1\n>","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 BA5DFC3257\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 25 Sep 2024 06:36:13 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id AC3D96350F;\n\tWed, 25 Sep 2024 08:36:12 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 63D95618D8\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 25 Sep 2024 08:36:10 +0200 (CEST)","from [IPV6:2405:201:2015:f873:c173:4b:4a04:3a21] (unknown\n\t[IPv6:2405:201:2015:f873:c173:4b:4a04:3a21])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 5D6DE5B2;\n\tWed, 25 Sep 2024 08:34:42 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"jvy2VSjS\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1727246082;\n\tbh=5IE4sSwzIXivn+YTRROS6Mzn4B7cGHzpf28A2TowD/4=;\n\th=Date:Subject:To:Cc:References:From:In-Reply-To:From;\n\tb=jvy2VSjSQZgAUTruROYUuq3ZJmhIYR66yIRYFRu1Slwb01I/kjZnSlekxSeuQP7/N\n\tSMy/2SYrDNd+OUHw1NnYobQut3BX7UOuIp4BgDwDHR4H3q8h3Yc033h3JO9BbuNj3U\n\t0D8G3PWfIf0g9wno8Otu+P6xSwgYq7s1KwG7XXDY=","Message-ID":"<d975583c-7f5d-4f5b-8e99-5cdc61396667@ideasonboard.com>","Date":"Wed, 25 Sep 2024 12:06:05 +0530","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Subject":"Re: [PATCH] libcamera: geometry: Rename Rectangle's top-left corner","To":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Cc":"chenghaoyang@google.com","References":"<20240924124525.95189-1-jacopo.mondi@ideasonboard.com>","Content-Language":"en-US","From":"Umang Jain <umang.jain@ideasonboard.com>","In-Reply-To":"<20240924124525.95189-1-jacopo.mondi@ideasonboard.com>","Content-Type":"text/plain; charset=UTF-8; format=flowed","Content-Transfer-Encoding":"8bit","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>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":31349,"web_url":"https://patchwork.libcamera.org/comment/31349/","msgid":"<CAC=wSGUwXZDvM68ZfhqPvYKhAB0bkem=zJhFJ-Fjafc9OYhDqA@mail.gmail.com>","date":"2024-09-25T07:09:38","subject":"Re: [PATCH] libcamera: geometry: Rename Rectangle's top-left corner","submitter":{"id":148,"url":"https://patchwork.libcamera.org/api/people/148/","name":"Cheng-Hao Yang","email":"chenghaoyang@google.com"},"content":"Hi Jacopo,\n\nThank you for the patch.\n\nOn Wed, Sep 25, 2024 at 2:36 PM Umang Jain <umang.jain@ideasonboard.com> wrote:\n>\n> Hi Jacopo\n>\n> Thank you for the patch\n>\n> On 24/09/24 6:15 pm, Jacopo Mondi wrote:\n> > The libcamera::Rectangle class should allow defining rectangles\n> > regardless of the reference system where an instance is used in.\n> >\n> > However the class documentation assumes the reference system origin\n> > point to be in the visual top-left side and that rectangles are\n> > constructed by specifying the top-left corner position and sizes.\n> >\n> > However this is ambiguous when using a different reference system as,\n> > in example, constructing a rectangle (x, y, w, h) in the following\n> > scenario, with the origin corner in the top-left position, would require\n> > a negative decrement along the y-axis.\n> >\n> >           ^\n> >           |\n> >          y|      o------------------\n> >           |      |                 | h\n> >           |      |                 |\n> >           |      -------------------\n> >           |               w\n> >            ------------------------------->\n> >           (0,0)  x\n> >\n> > To remove ambiguities, drop references to the visual top-left corner and\n> > define the rectangle's origin corner as the corner closer to the\n> > reference system origin point, and specify the horizontal and vertical\n> > dimensions always increment along their respective axis, as in the\n> > following example.\n> >\n> >           ^\n> >           |\n> >           |      -------------------\n> >           |      ^                 | h\n> >           |      |                 |\n> >          y|      o---->-------------\n> >           |               w\n> >            ------------------------------->\n> >           (0,0)  x\n> >\n> >           (0,0)  x\n> >             ------------------------------>\n> >            |              w\n> >           y|     o---->-------------\n> >            |     |                 | h\n> >            |     v                 |\n> >            |     -------------------\n> >            |\n> >            V\n> >\n> > Also rename for consistency the Rectangle::topLeft() function to\n> > Rectangle::origin() and update its in-tree users.\n> >\n> > Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n> > ---\n> >   include/libcamera/geometry.h                  |  2 +-\n> >   src/ipa/ipu3/algorithms/af.cpp                |  2 +-\n> >   src/libcamera/geometry.cpp                    | 85 ++++++++++++++-----\n> >   .../pipeline/rpi/common/pipeline_base.cpp     |  4 +-\n> >   src/py/libcamera/py_geometry.cpp              |  2 +-\n> >   test/geometry.cpp                             |  8 +-\n> >   6 files changed, 75 insertions(+), 28 deletions(-)\n> >\n> > diff --git a/include/libcamera/geometry.h b/include/libcamera/geometry.h\n> > index 3e6f0f5d7fab..07cb0a7866fe 100644\n> > --- a/include/libcamera/geometry.h\n> > +++ b/include/libcamera/geometry.h\n> > @@ -277,7 +277,7 @@ public:\n> >               return { width, height };\n> >       }\n> >\n> > -     Point topLeft() const\n> > +     Point origin() const\n> >       {\n> >               return { x, y };\n> >       }\n> > diff --git a/src/ipa/ipu3/algorithms/af.cpp b/src/ipa/ipu3/algorithms/af.cpp\n> > index cf68fb59c49b..1b707e9dd9ab 100644\n> > --- a/src/ipa/ipu3/algorithms/af.cpp\n> > +++ b/src/ipa/ipu3/algorithms/af.cpp\n> > @@ -155,7 +155,7 @@ int Af::configure(IPAContext &context, const IPAConfigInfo &configInfo)\n> >        * - Return the AF ROI as metadata in the Request\n> >        */\n> >       Rectangle roi = gridSize.centeredTo(bds.center());\n> > -     Point start = roi.topLeft();\n> > +     Point start = roi.origin();\n> >\n> >       /* x_start and y_start should be even */\n> >       grid.x_start = utils::alignDown(start.x, 2);\n> > diff --git a/src/libcamera/geometry.cpp b/src/libcamera/geometry.cpp\n> > index 000151364c7f..45ba81a99920 100644\n> > --- a/src/libcamera/geometry.cpp\n> > +++ b/src/libcamera/geometry.cpp\n> > @@ -593,11 +593,39 @@ std::ostream &operator<<(std::ostream &out, const SizeRange &sr)\n> >    * \\brief Describe a rectangle's position and dimensions\n> >    *\n> >    * Rectangles are used to identify an area of an image. They are specified by\n> > - * the coordinates of top-left corner and their horizontal and vertical size.\n> > + * the coordinates of the corner closer to the reference system's origin point\n> > + * and by horizontal and vertical increments from there.\n> >    *\n> > - * The measure unit of the rectangle coordinates and size, as well as the\n> > - * reference point from which the Rectangle::x and Rectangle::y displacements\n> > - * refers to, are defined by the context were rectangle is used.\n> > + * The corner closer to the reference system's origin point is the rectangle's\n> > + * origin corner.\n> > + *\n> > + * \\verbatim\n> > +\n> > +  o = origin corner\n> > +\n> > +         ^\n> > +         |\n> > +         |      -------------------\n> > +         |      ^                 |\n> > +         |      |                 |\n> > +         |      o---->-------------\n> > +         |\n> > +          ------------------------------->\n> > +         (0,0)\n> > +\n> > +         (0,0)\n> > +           ------------------------------->\n> > +          |\n> > +          |      o---->-------------\n> > +          |      |                 |\n> > +          |      v                 |\n> > +          |      -------------------\n> > +          |\n> > +          V\n> > +   \\endverbatim\n> > + *\n> > + * The measure unit of the rectangle coordinates and size are defined by the\n> > + * context were the rectangle is used.\n> >    */\n> >\n> >   /**\n> > @@ -608,35 +636,50 @@ std::ostream &operator<<(std::ostream &out, const SizeRange &sr)\n> >   /**\n> >    * \\fn Rectangle::Rectangle(int x, int y, const Size &size)\n> >    * \\brief Construct a Rectangle with the given position and size\n> > - * \\param[in] x The horizontal coordinate of the top-left corner\n> > - * \\param[in] y The vertical coordinate of the top-left corner\n> > + * \\param[in] x The horizontal coordinate of the origin corner\n> > + * \\param[in] y The vertical coordinate of the origin corner\n> >    * \\param[in] size The size\n> > + *\n> > + * The rectangle's origin corner is the corner closer to the reference system\n> > + * origin point (0, 0).\n\nI think we should stick to the previous description:\n`\"origin\" point defined as the point with the lower x and\nlower y of the rectangle`, as `x` and `y` are signed integers.\n\nIf we only support coordinates that are positive or 0, which\nI'm not sure if it's the case, how about making the type to be\n`unsigned int`?\n\nBR,\nHarvey\n\n\n> >    */\n> >\n> >   /**\n> >    * \\fn Rectangle::Rectangle(int x, int y, unsigned int width, unsigned int height)\n> >    * \\brief Construct a Rectangle with the given position and size\n> > - * \\param[in] x The horizontal coordinate of the top-left corner\n> > - * \\param[in] y The vertical coordinate of the top-left corner\n> > + * \\param[in] x The horizontal coordinate of the origin corner\n> > + * \\param[in] y The vertical coordinate of the origin corner\n> >    * \\param[in] width The width\n> >    * \\param[in] height The height\n> > + *\n> > + * The rectangle's origin corner is the corner closer to the reference system\n> > + * origin point (0, 0).\n> >    */\n> >\n> >   /**\n> >    * \\fn Rectangle::Rectangle(const Size &size)\n> > - * \\brief Construct a Rectangle of \\a size with its top left corner located\n> > + * \\brief Construct a Rectangle of \\a size with its origin corner located\n> >    * at (0,0)\n> >    * \\param[in] size The desired Rectangle size\n> > + *\n> > + * The rectangle's origin corner is the corner closer to the reference system\n> > + * origin point (0, 0).\n> >    */\n> >\n> >   /**\n> >    * \\var Rectangle::x\n> > - * \\brief The horizontal coordinate of the rectangle's top-left corner\n> > + * \\brief The horizontal coordinate of the rectangle's origin corner\n> > + *\n> > + * The rectangle's origin corner is the corner closer to the reference system\n> > + * origin point (0, 0).\n> >    */\n> >\n> >   /**\n> >    * \\var Rectangle::y\n> > - * \\brief The vertical coordinate of the rectangle's top-left corner\n> > + * \\brief The vertical coordinate of the rectangle's origin corner\n> > + *\n> > + * The rectangle's origin corner is the corner closer to the reference system\n> > + * origin point (0, 0).\n> >    */\n> >\n> >   /**\n> > @@ -683,9 +726,13 @@ Point Rectangle::center() const\n> >    */\n> >\n> >   /**\n> > - * \\fn Point Rectangle::topLeft() const\n> > - * \\brief Retrieve the coordinates of the top left corner of this Rectangle\n> > - * \\return The Rectangle's top left corner\n> > + * \\fn Point Rectangle::origin() const\n> > + * \\brief Retrieve the coordinates of the origin corner of this Rectangle\n> > + *\n> > + * The rectangle's origin corner is the corner closer to the reference system\n> > + * origin point (0, 0).\n> > + *\n> > + * \\return The Rectangle's origin corner\n>\n> I think you can drop \"corner\" from \"origin corner\"\n>\n> Probably throughout the patch:\n>      s/origin corner/origin/\n>\n> Otherwise, LGTM\n>\n> Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>\n> >    */\n> >\n> >   /**\n> > @@ -740,15 +787,15 @@ Rectangle &Rectangle::translateBy(const Point &point)\n> >    */\n> >   Rectangle Rectangle::boundedTo(const Rectangle &bound) const\n> >   {\n> > -     int topLeftX = std::max(x, bound.x);\n> > -     int topLeftY = std::max(y, bound.y);\n> > +     int originX = std::max(x, bound.x);\n> > +     int originY = std::max(y, bound.y);\n> >       int bottomRightX = std::min<int>(x + width, bound.x + bound.width);\n> >       int bottomRightY = std::min<int>(y + height, bound.y + bound.height);\n> >\n> > -     unsigned int newWidth = std::max(bottomRightX - topLeftX, 0);\n> > -     unsigned int newHeight = std::max(bottomRightY - topLeftY, 0);\n> > +     unsigned int newWidth = std::max(bottomRightX - originX, 0);\n> > +     unsigned int newHeight = std::max(bottomRightY - originY, 0);\n> >\n> > -     return { topLeftX, topLeftY, newWidth, newHeight };\n> > +     return { originX, originY, newWidth, newHeight };\n> >   }\n> >\n> >   /**\n> > diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n> > index 3041fd1ed9fd..8d2440026689 100644\n> > --- a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n> > +++ b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n> > @@ -1289,7 +1289,7 @@ Rectangle CameraData::scaleIspCrop(const Rectangle &ispCrop) const\n> >        */\n> >       Rectangle nativeCrop = ispCrop.scaledBy(sensorInfo_.analogCrop.size(),\n> >                                               sensorInfo_.outputSize);\n> > -     nativeCrop.translateBy(sensorInfo_.analogCrop.topLeft());\n> > +     nativeCrop.translateBy(sensorInfo_.analogCrop.origin());\n> >       return nativeCrop;\n> >   }\n> >\n> > @@ -1303,7 +1303,7 @@ void CameraData::applyScalerCrop(const ControlList &controls)\n> >                       nativeCrop = { 0, 0, 1, 1 };\n> >\n> >               /* Create a version of the crop scaled to ISP (camera mode) pixels. */\n> > -             Rectangle ispCrop = nativeCrop.translatedBy(-sensorInfo_.analogCrop.topLeft());\n> > +             Rectangle ispCrop = nativeCrop.translatedBy(-sensorInfo_.analogCrop.origin());\n> >               ispCrop.scaleBy(sensorInfo_.outputSize, sensorInfo_.analogCrop.size());\n> >\n> >               /*\n> > diff --git a/src/py/libcamera/py_geometry.cpp b/src/py/libcamera/py_geometry.cpp\n> > index c7e303609427..8dee365b25dd 100644\n> > --- a/src/py/libcamera/py_geometry.cpp\n> > +++ b/src/py/libcamera/py_geometry.cpp\n> > @@ -105,7 +105,7 @@ void init_py_geometry(py::module &m)\n> >               .def_property_readonly(\"is_null\", &Rectangle::isNull)\n> >               .def_property_readonly(\"center\", &Rectangle::center)\n> >               .def_property_readonly(\"size\", &Rectangle::size)\n> > -             .def_property_readonly(\"topLeft\", &Rectangle::topLeft)\n> > +             .def_property_readonly(\"origin\", &Rectangle::origin)\n> >               .def(\"scale_by\", &Rectangle::scaleBy)\n> >               .def(\"translate_by\", &Rectangle::translateBy)\n> >               .def(\"bounded_to\", &Rectangle::boundedTo)\n> > diff --git a/test/geometry.cpp b/test/geometry.cpp\n> > index 64169206ad16..a4ee6f6e167a 100644\n> > --- a/test/geometry.cpp\n> > +++ b/test/geometry.cpp\n> > @@ -363,16 +363,16 @@ protected:\n> >                       return TestFail;\n> >               }\n> >\n> > -             /* Rectangle::size(), Rectangle::topLeft() and Rectangle::center() tests */\n> > +             /* Rectangle::size(), Rectangle::origin() and Rectangle::center() tests */\n> >               if (Rectangle(-1, -2, 3, 4).size() != Size(3, 4) ||\n> >                   Rectangle(0, 0, 100000, 200000).size() != Size(100000, 200000)) {\n> >                       cout << \"Rectangle::size() test failed\" << endl;\n> >                       return TestFail;\n> >               }\n> >\n> > -             if (Rectangle(1, 2, 3, 4).topLeft() != Point(1, 2) ||\n> > -                 Rectangle(-1, -2, 3, 4).topLeft() != Point(-1, -2)) {\n> > -                     cout << \"Rectangle::topLeft() test failed\" << endl;\n> > +             if (Rectangle(1, 2, 3, 4).origin() != Point(1, 2) ||\n> > +                 Rectangle(-1, -2, 3, 4).origin() != Point(-1, -2)) {\n> > +                     cout << \"Rectangle::origin() test failed\" << endl;\n> >                       return TestFail;\n> >               }\n> >\n> > --\n> > 2.46.1\n> >\n>","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 AB8BBC3257\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 25 Sep 2024 07:10:18 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 97B926350F;\n\tWed, 25 Sep 2024 09:10:17 +0200 (CEST)","from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com\n\t[IPv6:2a00:1450:4864:20::52c])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 4C1D8634F4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 25 Sep 2024 09:10:16 +0200 (CEST)","by mail-ed1-x52c.google.com with SMTP id\n\t4fb4d7f45d1cf-5c247dd0899so14001a12.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 25 Sep 2024 00:10:16 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key;\n\tunprotected) header.d=google.com header.i=@google.com\n\theader.b=\"2M7mx0MO\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=google.com; s=20230601; t=1727248216; x=1727853016;\n\tdarn=lists.libcamera.org; \n\th=content-transfer-encoding:cc:to:subject:message-id:date:from\n\t:in-reply-to:references:mime-version:from:to:cc:subject:date\n\t:message-id:reply-to;\n\tbh=yeY09YxeVAKtZOHouOQ4R6rWxAILVBif2mSzY8XC87Q=;\n\tb=2M7mx0MOInw4/JUN1WFgh0I77CX12GXpQjTuA568Dcm+scrBATLsGcwMie5xrYE7Mb\n\trjtqrW1Bx1vpBcBunZuunN0w87Eo4VqV+PHwrLIP1EH6WAdP6fv0y8OuvoYDM9HRto6m\n\tzoV+W0QZe3fL0ujopaZir+OhzW26KIT7hlOz+S5Tcizpq2L7zuL3CDT20D1V+ccPcz3k\n\tQwO7NA6VlTsPZNWZGugRGx93Vyv78OVJczt2w9Hyq4Y9cIzLnjdI3ZYEX0dgKKZGo5Mw\n\tq0dDUXE1MgfyhnbpgdbC8n+ccZ19/D2WnjLmgTYNnM5Lf05NkE66EXhl5GTvtFJObcD9\n\t5Zaw==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1727248216; x=1727853016;\n\th=content-transfer-encoding:cc:to:subject:message-id:date:from\n\t:in-reply-to:references:mime-version:x-gm-message-state:from:to:cc\n\t:subject:date:message-id:reply-to;\n\tbh=yeY09YxeVAKtZOHouOQ4R6rWxAILVBif2mSzY8XC87Q=;\n\tb=oPynxn0ExJNZBJFH82/Qc+96LKKUbS/6sBABxYapiCThfNFcrN7Ynyq0YQyMD3+Fvc\n\tvAfi3/UQeuTcrlwtrIkq2Us1/H9CpfRmlK/vJVce/VSRQzyX1uyVp+5gFHanTScrR64A\n\tYZvBjZiiSsh+Sr6P2/VAZTtlQ/57O2Qxbbty8sjacT/SFYQsWdDYkRCOOdK0A/sJ2jeQ\n\tQXDM7pRRyquGR4iTCha/3+CCSzTHCtEOJnY7rcfN82PKz+XcMfCj7oCQiRnlmQL1P5Bv\n\tQxS7nJJjaRNL/p5XIvvHQtJ+ooCMGsLJFF+3t3/4cGCcMZMNdan41hxCsFiBgO65KZkS\n\tZhsA==","X-Forwarded-Encrypted":"i=1;\n\tAJvYcCXseJ2nBUL63k1pLhB42gEysquBSQfeaXpDtAPe0wnV6gQUJw6LTFF1iS7SUDN81lr0klfw7qbIi3v5NQIedeU=@lists.libcamera.org","X-Gm-Message-State":"AOJu0YyMS1HcwoDlH+BDsCIt3hpOIeu9FQsH24MHin8M2qNsjppuj5Q2\n\tsdBjiJDUlxkgT3T/Bf4vWMBSslm51qDaFsZXt/ZcX11l4qJv7JqPU9uQ0DR5H1qQVJlUfXdLSy2\n\tDvgXANwpFGcMu0ycrsLQUxOUrin8uuVygytjQ","X-Google-Smtp-Source":"AGHT+IHU8FXM5VDg8sDmjNYxU6pU5xNPp7AN4m0gXgbEFSLeF1gryhFFnZx+eArGzaASLuu4iRnNFy1GlQGxb6bhnXo=","X-Received":"by 2002:a05:6402:5206:b0:5c5:bb25:5a9c with SMTP id\n\t4fb4d7f45d1cf-5c720fd291dmr204214a12.7.1727248215250; Wed, 25 Sep 2024\n\t00:10:15 -0700 (PDT)","MIME-Version":"1.0","References":"<20240924124525.95189-1-jacopo.mondi@ideasonboard.com>\n\t<d975583c-7f5d-4f5b-8e99-5cdc61396667@ideasonboard.com>","In-Reply-To":"<d975583c-7f5d-4f5b-8e99-5cdc61396667@ideasonboard.com>","From":"Cheng-Hao Yang <chenghaoyang@google.com>","Date":"Wed, 25 Sep 2024 15:09:38 +0800","Message-ID":"<CAC=wSGUwXZDvM68ZfhqPvYKhAB0bkem=zJhFJ-Fjafc9OYhDqA@mail.gmail.com>","Subject":"Re: [PATCH] libcamera: geometry: Rename Rectangle's top-left corner","To":"Umang Jain <umang.jain@ideasonboard.com>","Cc":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Content-Type":"text/plain; charset=\"UTF-8\"","Content-Transfer-Encoding":"quoted-printable","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>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":31373,"web_url":"https://patchwork.libcamera.org/comment/31373/","msgid":"<hgq4tkusdwmyoagxsnbilhmz54mc7mlzckw3ylmoii5qgtb4oi@pgilpcfrxc6p>","date":"2024-09-26T07:55:36","subject":"Re: [PATCH] libcamera: geometry: Rename Rectangle's top-left corner","submitter":{"id":143,"url":"https://patchwork.libcamera.org/api/people/143/","name":"Jacopo Mondi","email":"jacopo.mondi@ideasonboard.com"},"content":"Hi Umang\n\nOn Wed, Sep 25, 2024 at 12:06:05PM GMT, Umang Jain wrote:\n> Hi Jacopo\n>\n> Thank you for the patch\n>\n> On 24/09/24 6:15 pm, Jacopo Mondi wrote:\n> > The libcamera::Rectangle class should allow defining rectangles\n> > regardless of the reference system where an instance is used in.\n> >\n> > However the class documentation assumes the reference system origin\n> > point to be in the visual top-left side and that rectangles are\n> > constructed by specifying the top-left corner position and sizes.\n> >\n> > However this is ambiguous when using a different reference system as,\n> > in example, constructing a rectangle (x, y, w, h) in the following\n> > scenario, with the origin corner in the top-left position, would require\n> > a negative decrement along the y-axis.\n> >\n> >           ^\n> >           |\n> >          y|      o------------------\n> >           |      |                 | h\n> >           |      |                 |\n> >           |      -------------------\n> >           |               w\n> >            ------------------------------->\n> >           (0,0)  x\n> >\n> > To remove ambiguities, drop references to the visual top-left corner and\n> > define the rectangle's origin corner as the corner closer to the\n> > reference system origin point, and specify the horizontal and vertical\n> > dimensions always increment along their respective axis, as in the\n> > following example.\n> >\n> >           ^\n> >           |\n> >           |      -------------------\n> >           |      ^                 | h\n> >           |      |                 |\n> >          y|      o---->-------------\n> >           |               w\n> >            ------------------------------->\n> >           (0,0)  x\n> >\n> >           (0,0)  x\n> >             ------------------------------>\n> >            |              w\n> >           y|     o---->-------------\n> >            |     |                 | h\n> >            |     v                 |\n> >            |     -------------------\n> >            |\n> >            V\n> >\n> > Also rename for consistency the Rectangle::topLeft() function to\n> > Rectangle::origin() and update its in-tree users.\n> >\n> > Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n> > ---\n> >   include/libcamera/geometry.h                  |  2 +-\n> >   src/ipa/ipu3/algorithms/af.cpp                |  2 +-\n> >   src/libcamera/geometry.cpp                    | 85 ++++++++++++++-----\n> >   .../pipeline/rpi/common/pipeline_base.cpp     |  4 +-\n> >   src/py/libcamera/py_geometry.cpp              |  2 +-\n> >   test/geometry.cpp                             |  8 +-\n> >   6 files changed, 75 insertions(+), 28 deletions(-)\n> >\n> > diff --git a/include/libcamera/geometry.h b/include/libcamera/geometry.h\n> > index 3e6f0f5d7fab..07cb0a7866fe 100644\n> > --- a/include/libcamera/geometry.h\n> > +++ b/include/libcamera/geometry.h\n> > @@ -277,7 +277,7 @@ public:\n> >   \t\treturn { width, height };\n> >   \t}\n> >\n> > -\tPoint topLeft() const\n> > +\tPoint origin() const\n> >   \t{\n> >   \t\treturn { x, y };\n> >   \t}\n> > diff --git a/src/ipa/ipu3/algorithms/af.cpp b/src/ipa/ipu3/algorithms/af.cpp\n> > index cf68fb59c49b..1b707e9dd9ab 100644\n> > --- a/src/ipa/ipu3/algorithms/af.cpp\n> > +++ b/src/ipa/ipu3/algorithms/af.cpp\n> > @@ -155,7 +155,7 @@ int Af::configure(IPAContext &context, const IPAConfigInfo &configInfo)\n> >   \t * - Return the AF ROI as metadata in the Request\n> >   \t */\n> >   \tRectangle roi = gridSize.centeredTo(bds.center());\n> > -\tPoint start = roi.topLeft();\n> > +\tPoint start = roi.origin();\n> >\n> >   \t/* x_start and y_start should be even */\n> >   \tgrid.x_start = utils::alignDown(start.x, 2);\n> > diff --git a/src/libcamera/geometry.cpp b/src/libcamera/geometry.cpp\n> > index 000151364c7f..45ba81a99920 100644\n> > --- a/src/libcamera/geometry.cpp\n> > +++ b/src/libcamera/geometry.cpp\n> > @@ -593,11 +593,39 @@ std::ostream &operator<<(std::ostream &out, const SizeRange &sr)\n> >    * \\brief Describe a rectangle's position and dimensions\n> >    *\n> >    * Rectangles are used to identify an area of an image. They are specified by\n> > - * the coordinates of top-left corner and their horizontal and vertical size.\n> > + * the coordinates of the corner closer to the reference system's origin point\n> > + * and by horizontal and vertical increments from there.\n> >    *\n> > - * The measure unit of the rectangle coordinates and size, as well as the\n> > - * reference point from which the Rectangle::x and Rectangle::y displacements\n> > - * refers to, are defined by the context were rectangle is used.\n> > + * The corner closer to the reference system's origin point is the rectangle's\n> > + * origin corner.\n> > + *\n> > + * \\verbatim\n> > +\n> > +  o = origin corner\n> > +\n> > +         ^\n> > +         |\n> > +         |      -------------------\n> > +         |      ^                 |\n> > +         |      |                 |\n> > +         |      o---->-------------\n> > +         |\n> > +          ------------------------------->\n> > +         (0,0)\n> > +\n> > +         (0,0)\n> > +           ------------------------------->\n> > +          |\n> > +          |      o---->-------------\n> > +          |      |                 |\n> > +          |      v                 |\n> > +          |      -------------------\n> > +          |\n> > +          V\n> > +   \\endverbatim\n> > + *\n> > + * The measure unit of the rectangle coordinates and size are defined by the\n> > + * context were the rectangle is used.\n> >    */\n> >\n> >   /**\n> > @@ -608,35 +636,50 @@ std::ostream &operator<<(std::ostream &out, const SizeRange &sr)\n> >   /**\n> >    * \\fn Rectangle::Rectangle(int x, int y, const Size &size)\n> >    * \\brief Construct a Rectangle with the given position and size\n> > - * \\param[in] x The horizontal coordinate of the top-left corner\n> > - * \\param[in] y The vertical coordinate of the top-left corner\n> > + * \\param[in] x The horizontal coordinate of the origin corner\n> > + * \\param[in] y The vertical coordinate of the origin corner\n> >    * \\param[in] size The size\n> > + *\n> > + * The rectangle's origin corner is the corner closer to the reference system\n> > + * origin point (0, 0).\n> >    */\n> >\n> >   /**\n> >    * \\fn Rectangle::Rectangle(int x, int y, unsigned int width, unsigned int height)\n> >    * \\brief Construct a Rectangle with the given position and size\n> > - * \\param[in] x The horizontal coordinate of the top-left corner\n> > - * \\param[in] y The vertical coordinate of the top-left corner\n> > + * \\param[in] x The horizontal coordinate of the origin corner\n> > + * \\param[in] y The vertical coordinate of the origin corner\n> >    * \\param[in] width The width\n> >    * \\param[in] height The height\n> > + *\n> > + * The rectangle's origin corner is the corner closer to the reference system\n> > + * origin point (0, 0).\n> >    */\n> >\n> >   /**\n> >    * \\fn Rectangle::Rectangle(const Size &size)\n> > - * \\brief Construct a Rectangle of \\a size with its top left corner located\n> > + * \\brief Construct a Rectangle of \\a size with its origin corner located\n> >    * at (0,0)\n> >    * \\param[in] size The desired Rectangle size\n> > + *\n> > + * The rectangle's origin corner is the corner closer to the reference system\n> > + * origin point (0, 0).\n> >    */\n> >\n> >   /**\n> >    * \\var Rectangle::x\n> > - * \\brief The horizontal coordinate of the rectangle's top-left corner\n> > + * \\brief The horizontal coordinate of the rectangle's origin corner\n> > + *\n> > + * The rectangle's origin corner is the corner closer to the reference system\n> > + * origin point (0, 0).\n> >    */\n> >\n> >   /**\n> >    * \\var Rectangle::y\n> > - * \\brief The vertical coordinate of the rectangle's top-left corner\n> > + * \\brief The vertical coordinate of the rectangle's origin corner\n> > + *\n> > + * The rectangle's origin corner is the corner closer to the reference system\n> > + * origin point (0, 0).\n> >    */\n> >\n> >   /**\n> > @@ -683,9 +726,13 @@ Point Rectangle::center() const\n> >    */\n> >\n> >   /**\n> > - * \\fn Point Rectangle::topLeft() const\n> > - * \\brief Retrieve the coordinates of the top left corner of this Rectangle\n> > - * \\return The Rectangle's top left corner\n> > + * \\fn Point Rectangle::origin() const\n> > + * \\brief Retrieve the coordinates of the origin corner of this Rectangle\n> > + *\n> > + * The rectangle's origin corner is the corner closer to the reference system\n> > + * origin point (0, 0).\n> > + *\n> > + * \\return The Rectangle's origin corner\n>\n> I think you can drop \"corner\" from \"origin corner\"\n>\n> Probably throughout the patch:\n>     s/origin corner/origin/\n>\n\nI considered that, but as a \"rectangle origin\" is not a well-defined\nterm in geometry I prefer to specify it's a corner. Is this ok ?\n\n> Otherwise, LGTM\n>\n> Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>\n\nThanks\n  j\n\n> >    */\n> >\n> >   /**\n> > @@ -740,15 +787,15 @@ Rectangle &Rectangle::translateBy(const Point &point)\n> >    */\n> >   Rectangle Rectangle::boundedTo(const Rectangle &bound) const\n> >   {\n> > -\tint topLeftX = std::max(x, bound.x);\n> > -\tint topLeftY = std::max(y, bound.y);\n> > +\tint originX = std::max(x, bound.x);\n> > +\tint originY = std::max(y, bound.y);\n> >   \tint bottomRightX = std::min<int>(x + width, bound.x + bound.width);\n> >   \tint bottomRightY = std::min<int>(y + height, bound.y + bound.height);\n> >\n> > -\tunsigned int newWidth = std::max(bottomRightX - topLeftX, 0);\n> > -\tunsigned int newHeight = std::max(bottomRightY - topLeftY, 0);\n> > +\tunsigned int newWidth = std::max(bottomRightX - originX, 0);\n> > +\tunsigned int newHeight = std::max(bottomRightY - originY, 0);\n> >\n> > -\treturn { topLeftX, topLeftY, newWidth, newHeight };\n> > +\treturn { originX, originY, newWidth, newHeight };\n> >   }\n> >\n> >   /**\n> > diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n> > index 3041fd1ed9fd..8d2440026689 100644\n> > --- a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n> > +++ b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n> > @@ -1289,7 +1289,7 @@ Rectangle CameraData::scaleIspCrop(const Rectangle &ispCrop) const\n> >   \t */\n> >   \tRectangle nativeCrop = ispCrop.scaledBy(sensorInfo_.analogCrop.size(),\n> >   \t\t\t\t\t\tsensorInfo_.outputSize);\n> > -\tnativeCrop.translateBy(sensorInfo_.analogCrop.topLeft());\n> > +\tnativeCrop.translateBy(sensorInfo_.analogCrop.origin());\n> >   \treturn nativeCrop;\n> >   }\n> >\n> > @@ -1303,7 +1303,7 @@ void CameraData::applyScalerCrop(const ControlList &controls)\n> >   \t\t\tnativeCrop = { 0, 0, 1, 1 };\n> >\n> >   \t\t/* Create a version of the crop scaled to ISP (camera mode) pixels. */\n> > -\t\tRectangle ispCrop = nativeCrop.translatedBy(-sensorInfo_.analogCrop.topLeft());\n> > +\t\tRectangle ispCrop = nativeCrop.translatedBy(-sensorInfo_.analogCrop.origin());\n> >   \t\tispCrop.scaleBy(sensorInfo_.outputSize, sensorInfo_.analogCrop.size());\n> >\n> >   \t\t/*\n> > diff --git a/src/py/libcamera/py_geometry.cpp b/src/py/libcamera/py_geometry.cpp\n> > index c7e303609427..8dee365b25dd 100644\n> > --- a/src/py/libcamera/py_geometry.cpp\n> > +++ b/src/py/libcamera/py_geometry.cpp\n> > @@ -105,7 +105,7 @@ void init_py_geometry(py::module &m)\n> >   \t\t.def_property_readonly(\"is_null\", &Rectangle::isNull)\n> >   \t\t.def_property_readonly(\"center\", &Rectangle::center)\n> >   \t\t.def_property_readonly(\"size\", &Rectangle::size)\n> > -\t\t.def_property_readonly(\"topLeft\", &Rectangle::topLeft)\n> > +\t\t.def_property_readonly(\"origin\", &Rectangle::origin)\n> >   \t\t.def(\"scale_by\", &Rectangle::scaleBy)\n> >   \t\t.def(\"translate_by\", &Rectangle::translateBy)\n> >   \t\t.def(\"bounded_to\", &Rectangle::boundedTo)\n> > diff --git a/test/geometry.cpp b/test/geometry.cpp\n> > index 64169206ad16..a4ee6f6e167a 100644\n> > --- a/test/geometry.cpp\n> > +++ b/test/geometry.cpp\n> > @@ -363,16 +363,16 @@ protected:\n> >   \t\t\treturn TestFail;\n> >   \t\t}\n> >\n> > -\t\t/* Rectangle::size(), Rectangle::topLeft() and Rectangle::center() tests */\n> > +\t\t/* Rectangle::size(), Rectangle::origin() and Rectangle::center() tests */\n> >   \t\tif (Rectangle(-1, -2, 3, 4).size() != Size(3, 4) ||\n> >   \t\t    Rectangle(0, 0, 100000, 200000).size() != Size(100000, 200000)) {\n> >   \t\t\tcout << \"Rectangle::size() test failed\" << endl;\n> >   \t\t\treturn TestFail;\n> >   \t\t}\n> >\n> > -\t\tif (Rectangle(1, 2, 3, 4).topLeft() != Point(1, 2) ||\n> > -\t\t    Rectangle(-1, -2, 3, 4).topLeft() != Point(-1, -2)) {\n> > -\t\t\tcout << \"Rectangle::topLeft() test failed\" << endl;\n> > +\t\tif (Rectangle(1, 2, 3, 4).origin() != Point(1, 2) ||\n> > +\t\t    Rectangle(-1, -2, 3, 4).origin() != Point(-1, -2)) {\n> > +\t\t\tcout << \"Rectangle::origin() test failed\" << endl;\n> >   \t\t\treturn TestFail;\n> >   \t\t}\n> >\n> > --\n> > 2.46.1\n> >\n>","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 BF79DC0F1B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 26 Sep 2024 07:55:43 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 5EB976350E;\n\tThu, 26 Sep 2024 09:55:42 +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 38B97634F2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 26 Sep 2024 09:55:41 +0200 (CEST)","from ideasonboard.com (mob-5-90-51-229.net.vodafone.it\n\t[5.90.51.229])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id DAC6A8D4;\n\tThu, 26 Sep 2024 09:54:12 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"b/0p75BF\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1727337253;\n\tbh=UiSfEhD9umBD5KdNCkVq5cev374VPaRqH/74uBjRSOE=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=b/0p75BFf9RRrVOaNOadeeVWWri+67OMx7FwfkMio3wn8lwodldb3/Zi5C0XEhNfU\n\ta9xzcs1la0RwgH2fSHMXyyhcJQYQcRxDiqlsWum6qr+/oc7HMjVrBPS5wfHhk1Z1s4\n\tkljJbYBJ1H3r9pQrjz8cny0haJC8pC0YEWQZUg1g=","Date":"Thu, 26 Sep 2024 09:55:36 +0200","From":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>","To":"Umang Jain <umang.jain@ideasonboard.com>","Cc":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>, \n\tlibcamera-devel@lists.libcamera.org, chenghaoyang@google.com","Subject":"Re: [PATCH] libcamera: geometry: Rename Rectangle's top-left corner","Message-ID":"<hgq4tkusdwmyoagxsnbilhmz54mc7mlzckw3ylmoii5qgtb4oi@pgilpcfrxc6p>","References":"<20240924124525.95189-1-jacopo.mondi@ideasonboard.com>\n\t<d975583c-7f5d-4f5b-8e99-5cdc61396667@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<d975583c-7f5d-4f5b-8e99-5cdc61396667@ideasonboard.com>","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>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":31374,"web_url":"https://patchwork.libcamera.org/comment/31374/","msgid":"<uzptnxdipytxx4nwqusnr62asaiwrdawylf2f3vzbmkc53onhc@nkeomtxtfw5g>","date":"2024-09-26T08:03:20","subject":"Re: [PATCH] libcamera: geometry: Rename Rectangle's top-left corner","submitter":{"id":143,"url":"https://patchwork.libcamera.org/api/people/143/","name":"Jacopo Mondi","email":"jacopo.mondi@ideasonboard.com"},"content":"Hi Harvey\n\nOn Wed, Sep 25, 2024 at 03:09:38PM GMT, Cheng-Hao Yang wrote:\n> Hi Jacopo,\n>\n> Thank you for the patch.\n>\n> On Wed, Sep 25, 2024 at 2:36 PM Umang Jain <umang.jain@ideasonboard.com> wrote:\n> >\n> > Hi Jacopo\n> >\n> > Thank you for the patch\n> >\n> > On 24/09/24 6:15 pm, Jacopo Mondi wrote:\n> > > The libcamera::Rectangle class should allow defining rectangles\n> > > regardless of the reference system where an instance is used in.\n> > >\n> > > However the class documentation assumes the reference system origin\n> > > point to be in the visual top-left side and that rectangles are\n> > > constructed by specifying the top-left corner position and sizes.\n> > >\n> > > However this is ambiguous when using a different reference system as,\n> > > in example, constructing a rectangle (x, y, w, h) in the following\n> > > scenario, with the origin corner in the top-left position, would require\n> > > a negative decrement along the y-axis.\n> > >\n> > >           ^\n> > >           |\n> > >          y|      o------------------\n> > >           |      |                 | h\n> > >           |      |                 |\n> > >           |      -------------------\n> > >           |               w\n> > >            ------------------------------->\n> > >           (0,0)  x\n> > >\n> > > To remove ambiguities, drop references to the visual top-left corner and\n> > > define the rectangle's origin corner as the corner closer to the\n> > > reference system origin point, and specify the horizontal and vertical\n> > > dimensions always increment along their respective axis, as in the\n> > > following example.\n> > >\n> > >           ^\n> > >           |\n> > >           |      -------------------\n> > >           |      ^                 | h\n> > >           |      |                 |\n> > >          y|      o---->-------------\n> > >           |               w\n> > >            ------------------------------->\n> > >           (0,0)  x\n> > >\n> > >           (0,0)  x\n> > >             ------------------------------>\n> > >            |              w\n> > >           y|     o---->-------------\n> > >            |     |                 | h\n> > >            |     v                 |\n> > >            |     -------------------\n> > >            |\n> > >            V\n> > >\n> > > Also rename for consistency the Rectangle::topLeft() function to\n> > > Rectangle::origin() and update its in-tree users.\n> > >\n> > > Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n> > > ---\n> > >   include/libcamera/geometry.h                  |  2 +-\n> > >   src/ipa/ipu3/algorithms/af.cpp                |  2 +-\n> > >   src/libcamera/geometry.cpp                    | 85 ++++++++++++++-----\n> > >   .../pipeline/rpi/common/pipeline_base.cpp     |  4 +-\n> > >   src/py/libcamera/py_geometry.cpp              |  2 +-\n> > >   test/geometry.cpp                             |  8 +-\n> > >   6 files changed, 75 insertions(+), 28 deletions(-)\n> > >\n> > > diff --git a/include/libcamera/geometry.h b/include/libcamera/geometry.h\n> > > index 3e6f0f5d7fab..07cb0a7866fe 100644\n> > > --- a/include/libcamera/geometry.h\n> > > +++ b/include/libcamera/geometry.h\n> > > @@ -277,7 +277,7 @@ public:\n> > >               return { width, height };\n> > >       }\n> > >\n> > > -     Point topLeft() const\n> > > +     Point origin() const\n> > >       {\n> > >               return { x, y };\n> > >       }\n> > > diff --git a/src/ipa/ipu3/algorithms/af.cpp b/src/ipa/ipu3/algorithms/af.cpp\n> > > index cf68fb59c49b..1b707e9dd9ab 100644\n> > > --- a/src/ipa/ipu3/algorithms/af.cpp\n> > > +++ b/src/ipa/ipu3/algorithms/af.cpp\n> > > @@ -155,7 +155,7 @@ int Af::configure(IPAContext &context, const IPAConfigInfo &configInfo)\n> > >        * - Return the AF ROI as metadata in the Request\n> > >        */\n> > >       Rectangle roi = gridSize.centeredTo(bds.center());\n> > > -     Point start = roi.topLeft();\n> > > +     Point start = roi.origin();\n> > >\n> > >       /* x_start and y_start should be even */\n> > >       grid.x_start = utils::alignDown(start.x, 2);\n> > > diff --git a/src/libcamera/geometry.cpp b/src/libcamera/geometry.cpp\n> > > index 000151364c7f..45ba81a99920 100644\n> > > --- a/src/libcamera/geometry.cpp\n> > > +++ b/src/libcamera/geometry.cpp\n> > > @@ -593,11 +593,39 @@ std::ostream &operator<<(std::ostream &out, const SizeRange &sr)\n> > >    * \\brief Describe a rectangle's position and dimensions\n> > >    *\n> > >    * Rectangles are used to identify an area of an image. They are specified by\n> > > - * the coordinates of top-left corner and their horizontal and vertical size.\n> > > + * the coordinates of the corner closer to the reference system's origin point\n> > > + * and by horizontal and vertical increments from there.\n> > >    *\n> > > - * The measure unit of the rectangle coordinates and size, as well as the\n> > > - * reference point from which the Rectangle::x and Rectangle::y displacements\n> > > - * refers to, are defined by the context were rectangle is used.\n> > > + * The corner closer to the reference system's origin point is the rectangle's\n> > > + * origin corner.\n> > > + *\n> > > + * \\verbatim\n> > > +\n> > > +  o = origin corner\n> > > +\n> > > +         ^\n> > > +         |\n> > > +         |      -------------------\n> > > +         |      ^                 |\n> > > +         |      |                 |\n> > > +         |      o---->-------------\n> > > +         |\n> > > +          ------------------------------->\n> > > +         (0,0)\n> > > +\n> > > +         (0,0)\n> > > +           ------------------------------->\n> > > +          |\n> > > +          |      o---->-------------\n> > > +          |      |                 |\n> > > +          |      v                 |\n> > > +          |      -------------------\n> > > +          |\n> > > +          V\n> > > +   \\endverbatim\n> > > + *\n> > > + * The measure unit of the rectangle coordinates and size are defined by the\n> > > + * context were the rectangle is used.\n> > >    */\n> > >\n> > >   /**\n> > > @@ -608,35 +636,50 @@ std::ostream &operator<<(std::ostream &out, const SizeRange &sr)\n> > >   /**\n> > >    * \\fn Rectangle::Rectangle(int x, int y, const Size &size)\n> > >    * \\brief Construct a Rectangle with the given position and size\n> > > - * \\param[in] x The horizontal coordinate of the top-left corner\n> > > - * \\param[in] y The vertical coordinate of the top-left corner\n> > > + * \\param[in] x The horizontal coordinate of the origin corner\n> > > + * \\param[in] y The vertical coordinate of the origin corner\n> > >    * \\param[in] size The size\n> > > + *\n> > > + * The rectangle's origin corner is the corner closer to the reference system\n> > > + * origin point (0, 0).\n>\n> I think we should stick to the previous description:\n> `\"origin\" point defined as the point with the lower x and\n> lower y of the rectangle`, as `x` and `y` are signed integers.\n>\n> If we only support coordinates that are positive or 0, which\n> I'm not sure if it's the case, how about making the type to be\n> `unsigned int`?\n>\n\nTo be honest I would rather make width and heigh signed to allow\nconstructing (x, y, -w, -h)\n\n\n\n\n               -------------------\n               |                 ^\n               |            ------------->\n               |           |     |\n               ------<-----|-----o\n                           |\n                           |\n                           V\n\nNot sure if it's useful or not though\n\n\n> BR,\n> Harvey\n>\n>\n> > >    */\n> > >\n> > >   /**\n> > >    * \\fn Rectangle::Rectangle(int x, int y, unsigned int width, unsigned int height)\n> > >    * \\brief Construct a Rectangle with the given position and size\n> > > - * \\param[in] x The horizontal coordinate of the top-left corner\n> > > - * \\param[in] y The vertical coordinate of the top-left corner\n> > > + * \\param[in] x The horizontal coordinate of the origin corner\n> > > + * \\param[in] y The vertical coordinate of the origin corner\n> > >    * \\param[in] width The width\n> > >    * \\param[in] height The height\n> > > + *\n> > > + * The rectangle's origin corner is the corner closer to the reference system\n> > > + * origin point (0, 0).\n> > >    */\n> > >\n> > >   /**\n> > >    * \\fn Rectangle::Rectangle(const Size &size)\n> > > - * \\brief Construct a Rectangle of \\a size with its top left corner located\n> > > + * \\brief Construct a Rectangle of \\a size with its origin corner located\n> > >    * at (0,0)\n> > >    * \\param[in] size The desired Rectangle size\n> > > + *\n> > > + * The rectangle's origin corner is the corner closer to the reference system\n> > > + * origin point (0, 0).\n> > >    */\n> > >\n> > >   /**\n> > >    * \\var Rectangle::x\n> > > - * \\brief The horizontal coordinate of the rectangle's top-left corner\n> > > + * \\brief The horizontal coordinate of the rectangle's origin corner\n> > > + *\n> > > + * The rectangle's origin corner is the corner closer to the reference system\n> > > + * origin point (0, 0).\n> > >    */\n> > >\n> > >   /**\n> > >    * \\var Rectangle::y\n> > > - * \\brief The vertical coordinate of the rectangle's top-left corner\n> > > + * \\brief The vertical coordinate of the rectangle's origin corner\n> > > + *\n> > > + * The rectangle's origin corner is the corner closer to the reference system\n> > > + * origin point (0, 0).\n> > >    */\n> > >\n> > >   /**\n> > > @@ -683,9 +726,13 @@ Point Rectangle::center() const\n> > >    */\n> > >\n> > >   /**\n> > > - * \\fn Point Rectangle::topLeft() const\n> > > - * \\brief Retrieve the coordinates of the top left corner of this Rectangle\n> > > - * \\return The Rectangle's top left corner\n> > > + * \\fn Point Rectangle::origin() const\n> > > + * \\brief Retrieve the coordinates of the origin corner of this Rectangle\n> > > + *\n> > > + * The rectangle's origin corner is the corner closer to the reference system\n> > > + * origin point (0, 0).\n> > > + *\n> > > + * \\return The Rectangle's origin corner\n> >\n> > I think you can drop \"corner\" from \"origin corner\"\n> >\n> > Probably throughout the patch:\n> >      s/origin corner/origin/\n> >\n> > Otherwise, LGTM\n> >\n> > Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>\n> > >    */\n> > >\n> > >   /**\n> > > @@ -740,15 +787,15 @@ Rectangle &Rectangle::translateBy(const Point &point)\n> > >    */\n> > >   Rectangle Rectangle::boundedTo(const Rectangle &bound) const\n> > >   {\n> > > -     int topLeftX = std::max(x, bound.x);\n> > > -     int topLeftY = std::max(y, bound.y);\n> > > +     int originX = std::max(x, bound.x);\n> > > +     int originY = std::max(y, bound.y);\n> > >       int bottomRightX = std::min<int>(x + width, bound.x + bound.width);\n> > >       int bottomRightY = std::min<int>(y + height, bound.y + bound.height);\n> > >\n> > > -     unsigned int newWidth = std::max(bottomRightX - topLeftX, 0);\n> > > -     unsigned int newHeight = std::max(bottomRightY - topLeftY, 0);\n> > > +     unsigned int newWidth = std::max(bottomRightX - originX, 0);\n> > > +     unsigned int newHeight = std::max(bottomRightY - originY, 0);\n> > >\n> > > -     return { topLeftX, topLeftY, newWidth, newHeight };\n> > > +     return { originX, originY, newWidth, newHeight };\n> > >   }\n> > >\n> > >   /**\n> > > diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n> > > index 3041fd1ed9fd..8d2440026689 100644\n> > > --- a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n> > > +++ b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n> > > @@ -1289,7 +1289,7 @@ Rectangle CameraData::scaleIspCrop(const Rectangle &ispCrop) const\n> > >        */\n> > >       Rectangle nativeCrop = ispCrop.scaledBy(sensorInfo_.analogCrop.size(),\n> > >                                               sensorInfo_.outputSize);\n> > > -     nativeCrop.translateBy(sensorInfo_.analogCrop.topLeft());\n> > > +     nativeCrop.translateBy(sensorInfo_.analogCrop.origin());\n> > >       return nativeCrop;\n> > >   }\n> > >\n> > > @@ -1303,7 +1303,7 @@ void CameraData::applyScalerCrop(const ControlList &controls)\n> > >                       nativeCrop = { 0, 0, 1, 1 };\n> > >\n> > >               /* Create a version of the crop scaled to ISP (camera mode) pixels. */\n> > > -             Rectangle ispCrop = nativeCrop.translatedBy(-sensorInfo_.analogCrop.topLeft());\n> > > +             Rectangle ispCrop = nativeCrop.translatedBy(-sensorInfo_.analogCrop.origin());\n> > >               ispCrop.scaleBy(sensorInfo_.outputSize, sensorInfo_.analogCrop.size());\n> > >\n> > >               /*\n> > > diff --git a/src/py/libcamera/py_geometry.cpp b/src/py/libcamera/py_geometry.cpp\n> > > index c7e303609427..8dee365b25dd 100644\n> > > --- a/src/py/libcamera/py_geometry.cpp\n> > > +++ b/src/py/libcamera/py_geometry.cpp\n> > > @@ -105,7 +105,7 @@ void init_py_geometry(py::module &m)\n> > >               .def_property_readonly(\"is_null\", &Rectangle::isNull)\n> > >               .def_property_readonly(\"center\", &Rectangle::center)\n> > >               .def_property_readonly(\"size\", &Rectangle::size)\n> > > -             .def_property_readonly(\"topLeft\", &Rectangle::topLeft)\n> > > +             .def_property_readonly(\"origin\", &Rectangle::origin)\n> > >               .def(\"scale_by\", &Rectangle::scaleBy)\n> > >               .def(\"translate_by\", &Rectangle::translateBy)\n> > >               .def(\"bounded_to\", &Rectangle::boundedTo)\n> > > diff --git a/test/geometry.cpp b/test/geometry.cpp\n> > > index 64169206ad16..a4ee6f6e167a 100644\n> > > --- a/test/geometry.cpp\n> > > +++ b/test/geometry.cpp\n> > > @@ -363,16 +363,16 @@ protected:\n> > >                       return TestFail;\n> > >               }\n> > >\n> > > -             /* Rectangle::size(), Rectangle::topLeft() and Rectangle::center() tests */\n> > > +             /* Rectangle::size(), Rectangle::origin() and Rectangle::center() tests */\n> > >               if (Rectangle(-1, -2, 3, 4).size() != Size(3, 4) ||\n> > >                   Rectangle(0, 0, 100000, 200000).size() != Size(100000, 200000)) {\n> > >                       cout << \"Rectangle::size() test failed\" << endl;\n> > >                       return TestFail;\n> > >               }\n> > >\n> > > -             if (Rectangle(1, 2, 3, 4).topLeft() != Point(1, 2) ||\n> > > -                 Rectangle(-1, -2, 3, 4).topLeft() != Point(-1, -2)) {\n> > > -                     cout << \"Rectangle::topLeft() test failed\" << endl;\n> > > +             if (Rectangle(1, 2, 3, 4).origin() != Point(1, 2) ||\n> > > +                 Rectangle(-1, -2, 3, 4).origin() != Point(-1, -2)) {\n> > > +                     cout << \"Rectangle::origin() test failed\" << endl;\n> > >                       return TestFail;\n> > >               }\n> > >\n> > > --\n> > > 2.46.1\n> > >\n> >\n>\n>\n> --\n> BR,\n> Harvey Yang","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 79DEFC3257\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 26 Sep 2024 08:03:27 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 39F946350F;\n\tThu, 26 Sep 2024 10:03:26 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id D1ABF634FB\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 26 Sep 2024 10:03:24 +0200 (CEST)","from ideasonboard.com (mob-5-90-51-229.net.vodafone.it\n\t[5.90.51.229])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 77A50169;\n\tThu, 26 Sep 2024 10:01:56 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"GgmKwq+H\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1727337716;\n\tbh=yM5zeRyO7UEvG3vByXmDhM4qckhtLjgvuY70evPcLsk=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=GgmKwq+HrfDpeASelNeTDDfZ+g4EDasarEFRPSNX2gyDi/Xv8qVEH7XdDvJTEtZ8d\n\tiiOmsKTNkfMazZMSTwJswm3XFeY3qKEmUhxfwMMh66Eu7iLiP7s5oHLc3mFHIY4mDH\n\tdF25NeWE97jmyCz3J38lW3rY95fVGnpFUY08zeVg=","Date":"Thu, 26 Sep 2024 10:03:20 +0200","From":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>","To":"Cheng-Hao Yang <chenghaoyang@google.com>","Cc":"Umang Jain <umang.jain@ideasonboard.com>, \n\tJacopo Mondi <jacopo.mondi@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Subject":"Re: [PATCH] libcamera: geometry: Rename Rectangle's top-left corner","Message-ID":"<uzptnxdipytxx4nwqusnr62asaiwrdawylf2f3vzbmkc53onhc@nkeomtxtfw5g>","References":"<20240924124525.95189-1-jacopo.mondi@ideasonboard.com>\n\t<d975583c-7f5d-4f5b-8e99-5cdc61396667@ideasonboard.com>\n\t<CAC=wSGUwXZDvM68ZfhqPvYKhAB0bkem=zJhFJ-Fjafc9OYhDqA@mail.gmail.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<CAC=wSGUwXZDvM68ZfhqPvYKhAB0bkem=zJhFJ-Fjafc9OYhDqA@mail.gmail.com>","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>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":31377,"web_url":"https://patchwork.libcamera.org/comment/31377/","msgid":"<CAC=wSGWEZU7_=nEFTp+g_g74L7kcs65wK3oOeS8xwBqzMHa5wQ@mail.gmail.com>","date":"2024-09-26T08:29:50","subject":"Re: [PATCH] libcamera: geometry: Rename Rectangle's top-left corner","submitter":{"id":148,"url":"https://patchwork.libcamera.org/api/people/148/","name":"Cheng-Hao Yang","email":"chenghaoyang@google.com"},"content":"Hi Jacopo,\n\nOn Thu, Sep 26, 2024, 4:03 PM Jacopo Mondi <jacopo.mondi@ideasonboard.com>\nwrote:\n\n> Hi Harvey\n>\n> On Wed, Sep 25, 2024 at 03:09:38PM GMT, Cheng-Hao Yang wrote:\n> > Hi Jacopo,\n> >\n> > Thank you for the patch.\n> >\n> > On Wed, Sep 25, 2024 at 2:36 PM Umang Jain <umang.jain@ideasonboard.com>\n> wrote:\n> > >\n> > > Hi Jacopo\n> > >\n> > > Thank you for the patch\n> > >\n> > > On 24/09/24 6:15 pm, Jacopo Mondi wrote:\n> > > > The libcamera::Rectangle class should allow defining rectangles\n> > > > regardless of the reference system where an instance is used in.\n> > > >\n> > > > However the class documentation assumes the reference system origin\n> > > > point to be in the visual top-left side and that rectangles are\n> > > > constructed by specifying the top-left corner position and sizes.\n> > > >\n> > > > However this is ambiguous when using a different reference system as,\n> > > > in example, constructing a rectangle (x, y, w, h) in the following\n> > > > scenario, with the origin corner in the top-left position, would\n> require\n> > > > a negative decrement along the y-axis.\n> > > >\n> > > >           ^\n> > > >           |\n> > > >          y|      o------------------\n> > > >           |      |                 | h\n> > > >           |      |                 |\n> > > >           |      -------------------\n> > > >           |               w\n> > > >            ------------------------------->\n> > > >           (0,0)  x\n> > > >\n> > > > To remove ambiguities, drop references to the visual top-left corner\n> and\n> > > > define the rectangle's origin corner as the corner closer to the\n> > > > reference system origin point, and specify the horizontal and\n> vertical\n> > > > dimensions always increment along their respective axis, as in the\n> > > > following example.\n> > > >\n> > > >           ^\n> > > >           |\n> > > >           |      -------------------\n> > > >           |      ^                 | h\n> > > >           |      |                 |\n> > > >          y|      o---->-------------\n> > > >           |               w\n> > > >            ------------------------------->\n> > > >           (0,0)  x\n> > > >\n> > > >           (0,0)  x\n> > > >             ------------------------------>\n> > > >            |              w\n> > > >           y|     o---->-------------\n> > > >            |     |                 | h\n> > > >            |     v                 |\n> > > >            |     -------------------\n> > > >            |\n> > > >            V\n> > > >\n> > > > Also rename for consistency the Rectangle::topLeft() function to\n> > > > Rectangle::origin() and update its in-tree users.\n> > > >\n> > > > Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n> > > > ---\n> > > >   include/libcamera/geometry.h                  |  2 +-\n> > > >   src/ipa/ipu3/algorithms/af.cpp                |  2 +-\n> > > >   src/libcamera/geometry.cpp                    | 85\n> ++++++++++++++-----\n> > > >   .../pipeline/rpi/common/pipeline_base.cpp     |  4 +-\n> > > >   src/py/libcamera/py_geometry.cpp              |  2 +-\n> > > >   test/geometry.cpp                             |  8 +-\n> > > >   6 files changed, 75 insertions(+), 28 deletions(-)\n> > > >\n> > > > diff --git a/include/libcamera/geometry.h\n> b/include/libcamera/geometry.h\n> > > > index 3e6f0f5d7fab..07cb0a7866fe 100644\n> > > > --- a/include/libcamera/geometry.h\n> > > > +++ b/include/libcamera/geometry.h\n> > > > @@ -277,7 +277,7 @@ public:\n> > > >               return { width, height };\n> > > >       }\n> > > >\n> > > > -     Point topLeft() const\n> > > > +     Point origin() const\n> > > >       {\n> > > >               return { x, y };\n> > > >       }\n> > > > diff --git a/src/ipa/ipu3/algorithms/af.cpp\n> b/src/ipa/ipu3/algorithms/af.cpp\n> > > > index cf68fb59c49b..1b707e9dd9ab 100644\n> > > > --- a/src/ipa/ipu3/algorithms/af.cpp\n> > > > +++ b/src/ipa/ipu3/algorithms/af.cpp\n> > > > @@ -155,7 +155,7 @@ int Af::configure(IPAContext &context, const\n> IPAConfigInfo &configInfo)\n> > > >        * - Return the AF ROI as metadata in the Request\n> > > >        */\n> > > >       Rectangle roi = gridSize.centeredTo(bds.center());\n> > > > -     Point start = roi.topLeft();\n> > > > +     Point start = roi.origin();\n> > > >\n> > > >       /* x_start and y_start should be even */\n> > > >       grid.x_start = utils::alignDown(start.x, 2);\n> > > > diff --git a/src/libcamera/geometry.cpp b/src/libcamera/geometry.cpp\n> > > > index 000151364c7f..45ba81a99920 100644\n> > > > --- a/src/libcamera/geometry.cpp\n> > > > +++ b/src/libcamera/geometry.cpp\n> > > > @@ -593,11 +593,39 @@ std::ostream &operator<<(std::ostream &out,\n> const SizeRange &sr)\n> > > >    * \\brief Describe a rectangle's position and dimensions\n> > > >    *\n> > > >    * Rectangles are used to identify an area of an image. They are\n> specified by\n> > > > - * the coordinates of top-left corner and their horizontal and\n> vertical size.\n> > > > + * the coordinates of the corner closer to the reference system's\n> origin point\n> > > > + * and by horizontal and vertical increments from there.\n> > > >    *\n> > > > - * The measure unit of the rectangle coordinates and size, as well\n> as the\n> > > > - * reference point from which the Rectangle::x and Rectangle::y\n> displacements\n> > > > - * refers to, are defined by the context were rectangle is used.\n> > > > + * The corner closer to the reference system's origin point is the\n> rectangle's\n> > > > + * origin corner.\n> > > > + *\n> > > > + * \\verbatim\n> > > > +\n> > > > +  o = origin corner\n> > > > +\n> > > > +         ^\n> > > > +         |\n> > > > +         |      -------------------\n> > > > +         |      ^                 |\n> > > > +         |      |                 |\n> > > > +         |      o---->-------------\n> > > > +         |\n> > > > +          ------------------------------->\n> > > > +         (0,0)\n> > > > +\n> > > > +         (0,0)\n> > > > +           ------------------------------->\n> > > > +          |\n> > > > +          |      o---->-------------\n> > > > +          |      |                 |\n> > > > +          |      v                 |\n> > > > +          |      -------------------\n> > > > +          |\n> > > > +          V\n> > > > +   \\endverbatim\n> > > > + *\n> > > > + * The measure unit of the rectangle coordinates and size are\n> defined by the\n> > > > + * context were the rectangle is used.\n> > > >    */\n> > > >\n> > > >   /**\n> > > > @@ -608,35 +636,50 @@ std::ostream &operator<<(std::ostream &out,\n> const SizeRange &sr)\n> > > >   /**\n> > > >    * \\fn Rectangle::Rectangle(int x, int y, const Size &size)\n> > > >    * \\brief Construct a Rectangle with the given position and size\n> > > > - * \\param[in] x The horizontal coordinate of the top-left corner\n> > > > - * \\param[in] y The vertical coordinate of the top-left corner\n> > > > + * \\param[in] x The horizontal coordinate of the origin corner\n> > > > + * \\param[in] y The vertical coordinate of the origin corner\n> > > >    * \\param[in] size The size\n> > > > + *\n> > > > + * The rectangle's origin corner is the corner closer to the\n> reference system\n> > > > + * origin point (0, 0).\n> >\n> > I think we should stick to the previous description:\n> > `\"origin\" point defined as the point with the lower x and\n> > lower y of the rectangle`, as `x` and `y` are signed integers.\n> >\n> > If we only support coordinates that are positive or 0, which\n> > I'm not sure if it's the case, how about making the type to be\n> > `unsigned int`?\n> >\n>\n> To be honest I would rather make width and heigh signed to allow\n> constructing (x, y, -w, -h)\n>\n>\n>\n>\n>                -------------------\n>                |                 ^\n>                |            ------------->\n>                |           |     |\n>                ------<-----|-----o\n>                            |\n>                            |\n>                            V\n>\n> Not sure if it's useful or not though\n>\n\nHmm... I find it pretty weird. What if all four corners have all negative\ncoordinates?\n\n\n\n\n>\n> > BR,\n> > Harvey\n> >\n> >\n> > > >    */\n> > > >\n> > > >   /**\n> > > >    * \\fn Rectangle::Rectangle(int x, int y, unsigned int width,\n> unsigned int height)\n> > > >    * \\brief Construct a Rectangle with the given position and size\n> > > > - * \\param[in] x The horizontal coordinate of the top-left corner\n> > > > - * \\param[in] y The vertical coordinate of the top-left corner\n> > > > + * \\param[in] x The horizontal coordinate of the origin corner\n> > > > + * \\param[in] y The vertical coordinate of the origin corner\n> > > >    * \\param[in] width The width\n> > > >    * \\param[in] height The height\n> > > > + *\n> > > > + * The rectangle's origin corner is the corner closer to the\n> reference system\n> > > > + * origin point (0, 0).\n> > > >    */\n> > > >\n> > > >   /**\n> > > >    * \\fn Rectangle::Rectangle(const Size &size)\n> > > > - * \\brief Construct a Rectangle of \\a size with its top left corner\n> located\n> > > > + * \\brief Construct a Rectangle of \\a size with its origin corner\n> located\n> > > >    * at (0,0)\n> > > >    * \\param[in] size The desired Rectangle size\n> > > > + *\n> > > > + * The rectangle's origin corner is the corner closer to the\n> reference system\n> > > > + * origin point (0, 0).\n> > > >    */\n> > > >\n> > > >   /**\n> > > >    * \\var Rectangle::x\n> > > > - * \\brief The horizontal coordinate of the rectangle's top-left\n> corner\n> > > > + * \\brief The horizontal coordinate of the rectangle's origin corner\n> > > > + *\n> > > > + * The rectangle's origin corner is the corner closer to the\n> reference system\n> > > > + * origin point (0, 0).\n> > > >    */\n> > > >\n> > > >   /**\n> > > >    * \\var Rectangle::y\n> > > > - * \\brief The vertical coordinate of the rectangle's top-left corner\n> > > > + * \\brief The vertical coordinate of the rectangle's origin corner\n> > > > + *\n> > > > + * The rectangle's origin corner is the corner closer to the\n> reference system\n> > > > + * origin point (0, 0).\n> > > >    */\n> > > >\n> > > >   /**\n> > > > @@ -683,9 +726,13 @@ Point Rectangle::center() const\n> > > >    */\n> > > >\n> > > >   /**\n> > > > - * \\fn Point Rectangle::topLeft() const\n> > > > - * \\brief Retrieve the coordinates of the top left corner of this\n> Rectangle\n> > > > - * \\return The Rectangle's top left corner\n> > > > + * \\fn Point Rectangle::origin() const\n> > > > + * \\brief Retrieve the coordinates of the origin corner of this\n> Rectangle\n> > > > + *\n> > > > + * The rectangle's origin corner is the corner closer to the\n> reference system\n> > > > + * origin point (0, 0).\n> > > > + *\n> > > > + * \\return The Rectangle's origin corner\n> > >\n> > > I think you can drop \"corner\" from \"origin corner\"\n> > >\n> > > Probably throughout the patch:\n> > >      s/origin corner/origin/\n> > >\n> > > Otherwise, LGTM\n> > >\n> > > Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>\n> > > >    */\n> > > >\n> > > >   /**\n> > > > @@ -740,15 +787,15 @@ Rectangle &Rectangle::translateBy(const Point\n> &point)\n> > > >    */\n> > > >   Rectangle Rectangle::boundedTo(const Rectangle &bound) const\n> > > >   {\n> > > > -     int topLeftX = std::max(x, bound.x);\n> > > > -     int topLeftY = std::max(y, bound.y);\n> > > > +     int originX = std::max(x, bound.x);\n> > > > +     int originY = std::max(y, bound.y);\n> > > >       int bottomRightX = std::min<int>(x + width, bound.x +\n> bound.width);\n> > > >       int bottomRightY = std::min<int>(y + height, bound.y +\n> bound.height);\n> > > >\n> > > > -     unsigned int newWidth = std::max(bottomRightX - topLeftX, 0);\n> > > > -     unsigned int newHeight = std::max(bottomRightY - topLeftY, 0);\n> > > > +     unsigned int newWidth = std::max(bottomRightX - originX, 0);\n> > > > +     unsigned int newHeight = std::max(bottomRightY - originY, 0);\n> > > >\n> > > > -     return { topLeftX, topLeftY, newWidth, newHeight };\n> > > > +     return { originX, originY, newWidth, newHeight };\n> > > >   }\n> > > >\n> > > >   /**\n> > > > diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n> b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n> > > > index 3041fd1ed9fd..8d2440026689 100644\n> > > > --- a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n> > > > +++ b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n> > > > @@ -1289,7 +1289,7 @@ Rectangle CameraData::scaleIspCrop(const\n> Rectangle &ispCrop) const\n> > > >        */\n> > > >       Rectangle nativeCrop =\n> ispCrop.scaledBy(sensorInfo_.analogCrop.size(),\n> > > >\n>  sensorInfo_.outputSize);\n> > > > -     nativeCrop.translateBy(sensorInfo_.analogCrop.topLeft());\n> > > > +     nativeCrop.translateBy(sensorInfo_.analogCrop.origin());\n> > > >       return nativeCrop;\n> > > >   }\n> > > >\n> > > > @@ -1303,7 +1303,7 @@ void CameraData::applyScalerCrop(const\n> ControlList &controls)\n> > > >                       nativeCrop = { 0, 0, 1, 1 };\n> > > >\n> > > >               /* Create a version of the crop scaled to ISP (camera\n> mode) pixels. */\n> > > > -             Rectangle ispCrop =\n> nativeCrop.translatedBy(-sensorInfo_.analogCrop.topLeft());\n> > > > +             Rectangle ispCrop =\n> nativeCrop.translatedBy(-sensorInfo_.analogCrop.origin());\n> > > >               ispCrop.scaleBy(sensorInfo_.outputSize,\n> sensorInfo_.analogCrop.size());\n> > > >\n> > > >               /*\n> > > > diff --git a/src/py/libcamera/py_geometry.cpp\n> b/src/py/libcamera/py_geometry.cpp\n> > > > index c7e303609427..8dee365b25dd 100644\n> > > > --- a/src/py/libcamera/py_geometry.cpp\n> > > > +++ b/src/py/libcamera/py_geometry.cpp\n> > > > @@ -105,7 +105,7 @@ void init_py_geometry(py::module &m)\n> > > >               .def_property_readonly(\"is_null\", &Rectangle::isNull)\n> > > >               .def_property_readonly(\"center\", &Rectangle::center)\n> > > >               .def_property_readonly(\"size\", &Rectangle::size)\n> > > > -             .def_property_readonly(\"topLeft\", &Rectangle::topLeft)\n> > > > +             .def_property_readonly(\"origin\", &Rectangle::origin)\n> > > >               .def(\"scale_by\", &Rectangle::scaleBy)\n> > > >               .def(\"translate_by\", &Rectangle::translateBy)\n> > > >               .def(\"bounded_to\", &Rectangle::boundedTo)\n> > > > diff --git a/test/geometry.cpp b/test/geometry.cpp\n> > > > index 64169206ad16..a4ee6f6e167a 100644\n> > > > --- a/test/geometry.cpp\n> > > > +++ b/test/geometry.cpp\n> > > > @@ -363,16 +363,16 @@ protected:\n> > > >                       return TestFail;\n> > > >               }\n> > > >\n> > > > -             /* Rectangle::size(), Rectangle::topLeft() and\n> Rectangle::center() tests */\n> > > > +             /* Rectangle::size(), Rectangle::origin() and\n> Rectangle::center() tests */\n> > > >               if (Rectangle(-1, -2, 3, 4).size() != Size(3, 4) ||\n> > > >                   Rectangle(0, 0, 100000, 200000).size() !=\n> Size(100000, 200000)) {\n> > > >                       cout << \"Rectangle::size() test failed\" <<\n> endl;\n> > > >                       return TestFail;\n> > > >               }\n> > > >\n> > > > -             if (Rectangle(1, 2, 3, 4).topLeft() != Point(1, 2) ||\n> > > > -                 Rectangle(-1, -2, 3, 4).topLeft() != Point(-1,\n> -2)) {\n> > > > -                     cout << \"Rectangle::topLeft() test failed\" <<\n> endl;\n> > > > +             if (Rectangle(1, 2, 3, 4).origin() != Point(1, 2) ||\n> > > > +                 Rectangle(-1, -2, 3, 4).origin() != Point(-1, -2))\n> {\n> > > > +                     cout << \"Rectangle::origin() test failed\" <<\n> endl;\n> > > >                       return TestFail;\n> > > >               }\n> > > >\n> > > > --\n> > > > 2.46.1\n> > > >\n> > >\n> >\n> >\n> > --\n> > BR,\n> > Harvey Yang\n>","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 336A0C3257\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 26 Sep 2024 08:30:06 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 5ECD16350F;\n\tThu, 26 Sep 2024 10:30:05 +0200 (CEST)","from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com\n\t[IPv6:2a00:1450:4864:20::32c])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 453FF634F2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 26 Sep 2024 10:30:03 +0200 (CEST)","by mail-wm1-x32c.google.com with SMTP id\n\t5b1f17b1804b1-42cae4ead5bso138875e9.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 26 Sep 2024 01:30:03 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key;\n\tunprotected) header.d=google.com header.i=@google.com\n\theader.b=\"SWXCXieG\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=google.com; s=20230601; t=1727339403; x=1727944203;\n\tdarn=lists.libcamera.org; \n\th=cc:to:subject:message-id:date:from:in-reply-to:references\n\t:mime-version:from:to:cc:subject:date:message-id:reply-to;\n\tbh=l282qheq2m349x5Uwy+Ch5TOmY1oM8OKs8S5N2KwKiA=;\n\tb=SWXCXieGtvTSl14km9KxLPgan066Bn8S0P+Xeg7Ag0fVpFkiTLLlZvSBdXu/Ot5G6H\n\t5nQIhLqztN8yb7wuyzSkuCdIZ9ZGxbwCHkA5XtqEiTEIksWO9f5WAoZhJlegte19MyL6\n\tZfpB3rgAk2eARKrFVVViJNUUnd48DyBE3/CuYBBlj99mF/ycNPbg6CYH9m7cFtNiMfYj\n\ts357W4vhyAAL3a9S4Tdd98H7OuosxrMUO22fFWb5egu7xd3EMhOYtNvhe91r3JMTsV6D\n\tUYH7fpBJScRpqLMNFhMAEwDUIkewoX7LpJVbftvfs+T1xwM7RR2Nx4i1nHJEHtQ4RVuA\n\tkAUg==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1727339403; x=1727944203;\n\th=cc:to:subject:message-id:date:from:in-reply-to:references\n\t:mime-version:x-gm-message-state:from:to:cc:subject:date:message-id\n\t:reply-to;\n\tbh=l282qheq2m349x5Uwy+Ch5TOmY1oM8OKs8S5N2KwKiA=;\n\tb=RiL66v6nSvgFqqWaPgACOOKbT+rD2YxN5/AbgoC9hyJwRksjnlli0dXQdMDH+wsQVV\n\t05RAVqAYrIGZvaFt+Sd3WrUtWnCByKw0erhRwWNFR11dP+ympNfG7zcceXvimR/eB/FH\n\t6wL6FrZJuHih2gRJ1Ekh1ESlgJeq+1IMu3c+fReo7PznpvZXPS5KMIq6azIJd3hKeYpC\n\tLz+F8bijjryXVmMjTEUU/EkkE3ch++oUI6OekJDSsBuXD5OQoxftC1Zjw7fObtqPE2De\n\t6+3Az2OgwXvckVsDVPquo6x0ESjNy7iWE5l0SV3kUVBVutBCjpTDvPTEJnHnJpLk/E0u\n\tpVQA==","X-Forwarded-Encrypted":"i=1;\n\tAJvYcCU2JUYVbXqoY2/MH0K2Ov+2RUqcbYGTdh8rSqeBXF4aIF15eCUqIqNgNUj+KCIs5H7YOVHbkSyIt0ORI7LXvzc=@lists.libcamera.org","X-Gm-Message-State":"AOJu0Yys9P/oPDdg/khYZxCk/JMHxwWAgMS1kIdhxvUgpvXBKX+dOhqk\n\tePDZcMChF+kA/OfAuSEHP7ekNY6txc6BQPC1wCtOaED8AeE97XfbiuKAij/46GLqXxj3Oeym7GS\n\tEt2U7sun+cUpNse2oG8QX7MCXO2Fsi1Mcxvr+IC+Ip6pL7Gw662ME","X-Google-Smtp-Source":"AGHT+IHpAzvqVHPW26mYSgu0A5eMOKjE6ZTh0tG2y/wIjqmIAAJ64bqagM8HY8w1SI+F+TpUbOgiPb7RcbQHDqVBzCw=","X-Received":"by 2002:a05:600c:3486:b0:426:7018:2e2f with SMTP id\n\t5b1f17b1804b1-42f537955bamr2411505e9.5.1727339402384; Thu, 26 Sep 2024\n\t01:30:02 -0700 (PDT)","MIME-Version":"1.0","References":"<20240924124525.95189-1-jacopo.mondi@ideasonboard.com>\n\t<d975583c-7f5d-4f5b-8e99-5cdc61396667@ideasonboard.com>\n\t<CAC=wSGUwXZDvM68ZfhqPvYKhAB0bkem=zJhFJ-Fjafc9OYhDqA@mail.gmail.com>\n\t<uzptnxdipytxx4nwqusnr62asaiwrdawylf2f3vzbmkc53onhc@nkeomtxtfw5g>","In-Reply-To":"<uzptnxdipytxx4nwqusnr62asaiwrdawylf2f3vzbmkc53onhc@nkeomtxtfw5g>","From":"Cheng-Hao Yang <chenghaoyang@google.com>","Date":"Thu, 26 Sep 2024 16:29:50 +0800","Message-ID":"<CAC=wSGWEZU7_=nEFTp+g_g74L7kcs65wK3oOeS8xwBqzMHa5wQ@mail.gmail.com>","Subject":"Re: [PATCH] libcamera: geometry: Rename Rectangle's top-left corner","To":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>","Cc":"Umang Jain <umang.jain@ideasonboard.com>, \n\tlibcamera devel <libcamera-devel@lists.libcamera.org>","Content-Type":"multipart/alternative; boundary=\"0000000000007d2bed0623018bfd\"","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>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":31378,"web_url":"https://patchwork.libcamera.org/comment/31378/","msgid":"<zsszrdewqlrlovncquphk43ajxyksfoijoiorglvwem4kb2u6q@my2gscqpdzd3>","date":"2024-09-26T08:38:04","subject":"Re: [PATCH] libcamera: geometry: Rename Rectangle's top-left corner","submitter":{"id":143,"url":"https://patchwork.libcamera.org/api/people/143/","name":"Jacopo Mondi","email":"jacopo.mondi@ideasonboard.com"},"content":"Hi Harvey\n\nOn Thu, Sep 26, 2024 at 04:29:50PM GMT, Cheng-Hao Yang wrote:\n> Hi Jacopo,\n>\n> On Thu, Sep 26, 2024, 4:03 PM Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n> wrote:\n>\n> > Hi Harvey\n> >\n> > On Wed, Sep 25, 2024 at 03:09:38PM GMT, Cheng-Hao Yang wrote:\n> > > Hi Jacopo,\n> > >\n> > > Thank you for the patch.\n> > >\n> > > On Wed, Sep 25, 2024 at 2:36 PM Umang Jain <umang.jain@ideasonboard.com>\n> > wrote:\n> > > >\n> > > > Hi Jacopo\n> > > >\n> > > > Thank you for the patch\n> > > >\n> > > > On 24/09/24 6:15 pm, Jacopo Mondi wrote:\n> > > > > The libcamera::Rectangle class should allow defining rectangles\n> > > > > regardless of the reference system where an instance is used in.\n> > > > >\n> > > > > However the class documentation assumes the reference system origin\n> > > > > point to be in the visual top-left side and that rectangles are\n> > > > > constructed by specifying the top-left corner position and sizes.\n> > > > >\n> > > > > However this is ambiguous when using a different reference system as,\n> > > > > in example, constructing a rectangle (x, y, w, h) in the following\n> > > > > scenario, with the origin corner in the top-left position, would\n> > require\n> > > > > a negative decrement along the y-axis.\n> > > > >\n> > > > >           ^\n> > > > >           |\n> > > > >          y|      o------------------\n> > > > >           |      |                 | h\n> > > > >           |      |                 |\n> > > > >           |      -------------------\n> > > > >           |               w\n> > > > >            ------------------------------->\n> > > > >           (0,0)  x\n> > > > >\n> > > > > To remove ambiguities, drop references to the visual top-left corner\n> > and\n> > > > > define the rectangle's origin corner as the corner closer to the\n> > > > > reference system origin point, and specify the horizontal and\n> > vertical\n> > > > > dimensions always increment along their respective axis, as in the\n> > > > > following example.\n> > > > >\n> > > > >           ^\n> > > > >           |\n> > > > >           |      -------------------\n> > > > >           |      ^                 | h\n> > > > >           |      |                 |\n> > > > >          y|      o---->-------------\n> > > > >           |               w\n> > > > >            ------------------------------->\n> > > > >           (0,0)  x\n> > > > >\n> > > > >           (0,0)  x\n> > > > >             ------------------------------>\n> > > > >            |              w\n> > > > >           y|     o---->-------------\n> > > > >            |     |                 | h\n> > > > >            |     v                 |\n> > > > >            |     -------------------\n> > > > >            |\n> > > > >            V\n> > > > >\n> > > > > Also rename for consistency the Rectangle::topLeft() function to\n> > > > > Rectangle::origin() and update its in-tree users.\n> > > > >\n> > > > > Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n> > > > > ---\n> > > > >   include/libcamera/geometry.h                  |  2 +-\n> > > > >   src/ipa/ipu3/algorithms/af.cpp                |  2 +-\n> > > > >   src/libcamera/geometry.cpp                    | 85\n> > ++++++++++++++-----\n> > > > >   .../pipeline/rpi/common/pipeline_base.cpp     |  4 +-\n> > > > >   src/py/libcamera/py_geometry.cpp              |  2 +-\n> > > > >   test/geometry.cpp                             |  8 +-\n> > > > >   6 files changed, 75 insertions(+), 28 deletions(-)\n> > > > >\n> > > > > diff --git a/include/libcamera/geometry.h\n> > b/include/libcamera/geometry.h\n> > > > > index 3e6f0f5d7fab..07cb0a7866fe 100644\n> > > > > --- a/include/libcamera/geometry.h\n> > > > > +++ b/include/libcamera/geometry.h\n> > > > > @@ -277,7 +277,7 @@ public:\n> > > > >               return { width, height };\n> > > > >       }\n> > > > >\n> > > > > -     Point topLeft() const\n> > > > > +     Point origin() const\n> > > > >       {\n> > > > >               return { x, y };\n> > > > >       }\n> > > > > diff --git a/src/ipa/ipu3/algorithms/af.cpp\n> > b/src/ipa/ipu3/algorithms/af.cpp\n> > > > > index cf68fb59c49b..1b707e9dd9ab 100644\n> > > > > --- a/src/ipa/ipu3/algorithms/af.cpp\n> > > > > +++ b/src/ipa/ipu3/algorithms/af.cpp\n> > > > > @@ -155,7 +155,7 @@ int Af::configure(IPAContext &context, const\n> > IPAConfigInfo &configInfo)\n> > > > >        * - Return the AF ROI as metadata in the Request\n> > > > >        */\n> > > > >       Rectangle roi = gridSize.centeredTo(bds.center());\n> > > > > -     Point start = roi.topLeft();\n> > > > > +     Point start = roi.origin();\n> > > > >\n> > > > >       /* x_start and y_start should be even */\n> > > > >       grid.x_start = utils::alignDown(start.x, 2);\n> > > > > diff --git a/src/libcamera/geometry.cpp b/src/libcamera/geometry.cpp\n> > > > > index 000151364c7f..45ba81a99920 100644\n> > > > > --- a/src/libcamera/geometry.cpp\n> > > > > +++ b/src/libcamera/geometry.cpp\n> > > > > @@ -593,11 +593,39 @@ std::ostream &operator<<(std::ostream &out,\n> > const SizeRange &sr)\n> > > > >    * \\brief Describe a rectangle's position and dimensions\n> > > > >    *\n> > > > >    * Rectangles are used to identify an area of an image. They are\n> > specified by\n> > > > > - * the coordinates of top-left corner and their horizontal and\n> > vertical size.\n> > > > > + * the coordinates of the corner closer to the reference system's\n> > origin point\n> > > > > + * and by horizontal and vertical increments from there.\n> > > > >    *\n> > > > > - * The measure unit of the rectangle coordinates and size, as well\n> > as the\n> > > > > - * reference point from which the Rectangle::x and Rectangle::y\n> > displacements\n> > > > > - * refers to, are defined by the context were rectangle is used.\n> > > > > + * The corner closer to the reference system's origin point is the\n> > rectangle's\n> > > > > + * origin corner.\n> > > > > + *\n> > > > > + * \\verbatim\n> > > > > +\n> > > > > +  o = origin corner\n> > > > > +\n> > > > > +         ^\n> > > > > +         |\n> > > > > +         |      -------------------\n> > > > > +         |      ^                 |\n> > > > > +         |      |                 |\n> > > > > +         |      o---->-------------\n> > > > > +         |\n> > > > > +          ------------------------------->\n> > > > > +         (0,0)\n> > > > > +\n> > > > > +         (0,0)\n> > > > > +           ------------------------------->\n> > > > > +          |\n> > > > > +          |      o---->-------------\n> > > > > +          |      |                 |\n> > > > > +          |      v                 |\n> > > > > +          |      -------------------\n> > > > > +          |\n> > > > > +          V\n> > > > > +   \\endverbatim\n> > > > > + *\n> > > > > + * The measure unit of the rectangle coordinates and size are\n> > defined by the\n> > > > > + * context were the rectangle is used.\n> > > > >    */\n> > > > >\n> > > > >   /**\n> > > > > @@ -608,35 +636,50 @@ std::ostream &operator<<(std::ostream &out,\n> > const SizeRange &sr)\n> > > > >   /**\n> > > > >    * \\fn Rectangle::Rectangle(int x, int y, const Size &size)\n> > > > >    * \\brief Construct a Rectangle with the given position and size\n> > > > > - * \\param[in] x The horizontal coordinate of the top-left corner\n> > > > > - * \\param[in] y The vertical coordinate of the top-left corner\n> > > > > + * \\param[in] x The horizontal coordinate of the origin corner\n> > > > > + * \\param[in] y The vertical coordinate of the origin corner\n> > > > >    * \\param[in] size The size\n> > > > > + *\n> > > > > + * The rectangle's origin corner is the corner closer to the\n> > reference system\n> > > > > + * origin point (0, 0).\n> > >\n> > > I think we should stick to the previous description:\n> > > `\"origin\" point defined as the point with the lower x and\n> > > lower y of the rectangle`, as `x` and `y` are signed integers.\n> > >\n> > > If we only support coordinates that are positive or 0, which\n> > > I'm not sure if it's the case, how about making the type to be\n> > > `unsigned int`?\n> > >\n> >\n> > To be honest I would rather make width and heigh signed to allow\n> > constructing (x, y, -w, -h)\n> >\n> >\n> >\n> >\n> >                -------------------\n> >                |                 ^\n> >                |            ------------->\n> >                |           |     |\n> >                ------<-----|-----o\n> >                            |\n> >                            |\n> >                            V\n> >\n> > Not sure if it's useful or not though\n> >\n>\n> Hmm... I find it pretty weird. What if all four corners have all negative\n> coordinates?\n>\n>\n\nDon't know, maybe if the reference system where the rectangle is used\ninto has 4 planes and so an all-negative rectangle makes sense.\n\nMy point is that we should allow users of this class to express\nRectangle in any context they plan to use them. Not sure if I'm going\noverboard here or it makes sense.\n\n>\n>\n> >\n> > > BR,\n> > > Harvey\n> > >\n> > >\n> > > > >    */\n> > > > >\n> > > > >   /**\n> > > > >    * \\fn Rectangle::Rectangle(int x, int y, unsigned int width,\n> > unsigned int height)\n> > > > >    * \\brief Construct a Rectangle with the given position and size\n> > > > > - * \\param[in] x The horizontal coordinate of the top-left corner\n> > > > > - * \\param[in] y The vertical coordinate of the top-left corner\n> > > > > + * \\param[in] x The horizontal coordinate of the origin corner\n> > > > > + * \\param[in] y The vertical coordinate of the origin corner\n> > > > >    * \\param[in] width The width\n> > > > >    * \\param[in] height The height\n> > > > > + *\n> > > > > + * The rectangle's origin corner is the corner closer to the\n> > reference system\n> > > > > + * origin point (0, 0).\n> > > > >    */\n> > > > >\n> > > > >   /**\n> > > > >    * \\fn Rectangle::Rectangle(const Size &size)\n> > > > > - * \\brief Construct a Rectangle of \\a size with its top left corner\n> > located\n> > > > > + * \\brief Construct a Rectangle of \\a size with its origin corner\n> > located\n> > > > >    * at (0,0)\n> > > > >    * \\param[in] size The desired Rectangle size\n> > > > > + *\n> > > > > + * The rectangle's origin corner is the corner closer to the\n> > reference system\n> > > > > + * origin point (0, 0).\n> > > > >    */\n> > > > >\n> > > > >   /**\n> > > > >    * \\var Rectangle::x\n> > > > > - * \\brief The horizontal coordinate of the rectangle's top-left\n> > corner\n> > > > > + * \\brief The horizontal coordinate of the rectangle's origin corner\n> > > > > + *\n> > > > > + * The rectangle's origin corner is the corner closer to the\n> > reference system\n> > > > > + * origin point (0, 0).\n> > > > >    */\n> > > > >\n> > > > >   /**\n> > > > >    * \\var Rectangle::y\n> > > > > - * \\brief The vertical coordinate of the rectangle's top-left corner\n> > > > > + * \\brief The vertical coordinate of the rectangle's origin corner\n> > > > > + *\n> > > > > + * The rectangle's origin corner is the corner closer to the\n> > reference system\n> > > > > + * origin point (0, 0).\n> > > > >    */\n> > > > >\n> > > > >   /**\n> > > > > @@ -683,9 +726,13 @@ Point Rectangle::center() const\n> > > > >    */\n> > > > >\n> > > > >   /**\n> > > > > - * \\fn Point Rectangle::topLeft() const\n> > > > > - * \\brief Retrieve the coordinates of the top left corner of this\n> > Rectangle\n> > > > > - * \\return The Rectangle's top left corner\n> > > > > + * \\fn Point Rectangle::origin() const\n> > > > > + * \\brief Retrieve the coordinates of the origin corner of this\n> > Rectangle\n> > > > > + *\n> > > > > + * The rectangle's origin corner is the corner closer to the\n> > reference system\n> > > > > + * origin point (0, 0).\n> > > > > + *\n> > > > > + * \\return The Rectangle's origin corner\n> > > >\n> > > > I think you can drop \"corner\" from \"origin corner\"\n> > > >\n> > > > Probably throughout the patch:\n> > > >      s/origin corner/origin/\n> > > >\n> > > > Otherwise, LGTM\n> > > >\n> > > > Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>\n> > > > >    */\n> > > > >\n> > > > >   /**\n> > > > > @@ -740,15 +787,15 @@ Rectangle &Rectangle::translateBy(const Point\n> > &point)\n> > > > >    */\n> > > > >   Rectangle Rectangle::boundedTo(const Rectangle &bound) const\n> > > > >   {\n> > > > > -     int topLeftX = std::max(x, bound.x);\n> > > > > -     int topLeftY = std::max(y, bound.y);\n> > > > > +     int originX = std::max(x, bound.x);\n> > > > > +     int originY = std::max(y, bound.y);\n> > > > >       int bottomRightX = std::min<int>(x + width, bound.x +\n> > bound.width);\n> > > > >       int bottomRightY = std::min<int>(y + height, bound.y +\n> > bound.height);\n> > > > >\n> > > > > -     unsigned int newWidth = std::max(bottomRightX - topLeftX, 0);\n> > > > > -     unsigned int newHeight = std::max(bottomRightY - topLeftY, 0);\n> > > > > +     unsigned int newWidth = std::max(bottomRightX - originX, 0);\n> > > > > +     unsigned int newHeight = std::max(bottomRightY - originY, 0);\n> > > > >\n> > > > > -     return { topLeftX, topLeftY, newWidth, newHeight };\n> > > > > +     return { originX, originY, newWidth, newHeight };\n> > > > >   }\n> > > > >\n> > > > >   /**\n> > > > > diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n> > b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n> > > > > index 3041fd1ed9fd..8d2440026689 100644\n> > > > > --- a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n> > > > > +++ b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n> > > > > @@ -1289,7 +1289,7 @@ Rectangle CameraData::scaleIspCrop(const\n> > Rectangle &ispCrop) const\n> > > > >        */\n> > > > >       Rectangle nativeCrop =\n> > ispCrop.scaledBy(sensorInfo_.analogCrop.size(),\n> > > > >\n> >  sensorInfo_.outputSize);\n> > > > > -     nativeCrop.translateBy(sensorInfo_.analogCrop.topLeft());\n> > > > > +     nativeCrop.translateBy(sensorInfo_.analogCrop.origin());\n> > > > >       return nativeCrop;\n> > > > >   }\n> > > > >\n> > > > > @@ -1303,7 +1303,7 @@ void CameraData::applyScalerCrop(const\n> > ControlList &controls)\n> > > > >                       nativeCrop = { 0, 0, 1, 1 };\n> > > > >\n> > > > >               /* Create a version of the crop scaled to ISP (camera\n> > mode) pixels. */\n> > > > > -             Rectangle ispCrop =\n> > nativeCrop.translatedBy(-sensorInfo_.analogCrop.topLeft());\n> > > > > +             Rectangle ispCrop =\n> > nativeCrop.translatedBy(-sensorInfo_.analogCrop.origin());\n> > > > >               ispCrop.scaleBy(sensorInfo_.outputSize,\n> > sensorInfo_.analogCrop.size());\n> > > > >\n> > > > >               /*\n> > > > > diff --git a/src/py/libcamera/py_geometry.cpp\n> > b/src/py/libcamera/py_geometry.cpp\n> > > > > index c7e303609427..8dee365b25dd 100644\n> > > > > --- a/src/py/libcamera/py_geometry.cpp\n> > > > > +++ b/src/py/libcamera/py_geometry.cpp\n> > > > > @@ -105,7 +105,7 @@ void init_py_geometry(py::module &m)\n> > > > >               .def_property_readonly(\"is_null\", &Rectangle::isNull)\n> > > > >               .def_property_readonly(\"center\", &Rectangle::center)\n> > > > >               .def_property_readonly(\"size\", &Rectangle::size)\n> > > > > -             .def_property_readonly(\"topLeft\", &Rectangle::topLeft)\n> > > > > +             .def_property_readonly(\"origin\", &Rectangle::origin)\n> > > > >               .def(\"scale_by\", &Rectangle::scaleBy)\n> > > > >               .def(\"translate_by\", &Rectangle::translateBy)\n> > > > >               .def(\"bounded_to\", &Rectangle::boundedTo)\n> > > > > diff --git a/test/geometry.cpp b/test/geometry.cpp\n> > > > > index 64169206ad16..a4ee6f6e167a 100644\n> > > > > --- a/test/geometry.cpp\n> > > > > +++ b/test/geometry.cpp\n> > > > > @@ -363,16 +363,16 @@ protected:\n> > > > >                       return TestFail;\n> > > > >               }\n> > > > >\n> > > > > -             /* Rectangle::size(), Rectangle::topLeft() and\n> > Rectangle::center() tests */\n> > > > > +             /* Rectangle::size(), Rectangle::origin() and\n> > Rectangle::center() tests */\n> > > > >               if (Rectangle(-1, -2, 3, 4).size() != Size(3, 4) ||\n> > > > >                   Rectangle(0, 0, 100000, 200000).size() !=\n> > Size(100000, 200000)) {\n> > > > >                       cout << \"Rectangle::size() test failed\" <<\n> > endl;\n> > > > >                       return TestFail;\n> > > > >               }\n> > > > >\n> > > > > -             if (Rectangle(1, 2, 3, 4).topLeft() != Point(1, 2) ||\n> > > > > -                 Rectangle(-1, -2, 3, 4).topLeft() != Point(-1,\n> > -2)) {\n> > > > > -                     cout << \"Rectangle::topLeft() test failed\" <<\n> > endl;\n> > > > > +             if (Rectangle(1, 2, 3, 4).origin() != Point(1, 2) ||\n> > > > > +                 Rectangle(-1, -2, 3, 4).origin() != Point(-1, -2))\n> > {\n> > > > > +                     cout << \"Rectangle::origin() test failed\" <<\n> > endl;\n> > > > >                       return TestFail;\n> > > > >               }\n> > > > >\n> > > > > --\n> > > > > 2.46.1\n> > > > >\n> > > >\n> > >\n> > >\n> > > --\n> > > BR,\n> > > Harvey Yang\n> >","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 A9ED5C0F1B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 26 Sep 2024 08:38:09 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 9FAB66350E;\n\tThu, 26 Sep 2024 10:38:08 +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 B855E634F2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 26 Sep 2024 10:38:07 +0200 (CEST)","from ideasonboard.com (mob-5-90-51-229.net.vodafone.it\n\t[5.90.51.229])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 7B4F2169;\n\tThu, 26 Sep 2024 10:36:39 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"Bj6jlqXW\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1727339799;\n\tbh=eE0onyB2fs24m/4f8YV6nu6Reyx0kvuRIwoFqOVJ2Gg=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=Bj6jlqXWTYJ8/22++jX6I40J565d+E3HV9T3UE7pWOQXCGYf9V9EQP1In/NSedvQF\n\tUma0pxlxQiE/UIhS+cGVDiaWO6vawFo/o8GjoiwAVYey4gkr/gkEdKO+1TRrStISGX\n\tnsnX9YtkHu9Wa6tdQ/6pCGcn67XCSjIlMc/ArT5E=","Date":"Thu, 26 Sep 2024 10:38:04 +0200","From":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>","To":"Cheng-Hao Yang <chenghaoyang@google.com>","Cc":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>, \n\tUmang Jain <umang.jain@ideasonboard.com>,\n\tlibcamera devel <libcamera-devel@lists.libcamera.org>","Subject":"Re: [PATCH] libcamera: geometry: Rename Rectangle's top-left corner","Message-ID":"<zsszrdewqlrlovncquphk43ajxyksfoijoiorglvwem4kb2u6q@my2gscqpdzd3>","References":"<20240924124525.95189-1-jacopo.mondi@ideasonboard.com>\n\t<d975583c-7f5d-4f5b-8e99-5cdc61396667@ideasonboard.com>\n\t<CAC=wSGUwXZDvM68ZfhqPvYKhAB0bkem=zJhFJ-Fjafc9OYhDqA@mail.gmail.com>\n\t<uzptnxdipytxx4nwqusnr62asaiwrdawylf2f3vzbmkc53onhc@nkeomtxtfw5g>\n\t<CAC=wSGWEZU7_=nEFTp+g_g74L7kcs65wK3oOeS8xwBqzMHa5wQ@mail.gmail.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<CAC=wSGWEZU7_=nEFTp+g_g74L7kcs65wK3oOeS8xwBqzMHa5wQ@mail.gmail.com>","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>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":31379,"web_url":"https://patchwork.libcamera.org/comment/31379/","msgid":"<1ca9fa68-42a5-4512-a135-55908f332afc@ideasonboard.com>","date":"2024-09-26T08:45:01","subject":"Re: [PATCH] libcamera: geometry: Rename Rectangle's top-left corner","submitter":{"id":86,"url":"https://patchwork.libcamera.org/api/people/86/","name":"Umang Jain","email":"umang.jain@ideasonboard.com"},"content":"Hi Jacopo\n\nOn 26/09/24 1:25 pm, Jacopo Mondi wrote:\n> Hi Umang\n>\n> On Wed, Sep 25, 2024 at 12:06:05PM GMT, Umang Jain wrote:\n>> Hi Jacopo\n>>\n>> Thank you for the patch\n>>\n>> On 24/09/24 6:15 pm, Jacopo Mondi wrote:\n>>> The libcamera::Rectangle class should allow defining rectangles\n>>> regardless of the reference system where an instance is used in.\n>>>\n>>> However the class documentation assumes the reference system origin\n>>> point to be in the visual top-left side and that rectangles are\n>>> constructed by specifying the top-left corner position and sizes.\n>>>\n>>> However this is ambiguous when using a different reference system as,\n>>> in example, constructing a rectangle (x, y, w, h) in the following\n>>> scenario, with the origin corner in the top-left position, would require\n>>> a negative decrement along the y-axis.\n>>>\n>>>            ^\n>>>            |\n>>>           y|      o------------------\n>>>            |      |                 | h\n>>>            |      |                 |\n>>>            |      -------------------\n>>>            |               w\n>>>             ------------------------------->\n>>>            (0,0)  x\n>>>\n>>> To remove ambiguities, drop references to the visual top-left corner and\n>>> define the rectangle's origin corner as the corner closer to the\n>>> reference system origin point, and specify the horizontal and vertical\n>>> dimensions always increment along their respective axis, as in the\n>>> following example.\n>>>\n>>>            ^\n>>>            |\n>>>            |      -------------------\n>>>            |      ^                 | h\n>>>            |      |                 |\n>>>           y|      o---->-------------\n>>>            |               w\n>>>             ------------------------------->\n>>>            (0,0)  x\n>>>\n>>>            (0,0)  x\n>>>              ------------------------------>\n>>>             |              w\n>>>            y|     o---->-------------\n>>>             |     |                 | h\n>>>             |     v                 |\n>>>             |     -------------------\n>>>             |\n>>>             V\n>>>\n>>> Also rename for consistency the Rectangle::topLeft() function to\n>>> Rectangle::origin() and update its in-tree users.\n>>>\n>>> Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n>>> ---\n>>>    include/libcamera/geometry.h                  |  2 +-\n>>>    src/ipa/ipu3/algorithms/af.cpp                |  2 +-\n>>>    src/libcamera/geometry.cpp                    | 85 ++++++++++++++-----\n>>>    .../pipeline/rpi/common/pipeline_base.cpp     |  4 +-\n>>>    src/py/libcamera/py_geometry.cpp              |  2 +-\n>>>    test/geometry.cpp                             |  8 +-\n>>>    6 files changed, 75 insertions(+), 28 deletions(-)\n>>>\n>>> diff --git a/include/libcamera/geometry.h b/include/libcamera/geometry.h\n>>> index 3e6f0f5d7fab..07cb0a7866fe 100644\n>>> --- a/include/libcamera/geometry.h\n>>> +++ b/include/libcamera/geometry.h\n>>> @@ -277,7 +277,7 @@ public:\n>>>    \t\treturn { width, height };\n>>>    \t}\n>>>\n>>> -\tPoint topLeft() const\n>>> +\tPoint origin() const\n>>>    \t{\n>>>    \t\treturn { x, y };\n>>>    \t}\n>>> diff --git a/src/ipa/ipu3/algorithms/af.cpp b/src/ipa/ipu3/algorithms/af.cpp\n>>> index cf68fb59c49b..1b707e9dd9ab 100644\n>>> --- a/src/ipa/ipu3/algorithms/af.cpp\n>>> +++ b/src/ipa/ipu3/algorithms/af.cpp\n>>> @@ -155,7 +155,7 @@ int Af::configure(IPAContext &context, const IPAConfigInfo &configInfo)\n>>>    \t * - Return the AF ROI as metadata in the Request\n>>>    \t */\n>>>    \tRectangle roi = gridSize.centeredTo(bds.center());\n>>> -\tPoint start = roi.topLeft();\n>>> +\tPoint start = roi.origin();\n>>>\n>>>    \t/* x_start and y_start should be even */\n>>>    \tgrid.x_start = utils::alignDown(start.x, 2);\n>>> diff --git a/src/libcamera/geometry.cpp b/src/libcamera/geometry.cpp\n>>> index 000151364c7f..45ba81a99920 100644\n>>> --- a/src/libcamera/geometry.cpp\n>>> +++ b/src/libcamera/geometry.cpp\n>>> @@ -593,11 +593,39 @@ std::ostream &operator<<(std::ostream &out, const SizeRange &sr)\n>>>     * \\brief Describe a rectangle's position and dimensions\n>>>     *\n>>>     * Rectangles are used to identify an area of an image. They are specified by\n>>> - * the coordinates of top-left corner and their horizontal and vertical size.\n>>> + * the coordinates of the corner closer to the reference system's origin point\n>>> + * and by horizontal and vertical increments from there.\n>>>     *\n>>> - * The measure unit of the rectangle coordinates and size, as well as the\n>>> - * reference point from which the Rectangle::x and Rectangle::y displacements\n>>> - * refers to, are defined by the context were rectangle is used.\n>>> + * The corner closer to the reference system's origin point is the rectangle's\n>>> + * origin corner.\n>>> + *\n>>> + * \\verbatim\n>>> +\n>>> +  o = origin corner\n>>> +\n>>> +         ^\n>>> +         |\n>>> +         |      -------------------\n>>> +         |      ^                 |\n>>> +         |      |                 |\n>>> +         |      o---->-------------\n>>> +         |\n>>> +          ------------------------------->\n>>> +         (0,0)\n>>> +\n>>> +         (0,0)\n>>> +           ------------------------------->\n>>> +          |\n>>> +          |      o---->-------------\n>>> +          |      |                 |\n>>> +          |      v                 |\n>>> +          |      -------------------\n>>> +          |\n>>> +          V\n>>> +   \\endverbatim\n>>> + *\n>>> + * The measure unit of the rectangle coordinates and size are defined by the\n>>> + * context were the rectangle is used.\n>>>     */\n>>>\n>>>    /**\n>>> @@ -608,35 +636,50 @@ std::ostream &operator<<(std::ostream &out, const SizeRange &sr)\n>>>    /**\n>>>     * \\fn Rectangle::Rectangle(int x, int y, const Size &size)\n>>>     * \\brief Construct a Rectangle with the given position and size\n>>> - * \\param[in] x The horizontal coordinate of the top-left corner\n>>> - * \\param[in] y The vertical coordinate of the top-left corner\n>>> + * \\param[in] x The horizontal coordinate of the origin corner\n>>> + * \\param[in] y The vertical coordinate of the origin corner\n>>>     * \\param[in] size The size\n>>> + *\n>>> + * The rectangle's origin corner is the corner closer to the reference system\n>>> + * origin point (0, 0).\n>>>     */\n>>>\n>>>    /**\n>>>     * \\fn Rectangle::Rectangle(int x, int y, unsigned int width, unsigned int height)\n>>>     * \\brief Construct a Rectangle with the given position and size\n>>> - * \\param[in] x The horizontal coordinate of the top-left corner\n>>> - * \\param[in] y The vertical coordinate of the top-left corner\n>>> + * \\param[in] x The horizontal coordinate of the origin corner\n>>> + * \\param[in] y The vertical coordinate of the origin corner\n>>>     * \\param[in] width The width\n>>>     * \\param[in] height The height\n>>> + *\n>>> + * The rectangle's origin corner is the corner closer to the reference system\n>>> + * origin point (0, 0).\n>>>     */\n>>>\n>>>    /**\n>>>     * \\fn Rectangle::Rectangle(const Size &size)\n>>> - * \\brief Construct a Rectangle of \\a size with its top left corner located\n>>> + * \\brief Construct a Rectangle of \\a size with its origin corner located\n>>>     * at (0,0)\n>>>     * \\param[in] size The desired Rectangle size\n>>> + *\n>>> + * The rectangle's origin corner is the corner closer to the reference system\n>>> + * origin point (0, 0).\n>>>     */\n>>>\n>>>    /**\n>>>     * \\var Rectangle::x\n>>> - * \\brief The horizontal coordinate of the rectangle's top-left corner\n>>> + * \\brief The horizontal coordinate of the rectangle's origin corner\n>>> + *\n>>> + * The rectangle's origin corner is the corner closer to the reference system\n>>> + * origin point (0, 0).\n>>>     */\n>>>\n>>>    /**\n>>>     * \\var Rectangle::y\n>>> - * \\brief The vertical coordinate of the rectangle's top-left corner\n>>> + * \\brief The vertical coordinate of the rectangle's origin corner\n>>> + *\n>>> + * The rectangle's origin corner is the corner closer to the reference system\n>>> + * origin point (0, 0).\n>>>     */\n>>>\n>>>    /**\n>>> @@ -683,9 +726,13 @@ Point Rectangle::center() const\n>>>     */\n>>>\n>>>    /**\n>>> - * \\fn Point Rectangle::topLeft() const\n>>> - * \\brief Retrieve the coordinates of the top left corner of this Rectangle\n>>> - * \\return The Rectangle's top left corner\n>>> + * \\fn Point Rectangle::origin() const\n>>> + * \\brief Retrieve the coordinates of the origin corner of this Rectangle\n>>> + *\n>>> + * The rectangle's origin corner is the corner closer to the reference system\n>>> + * origin point (0, 0).\n>>> + *\n>>> + * \\return The Rectangle's origin corner\n>> I think you can drop \"corner\" from \"origin corner\"\n>>\n>> Probably throughout the patch:\n>>      s/origin corner/origin/\n>>\n> I considered that, but as a \"rectangle origin\" is not a well-defined\n> term in geometry I prefer to specify it's a corner. Is this ok ?\n\nMaybe \"rectangle origin vertex\"  ?\n\nJust a suggestion. Keep what you think is best!\n\n>\n>> Otherwise, LGTM\n>>\n>> Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>\n> Thanks\n>    j\n>\n>>>     */\n>>>\n>>>    /**\n>>> @@ -740,15 +787,15 @@ Rectangle &Rectangle::translateBy(const Point &point)\n>>>     */\n>>>    Rectangle Rectangle::boundedTo(const Rectangle &bound) const\n>>>    {\n>>> -\tint topLeftX = std::max(x, bound.x);\n>>> -\tint topLeftY = std::max(y, bound.y);\n>>> +\tint originX = std::max(x, bound.x);\n>>> +\tint originY = std::max(y, bound.y);\n>>>    \tint bottomRightX = std::min<int>(x + width, bound.x + bound.width);\n>>>    \tint bottomRightY = std::min<int>(y + height, bound.y + bound.height);\n>>>\n>>> -\tunsigned int newWidth = std::max(bottomRightX - topLeftX, 0);\n>>> -\tunsigned int newHeight = std::max(bottomRightY - topLeftY, 0);\n>>> +\tunsigned int newWidth = std::max(bottomRightX - originX, 0);\n>>> +\tunsigned int newHeight = std::max(bottomRightY - originY, 0);\n>>>\n>>> -\treturn { topLeftX, topLeftY, newWidth, newHeight };\n>>> +\treturn { originX, originY, newWidth, newHeight };\n>>>    }\n>>>\n>>>    /**\n>>> diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n>>> index 3041fd1ed9fd..8d2440026689 100644\n>>> --- a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n>>> +++ b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n>>> @@ -1289,7 +1289,7 @@ Rectangle CameraData::scaleIspCrop(const Rectangle &ispCrop) const\n>>>    \t */\n>>>    \tRectangle nativeCrop = ispCrop.scaledBy(sensorInfo_.analogCrop.size(),\n>>>    \t\t\t\t\t\tsensorInfo_.outputSize);\n>>> -\tnativeCrop.translateBy(sensorInfo_.analogCrop.topLeft());\n>>> +\tnativeCrop.translateBy(sensorInfo_.analogCrop.origin());\n>>>    \treturn nativeCrop;\n>>>    }\n>>>\n>>> @@ -1303,7 +1303,7 @@ void CameraData::applyScalerCrop(const ControlList &controls)\n>>>    \t\t\tnativeCrop = { 0, 0, 1, 1 };\n>>>\n>>>    \t\t/* Create a version of the crop scaled to ISP (camera mode) pixels. */\n>>> -\t\tRectangle ispCrop = nativeCrop.translatedBy(-sensorInfo_.analogCrop.topLeft());\n>>> +\t\tRectangle ispCrop = nativeCrop.translatedBy(-sensorInfo_.analogCrop.origin());\n>>>    \t\tispCrop.scaleBy(sensorInfo_.outputSize, sensorInfo_.analogCrop.size());\n>>>\n>>>    \t\t/*\n>>> diff --git a/src/py/libcamera/py_geometry.cpp b/src/py/libcamera/py_geometry.cpp\n>>> index c7e303609427..8dee365b25dd 100644\n>>> --- a/src/py/libcamera/py_geometry.cpp\n>>> +++ b/src/py/libcamera/py_geometry.cpp\n>>> @@ -105,7 +105,7 @@ void init_py_geometry(py::module &m)\n>>>    \t\t.def_property_readonly(\"is_null\", &Rectangle::isNull)\n>>>    \t\t.def_property_readonly(\"center\", &Rectangle::center)\n>>>    \t\t.def_property_readonly(\"size\", &Rectangle::size)\n>>> -\t\t.def_property_readonly(\"topLeft\", &Rectangle::topLeft)\n>>> +\t\t.def_property_readonly(\"origin\", &Rectangle::origin)\n>>>    \t\t.def(\"scale_by\", &Rectangle::scaleBy)\n>>>    \t\t.def(\"translate_by\", &Rectangle::translateBy)\n>>>    \t\t.def(\"bounded_to\", &Rectangle::boundedTo)\n>>> diff --git a/test/geometry.cpp b/test/geometry.cpp\n>>> index 64169206ad16..a4ee6f6e167a 100644\n>>> --- a/test/geometry.cpp\n>>> +++ b/test/geometry.cpp\n>>> @@ -363,16 +363,16 @@ protected:\n>>>    \t\t\treturn TestFail;\n>>>    \t\t}\n>>>\n>>> -\t\t/* Rectangle::size(), Rectangle::topLeft() and Rectangle::center() tests */\n>>> +\t\t/* Rectangle::size(), Rectangle::origin() and Rectangle::center() tests */\n>>>    \t\tif (Rectangle(-1, -2, 3, 4).size() != Size(3, 4) ||\n>>>    \t\t    Rectangle(0, 0, 100000, 200000).size() != Size(100000, 200000)) {\n>>>    \t\t\tcout << \"Rectangle::size() test failed\" << endl;\n>>>    \t\t\treturn TestFail;\n>>>    \t\t}\n>>>\n>>> -\t\tif (Rectangle(1, 2, 3, 4).topLeft() != Point(1, 2) ||\n>>> -\t\t    Rectangle(-1, -2, 3, 4).topLeft() != Point(-1, -2)) {\n>>> -\t\t\tcout << \"Rectangle::topLeft() test failed\" << endl;\n>>> +\t\tif (Rectangle(1, 2, 3, 4).origin() != Point(1, 2) ||\n>>> +\t\t    Rectangle(-1, -2, 3, 4).origin() != Point(-1, -2)) {\n>>> +\t\t\tcout << \"Rectangle::origin() test failed\" << endl;\n>>>    \t\t\treturn TestFail;\n>>>    \t\t}\n>>>\n>>> --\n>>> 2.46.1\n>>>","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 0E9BEC3257\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 26 Sep 2024 08:45:09 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id F21C26350E;\n\tThu, 26 Sep 2024 10:45:07 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 2CFCA6350B\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 26 Sep 2024 10:45:06 +0200 (CEST)","from [IPV6:2405:201:2015:f873:c173:4b:4a04:3a21] (unknown\n\t[IPv6:2405:201:2015:f873:c173:4b:4a04:3a21])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 56CEC169;\n\tThu, 26 Sep 2024 10:43:37 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"XZnT0OrH\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1727340217;\n\tbh=y7Se+gUBhtKZCpePgFbjACLDsszMZ70WK2XVZMlSkTY=;\n\th=Date:Subject:To:Cc:References:From:In-Reply-To:From;\n\tb=XZnT0OrH1tqc62gh+qfpmYBF0FB2ph/v3I0KTFy6BXXZgEgs3yFqAe+H0mIlk9b7B\n\tSsJ0rx252jwldPlF0Py8dJlpYVwekWwmVc/+XHkm0Oddgy+/28h+wFMWTIoOP22hpK\n\t8npPH9LxOQuTwP64/wj3RCOXkNfV29G5V/o/w598=","Message-ID":"<1ca9fa68-42a5-4512-a135-55908f332afc@ideasonboard.com>","Date":"Thu, 26 Sep 2024 14:15:01 +0530","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Subject":"Re: [PATCH] libcamera: geometry: Rename Rectangle's top-left corner","To":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org, chenghaoyang@google.com","References":"<20240924124525.95189-1-jacopo.mondi@ideasonboard.com>\n\t<d975583c-7f5d-4f5b-8e99-5cdc61396667@ideasonboard.com>\n\t<hgq4tkusdwmyoagxsnbilhmz54mc7mlzckw3ylmoii5qgtb4oi@pgilpcfrxc6p>","Content-Language":"en-US","From":"Umang Jain <umang.jain@ideasonboard.com>","In-Reply-To":"<hgq4tkusdwmyoagxsnbilhmz54mc7mlzckw3ylmoii5qgtb4oi@pgilpcfrxc6p>","Content-Type":"text/plain; charset=UTF-8; format=flowed","Content-Transfer-Encoding":"8bit","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>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":31385,"web_url":"https://patchwork.libcamera.org/comment/31385/","msgid":"<CAC=wSGXj==p2GZMidtwb9pUhmnuRrdqbGhQUF14HSNfTzgz_Cw@mail.gmail.com>","date":"2024-09-26T09:28:13","subject":"Re: [PATCH] libcamera: geometry: Rename Rectangle's top-left corner","submitter":{"id":148,"url":"https://patchwork.libcamera.org/api/people/148/","name":"Cheng-Hao Yang","email":"chenghaoyang@google.com"},"content":"Hi Jacopo,\n\n\n\nOn Thu, Sep 26, 2024, 4:38 PM Jacopo Mondi <jacopo.mondi@ideasonboard.com>\nwrote:\n\n> Hi Harvey\n>\n> On Thu, Sep 26, 2024 at 04:29:50PM GMT, Cheng-Hao Yang wrote:\n> > Hi Jacopo,\n> >\n> > On Thu, Sep 26, 2024, 4:03 PM Jacopo Mondi <\n> jacopo.mondi@ideasonboard.com>\n> > wrote:\n> >\n> > > Hi Harvey\n> > >\n> > > On Wed, Sep 25, 2024 at 03:09:38PM GMT, Cheng-Hao Yang wrote:\n> > > > Hi Jacopo,\n> > > >\n> > > > Thank you for the patch.\n> > > >\n> > > > On Wed, Sep 25, 2024 at 2:36 PM Umang Jain <\n> umang.jain@ideasonboard.com>\n> > > wrote:\n> > > > >\n> > > > > Hi Jacopo\n> > > > >\n> > > > > Thank you for the patch\n> > > > >\n> > > > > On 24/09/24 6:15 pm, Jacopo Mondi wrote:\n> > > > > > The libcamera::Rectangle class should allow defining rectangles\n> > > > > > regardless of the reference system where an instance is used in.\n> > > > > >\n> > > > > > However the class documentation assumes the reference system\n> origin\n> > > > > > point to be in the visual top-left side and that rectangles are\n> > > > > > constructed by specifying the top-left corner position and sizes.\n> > > > > >\n> > > > > > However this is ambiguous when using a different reference\n> system as,\n> > > > > > in example, constructing a rectangle (x, y, w, h) in the\n> following\n> > > > > > scenario, with the origin corner in the top-left position, would\n> > > require\n> > > > > > a negative decrement along the y-axis.\n> > > > > >\n> > > > > >           ^\n> > > > > >           |\n> > > > > >          y|      o------------------\n> > > > > >           |      |                 | h\n> > > > > >           |      |                 |\n> > > > > >           |      -------------------\n> > > > > >           |               w\n> > > > > >            ------------------------------->\n> > > > > >           (0,0)  x\n> > > > > >\n> > > > > > To remove ambiguities, drop references to the visual top-left\n> corner\n> > > and\n> > > > > > define the rectangle's origin corner as the corner closer to the\n> > > > > > reference system origin point, and specify the horizontal and\n> > > vertical\n> > > > > > dimensions always increment along their respective axis, as in\n> the\n> > > > > > following example.\n> > > > > >\n> > > > > >           ^\n> > > > > >           |\n> > > > > >           |      -------------------\n> > > > > >           |      ^                 | h\n> > > > > >           |      |                 |\n> > > > > >          y|      o---->-------------\n> > > > > >           |               w\n> > > > > >            ------------------------------->\n> > > > > >           (0,0)  x\n> > > > > >\n> > > > > >           (0,0)  x\n> > > > > >             ------------------------------>\n> > > > > >            |              w\n> > > > > >           y|     o---->-------------\n> > > > > >            |     |                 | h\n> > > > > >            |     v                 |\n> > > > > >            |     -------------------\n> > > > > >            |\n> > > > > >            V\n> > > > > >\n> > > > > > Also rename for consistency the Rectangle::topLeft() function to\n> > > > > > Rectangle::origin() and update its in-tree users.\n> > > > > >\n> > > > > > Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n> > > > > > ---\n> > > > > >   include/libcamera/geometry.h                  |  2 +-\n> > > > > >   src/ipa/ipu3/algorithms/af.cpp                |  2 +-\n> > > > > >   src/libcamera/geometry.cpp                    | 85\n> > > ++++++++++++++-----\n> > > > > >   .../pipeline/rpi/common/pipeline_base.cpp     |  4 +-\n> > > > > >   src/py/libcamera/py_geometry.cpp              |  2 +-\n> > > > > >   test/geometry.cpp                             |  8 +-\n> > > > > >   6 files changed, 75 insertions(+), 28 deletions(-)\n> > > > > >\n> > > > > > diff --git a/include/libcamera/geometry.h\n> > > b/include/libcamera/geometry.h\n> > > > > > index 3e6f0f5d7fab..07cb0a7866fe 100644\n> > > > > > --- a/include/libcamera/geometry.h\n> > > > > > +++ b/include/libcamera/geometry.h\n> > > > > > @@ -277,7 +277,7 @@ public:\n> > > > > >               return { width, height };\n> > > > > >       }\n> > > > > >\n> > > > > > -     Point topLeft() const\n> > > > > > +     Point origin() const\n> > > > > >       {\n> > > > > >               return { x, y };\n> > > > > >       }\n> > > > > > diff --git a/src/ipa/ipu3/algorithms/af.cpp\n> > > b/src/ipa/ipu3/algorithms/af.cpp\n> > > > > > index cf68fb59c49b..1b707e9dd9ab 100644\n> > > > > > --- a/src/ipa/ipu3/algorithms/af.cpp\n> > > > > > +++ b/src/ipa/ipu3/algorithms/af.cpp\n> > > > > > @@ -155,7 +155,7 @@ int Af::configure(IPAContext &context, const\n> > > IPAConfigInfo &configInfo)\n> > > > > >        * - Return the AF ROI as metadata in the Request\n> > > > > >        */\n> > > > > >       Rectangle roi = gridSize.centeredTo(bds.center());\n> > > > > > -     Point start = roi.topLeft();\n> > > > > > +     Point start = roi.origin();\n> > > > > >\n> > > > > >       /* x_start and y_start should be even */\n> > > > > >       grid.x_start = utils::alignDown(start.x, 2);\n> > > > > > diff --git a/src/libcamera/geometry.cpp\n> b/src/libcamera/geometry.cpp\n> > > > > > index 000151364c7f..45ba81a99920 100644\n> > > > > > --- a/src/libcamera/geometry.cpp\n> > > > > > +++ b/src/libcamera/geometry.cpp\n> > > > > > @@ -593,11 +593,39 @@ std::ostream &operator<<(std::ostream &out,\n> > > const SizeRange &sr)\n> > > > > >    * \\brief Describe a rectangle's position and dimensions\n> > > > > >    *\n> > > > > >    * Rectangles are used to identify an area of an image. They\n> are\n> > > specified by\n> > > > > > - * the coordinates of top-left corner and their horizontal and\n> > > vertical size.\n> > > > > > + * the coordinates of the corner closer to the reference\n> system's\n> > > origin point\n> > > > > > + * and by horizontal and vertical increments from there.\n> > > > > >    *\n> > > > > > - * The measure unit of the rectangle coordinates and size, as\n> well\n> > > as the\n> > > > > > - * reference point from which the Rectangle::x and Rectangle::y\n> > > displacements\n> > > > > > - * refers to, are defined by the context were rectangle is used.\n> > > > > > + * The corner closer to the reference system's origin point is\n> the\n> > > rectangle's\n> > > > > > + * origin corner.\n> > > > > > + *\n> > > > > > + * \\verbatim\n> > > > > > +\n> > > > > > +  o = origin corner\n> > > > > > +\n> > > > > > +         ^\n> > > > > > +         |\n> > > > > > +         |      -------------------\n> > > > > > +         |      ^                 |\n> > > > > > +         |      |                 |\n> > > > > > +         |      o---->-------------\n> > > > > > +         |\n> > > > > > +          ------------------------------->\n> > > > > > +         (0,0)\n> > > > > > +\n> > > > > > +         (0,0)\n> > > > > > +           ------------------------------->\n> > > > > > +          |\n> > > > > > +          |      o---->-------------\n> > > > > > +          |      |                 |\n> > > > > > +          |      v                 |\n> > > > > > +          |      -------------------\n> > > > > > +          |\n> > > > > > +          V\n> > > > > > +   \\endverbatim\n> > > > > > + *\n> > > > > > + * The measure unit of the rectangle coordinates and size are\n> > > defined by the\n> > > > > > + * context were the rectangle is used.\n> > > > > >    */\n> > > > > >\n> > > > > >   /**\n> > > > > > @@ -608,35 +636,50 @@ std::ostream &operator<<(std::ostream &out,\n> > > const SizeRange &sr)\n> > > > > >   /**\n> > > > > >    * \\fn Rectangle::Rectangle(int x, int y, const Size &size)\n> > > > > >    * \\brief Construct a Rectangle with the given position and\n> size\n> > > > > > - * \\param[in] x The horizontal coordinate of the top-left corner\n> > > > > > - * \\param[in] y The vertical coordinate of the top-left corner\n> > > > > > + * \\param[in] x The horizontal coordinate of the origin corner\n> > > > > > + * \\param[in] y The vertical coordinate of the origin corner\n> > > > > >    * \\param[in] size The size\n> > > > > > + *\n> > > > > > + * The rectangle's origin corner is the corner closer to the\n> > > reference system\n> > > > > > + * origin point (0, 0).\n> > > >\n> > > > I think we should stick to the previous description:\n> > > > `\"origin\" point defined as the point with the lower x and\n> > > > lower y of the rectangle`, as `x` and `y` are signed integers.\n> > > >\n> > > > If we only support coordinates that are positive or 0, which\n> > > > I'm not sure if it's the case, how about making the type to be\n> > > > `unsigned int`?\n> > > >\n> > >\n> > > To be honest I would rather make width and heigh signed to allow\n> > > constructing (x, y, -w, -h)\n> > >\n> > >\n> > >\n> > >\n> > >                -------------------\n> > >                |                 ^\n> > >                |            ------------->\n> > >                |           |     |\n> > >                ------<-----|-----o\n> > >                            |\n> > >                            |\n> > >                            V\n> > >\n> > > Not sure if it's useful or not though\n> > >\n> >\n> > Hmm... I find it pretty weird. What if all four corners have all negative\n> > coordinates?\n> >\n> >\n>\n> Don't know, maybe if the reference system where the rectangle is used\n> into has 4 planes and so an all-negative rectangle makes sense.\n>\n> My point is that we should allow users of this class to express\n> Rectangle in any context they plan to use them. Not sure if I'm going\n> overboard here or it makes sense.\n>\n\nYeah I agree, while doesn't that mean the description doesn't fit all\ncases, like the corner closer to the reference system origin point of a\nrectangle that has all negative coordinates is actually the \"bottom-right\"\ncorner, and currently libcamera::Size only allows non-negative width and\nheight [1].\n\n[1]:\nhttps://git.libcamera.org/libcamera/libcamera.git/tree/include/libcamera/geometry.h#n65\n\n\n> >\n> >\n> > >\n> > > > BR,\n> > > > Harvey\n> > > >\n> > > >\n> > > > > >    */\n> > > > > >\n> > > > > >   /**\n> > > > > >    * \\fn Rectangle::Rectangle(int x, int y, unsigned int width,\n> > > unsigned int height)\n> > > > > >    * \\brief Construct a Rectangle with the given position and\n> size\n> > > > > > - * \\param[in] x The horizontal coordinate of the top-left corner\n> > > > > > - * \\param[in] y The vertical coordinate of the top-left corner\n> > > > > > + * \\param[in] x The horizontal coordinate of the origin corner\n> > > > > > + * \\param[in] y The vertical coordinate of the origin corner\n> > > > > >    * \\param[in] width The width\n> > > > > >    * \\param[in] height The height\n> > > > > > + *\n> > > > > > + * The rectangle's origin corner is the corner closer to the\n> > > reference system\n> > > > > > + * origin point (0, 0).\n> > > > > >    */\n> > > > > >\n> > > > > >   /**\n> > > > > >    * \\fn Rectangle::Rectangle(const Size &size)\n> > > > > > - * \\brief Construct a Rectangle of \\a size with its top left\n> corner\n> > > located\n> > > > > > + * \\brief Construct a Rectangle of \\a size with its origin\n> corner\n> > > located\n> > > > > >    * at (0,0)\n> > > > > >    * \\param[in] size The desired Rectangle size\n> > > > > > + *\n> > > > > > + * The rectangle's origin corner is the corner closer to the\n> > > reference system\n> > > > > > + * origin point (0, 0).\n> > > > > >    */\n> > > > > >\n> > > > > >   /**\n> > > > > >    * \\var Rectangle::x\n> > > > > > - * \\brief The horizontal coordinate of the rectangle's top-left\n> > > corner\n> > > > > > + * \\brief The horizontal coordinate of the rectangle's origin\n> corner\n> > > > > > + *\n> > > > > > + * The rectangle's origin corner is the corner closer to the\n> > > reference system\n> > > > > > + * origin point (0, 0).\n> > > > > >    */\n> > > > > >\n> > > > > >   /**\n> > > > > >    * \\var Rectangle::y\n> > > > > > - * \\brief The vertical coordinate of the rectangle's top-left\n> corner\n> > > > > > + * \\brief The vertical coordinate of the rectangle's origin\n> corner\n> > > > > > + *\n> > > > > > + * The rectangle's origin corner is the corner closer to the\n> > > reference system\n> > > > > > + * origin point (0, 0).\n> > > > > >    */\n> > > > > >\n> > > > > >   /**\n> > > > > > @@ -683,9 +726,13 @@ Point Rectangle::center() const\n> > > > > >    */\n> > > > > >\n> > > > > >   /**\n> > > > > > - * \\fn Point Rectangle::topLeft() const\n> > > > > > - * \\brief Retrieve the coordinates of the top left corner of\n> this\n> > > Rectangle\n> > > > > > - * \\return The Rectangle's top left corner\n> > > > > > + * \\fn Point Rectangle::origin() const\n> > > > > > + * \\brief Retrieve the coordinates of the origin corner of this\n> > > Rectangle\n> > > > > > + *\n> > > > > > + * The rectangle's origin corner is the corner closer to the\n> > > reference system\n> > > > > > + * origin point (0, 0).\n> > > > > > + *\n> > > > > > + * \\return The Rectangle's origin corner\n> > > > >\n> > > > > I think you can drop \"corner\" from \"origin corner\"\n> > > > >\n> > > > > Probably throughout the patch:\n> > > > >      s/origin corner/origin/\n> > > > >\n> > > > > Otherwise, LGTM\n> > > > >\n> > > > > Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>\n> > > > > >    */\n> > > > > >\n> > > > > >   /**\n> > > > > > @@ -740,15 +787,15 @@ Rectangle &Rectangle::translateBy(const\n> Point\n> > > &point)\n> > > > > >    */\n> > > > > >   Rectangle Rectangle::boundedTo(const Rectangle &bound) const\n> > > > > >   {\n> > > > > > -     int topLeftX = std::max(x, bound.x);\n> > > > > > -     int topLeftY = std::max(y, bound.y);\n> > > > > > +     int originX = std::max(x, bound.x);\n> > > > > > +     int originY = std::max(y, bound.y);\n> > > > > >       int bottomRightX = std::min<int>(x + width, bound.x +\n> > > bound.width);\n> > > > > >       int bottomRightY = std::min<int>(y + height, bound.y +\n> > > bound.height);\n> > > > > >\n> > > > > > -     unsigned int newWidth = std::max(bottomRightX - topLeftX,\n> 0);\n> > > > > > -     unsigned int newHeight = std::max(bottomRightY - topLeftY,\n> 0);\n> > > > > > +     unsigned int newWidth = std::max(bottomRightX - originX,\n> 0);\n> > > > > > +     unsigned int newHeight = std::max(bottomRightY - originY,\n> 0);\n> > > > > >\n> > > > > > -     return { topLeftX, topLeftY, newWidth, newHeight };\n> > > > > > +     return { originX, originY, newWidth, newHeight };\n> > > > > >   }\n> > > > > >\n> > > > > >   /**\n> > > > > > diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n> > > b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n> > > > > > index 3041fd1ed9fd..8d2440026689 100644\n> > > > > > --- a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n> > > > > > +++ b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n> > > > > > @@ -1289,7 +1289,7 @@ Rectangle CameraData::scaleIspCrop(const\n> > > Rectangle &ispCrop) const\n> > > > > >        */\n> > > > > >       Rectangle nativeCrop =\n> > > ispCrop.scaledBy(sensorInfo_.analogCrop.size(),\n> > > > > >\n> > >  sensorInfo_.outputSize);\n> > > > > > -     nativeCrop.translateBy(sensorInfo_.analogCrop.topLeft());\n> > > > > > +     nativeCrop.translateBy(sensorInfo_.analogCrop.origin());\n> > > > > >       return nativeCrop;\n> > > > > >   }\n> > > > > >\n> > > > > > @@ -1303,7 +1303,7 @@ void CameraData::applyScalerCrop(const\n> > > ControlList &controls)\n> > > > > >                       nativeCrop = { 0, 0, 1, 1 };\n> > > > > >\n> > > > > >               /* Create a version of the crop scaled to ISP\n> (camera\n> > > mode) pixels. */\n> > > > > > -             Rectangle ispCrop =\n> > > nativeCrop.translatedBy(-sensorInfo_.analogCrop.topLeft());\n> > > > > > +             Rectangle ispCrop =\n> > > nativeCrop.translatedBy(-sensorInfo_.analogCrop.origin());\n> > > > > >               ispCrop.scaleBy(sensorInfo_.outputSize,\n> > > sensorInfo_.analogCrop.size());\n> > > > > >\n> > > > > >               /*\n> > > > > > diff --git a/src/py/libcamera/py_geometry.cpp\n> > > b/src/py/libcamera/py_geometry.cpp\n> > > > > > index c7e303609427..8dee365b25dd 100644\n> > > > > > --- a/src/py/libcamera/py_geometry.cpp\n> > > > > > +++ b/src/py/libcamera/py_geometry.cpp\n> > > > > > @@ -105,7 +105,7 @@ void init_py_geometry(py::module &m)\n> > > > > >               .def_property_readonly(\"is_null\",\n> &Rectangle::isNull)\n> > > > > >               .def_property_readonly(\"center\",\n> &Rectangle::center)\n> > > > > >               .def_property_readonly(\"size\", &Rectangle::size)\n> > > > > > -             .def_property_readonly(\"topLeft\",\n> &Rectangle::topLeft)\n> > > > > > +             .def_property_readonly(\"origin\",\n> &Rectangle::origin)\n> > > > > >               .def(\"scale_by\", &Rectangle::scaleBy)\n> > > > > >               .def(\"translate_by\", &Rectangle::translateBy)\n> > > > > >               .def(\"bounded_to\", &Rectangle::boundedTo)\n> > > > > > diff --git a/test/geometry.cpp b/test/geometry.cpp\n> > > > > > index 64169206ad16..a4ee6f6e167a 100644\n> > > > > > --- a/test/geometry.cpp\n> > > > > > +++ b/test/geometry.cpp\n> > > > > > @@ -363,16 +363,16 @@ protected:\n> > > > > >                       return TestFail;\n> > > > > >               }\n> > > > > >\n> > > > > > -             /* Rectangle::size(), Rectangle::topLeft() and\n> > > Rectangle::center() tests */\n> > > > > > +             /* Rectangle::size(), Rectangle::origin() and\n> > > Rectangle::center() tests */\n> > > > > >               if (Rectangle(-1, -2, 3, 4).size() != Size(3, 4) ||\n> > > > > >                   Rectangle(0, 0, 100000, 200000).size() !=\n> > > Size(100000, 200000)) {\n> > > > > >                       cout << \"Rectangle::size() test failed\" <<\n> > > endl;\n> > > > > >                       return TestFail;\n> > > > > >               }\n> > > > > >\n> > > > > > -             if (Rectangle(1, 2, 3, 4).topLeft() != Point(1, 2)\n> ||\n> > > > > > -                 Rectangle(-1, -2, 3, 4).topLeft() != Point(-1,\n> > > -2)) {\n> > > > > > -                     cout << \"Rectangle::topLeft() test failed\"\n> <<\n> > > endl;\n> > > > > > +             if (Rectangle(1, 2, 3, 4).origin() != Point(1, 2)\n> ||\n> > > > > > +                 Rectangle(-1, -2, 3, 4).origin() != Point(-1,\n> -2))\n> > > {\n> > > > > > +                     cout << \"Rectangle::origin() test failed\"\n> <<\n> > > endl;\n> > > > > >                       return TestFail;\n> > > > > >               }\n> > > > > >\n> > > > > > --\n> > > > > > 2.46.1\n> > > > > >\n> > > > >\n> > > >\n> > > >\n> > > > --\n> > > > BR,\n> > > > Harvey Yang\n> > >\n>","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 34DA5C0F1B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 26 Sep 2024 09:28:27 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id DA00D6350E;\n\tThu, 26 Sep 2024 11:28:26 +0200 (CEST)","from mail-lf1-x133.google.com (mail-lf1-x133.google.com\n\t[IPv6:2a00:1450:4864:20::133])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 54782634F2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 26 Sep 2024 11:28:25 +0200 (CEST)","by mail-lf1-x133.google.com with SMTP id\n\t2adb3069b0e04-53690eb134bso4149e87.0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 26 Sep 2024 02:28:25 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key;\n\tunprotected) header.d=google.com header.i=@google.com\n\theader.b=\"1//sHZ0+\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=google.com; s=20230601; t=1727342904; x=1727947704;\n\tdarn=lists.libcamera.org; \n\th=cc:to:subject:message-id:date:from:in-reply-to:references\n\t:mime-version:from:to:cc:subject:date:message-id:reply-to;\n\tbh=TvPkc3QpK8AChNmBZlr8YTHipHk6OH0sLrMtTRAsnDo=;\n\tb=1//sHZ0+hgyYN3K4sR+YKU5+rm8a4E6ipiwD+V6lsBNhIuPiSpcl1yrl/dQ5rufQ9v\n\txqIbTvQWVJSBxgrRa1vnJzjHTsI0BKb8bZzCYZjEU8Lafdsj/0O9b4nyppaZC8iStvUD\n\tkhVJU9L+UZv2ErgPkXa6eE3q/3/3T7K5E3xDjxdTldIlPYJl8fj9ZKgdq42Lf+l1pK1G\n\tE2HzXYXLZgwO7FtUl4YHpP/8nKSnlqUUwW1W0fXxR3QWB0SUTPyW9hPIOXvx+36rug+H\n\tz0PtcxWHJMndlpvaZ1pxkZJJJipXPJa5vTt0qkLgrRGluw/Y5px3kmoGW4ZTqNSzhSun\n\tRvcw==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1727342904; x=1727947704;\n\th=cc:to:subject:message-id:date:from:in-reply-to:references\n\t:mime-version:x-gm-message-state:from:to:cc:subject:date:message-id\n\t:reply-to;\n\tbh=TvPkc3QpK8AChNmBZlr8YTHipHk6OH0sLrMtTRAsnDo=;\n\tb=IlUPcTvvBAMT6jmdHenhndf+jHEwUnwifKQZHtm84sb1D6DxDCEYnnV1W79KyUgepD\n\tdxTmKsTFcDmSsrRWfxjYys7b0zb4nOOGdNZTFKRZaMVaz56z9WWiprGE9Tv0IpPmbE0o\n\tLhpSDO9ahTNFKODU4/7yFCdwu0ly5qJXzK9C2GF935sT/fQUwm2VKF0F5OulxoTKWKKB\n\tFJCbmPIUT7Twghh/D/2OuJkcyD1n6IlzaUhyv52YlmY8/VVoOgswBH4C8TWssQWp6Qk5\n\ttfzbdFKxWY+7HlgeK5yzqYFkU9wjI41zdT0ZrPx0p/iYk0dMQwfw7EgqpQPnnF2VxzSc\n\tP7wg==","X-Forwarded-Encrypted":"i=1;\n\tAJvYcCXTNMN7Xe+Hr6MUmEY4J9qwcYjPTQkurhBxBfOkRPMTsq/FkQpQQzD40crc3XTT2Sz/mlvu/+VLPDrXimVte8Q=@lists.libcamera.org","X-Gm-Message-State":"AOJu0YyJSsBFoVgxKQ+34q2JvsmHpjvSo4vX7p3dlLRqbI2EyaJlqqg2\n\trJDFJLnvrdRnFy1K32zlGRm8KwW872WawfAl3XB0XNBmZZ65tzXgFRplG3rqOv05jxuw3eYB32w\n\tnbgGkjvEb6ihb4tn0yhR7mgBrVqletucGxcFc","X-Google-Smtp-Source":"AGHT+IHbGUMPpXJVMPjbg6e3ay9hXFuNCjyaSnTGM0ADZCVoH5BbhkiZ5s3IpDGBolI872KAf2HdaZigk6TC4ogCeUE=","X-Received":"by 2002:a05:6512:32c6:b0:535:3d14:1313 with SMTP id\n\t2adb3069b0e04-5389720d96fmr104172e87.0.1727342904035; Thu, 26 Sep 2024\n\t02:28:24 -0700 (PDT)","MIME-Version":"1.0","References":"<20240924124525.95189-1-jacopo.mondi@ideasonboard.com>\n\t<d975583c-7f5d-4f5b-8e99-5cdc61396667@ideasonboard.com>\n\t<CAC=wSGUwXZDvM68ZfhqPvYKhAB0bkem=zJhFJ-Fjafc9OYhDqA@mail.gmail.com>\n\t<uzptnxdipytxx4nwqusnr62asaiwrdawylf2f3vzbmkc53onhc@nkeomtxtfw5g>\n\t<CAC=wSGWEZU7_=nEFTp+g_g74L7kcs65wK3oOeS8xwBqzMHa5wQ@mail.gmail.com>\n\t<zsszrdewqlrlovncquphk43ajxyksfoijoiorglvwem4kb2u6q@my2gscqpdzd3>","In-Reply-To":"<zsszrdewqlrlovncquphk43ajxyksfoijoiorglvwem4kb2u6q@my2gscqpdzd3>","From":"Cheng-Hao Yang <chenghaoyang@google.com>","Date":"Thu, 26 Sep 2024 17:28:13 +0800","Message-ID":"<CAC=wSGXj==p2GZMidtwb9pUhmnuRrdqbGhQUF14HSNfTzgz_Cw@mail.gmail.com>","Subject":"Re: [PATCH] libcamera: geometry: Rename Rectangle's top-left corner","To":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>","Cc":"Umang Jain <umang.jain@ideasonboard.com>, \n\tlibcamera devel <libcamera-devel@lists.libcamera.org>","Content-Type":"multipart/alternative; boundary=\"000000000000344a670623025c90\"","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>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":31388,"web_url":"https://patchwork.libcamera.org/comment/31388/","msgid":"<62yvkiqioilupdcm7ryjtrz273iamzojfi2pgxndmjwoyyaitb@iq46e47ke2vg>","date":"2024-09-26T09:36:35","subject":"Re: [PATCH] libcamera: geometry: Rename Rectangle's top-left corner","submitter":{"id":143,"url":"https://patchwork.libcamera.org/api/people/143/","name":"Jacopo Mondi","email":"jacopo.mondi@ideasonboard.com"},"content":"Hi Harvey\n\nOn Thu, Sep 26, 2024 at 05:28:13PM GMT, Cheng-Hao Yang wrote:\n> Hi Jacopo,\n>\n>\n>\n> On Thu, Sep 26, 2024, 4:38 PM Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n> wrote:\n>\n> > Hi Harvey\n> >\n> > On Thu, Sep 26, 2024 at 04:29:50PM GMT, Cheng-Hao Yang wrote:\n> > > Hi Jacopo,\n> > >\n> > > On Thu, Sep 26, 2024, 4:03 PM Jacopo Mondi <\n> > jacopo.mondi@ideasonboard.com>\n> > > wrote:\n> > >\n> > > > Hi Harvey\n> > > >\n> > > > On Wed, Sep 25, 2024 at 03:09:38PM GMT, Cheng-Hao Yang wrote:\n> > > > > Hi Jacopo,\n> > > > >\n> > > > > Thank you for the patch.\n> > > > >\n> > > > > On Wed, Sep 25, 2024 at 2:36 PM Umang Jain <\n> > umang.jain@ideasonboard.com>\n> > > > wrote:\n> > > > > >\n> > > > > > Hi Jacopo\n> > > > > >\n> > > > > > Thank you for the patch\n> > > > > >\n> > > > > > On 24/09/24 6:15 pm, Jacopo Mondi wrote:\n> > > > > > > The libcamera::Rectangle class should allow defining rectangles\n> > > > > > > regardless of the reference system where an instance is used in.\n> > > > > > >\n> > > > > > > However the class documentation assumes the reference system\n> > origin\n> > > > > > > point to be in the visual top-left side and that rectangles are\n> > > > > > > constructed by specifying the top-left corner position and sizes.\n> > > > > > >\n> > > > > > > However this is ambiguous when using a different reference\n> > system as,\n> > > > > > > in example, constructing a rectangle (x, y, w, h) in the\n> > following\n> > > > > > > scenario, with the origin corner in the top-left position, would\n> > > > require\n> > > > > > > a negative decrement along the y-axis.\n> > > > > > >\n> > > > > > >           ^\n> > > > > > >           |\n> > > > > > >          y|      o------------------\n> > > > > > >           |      |                 | h\n> > > > > > >           |      |                 |\n> > > > > > >           |      -------------------\n> > > > > > >           |               w\n> > > > > > >            ------------------------------->\n> > > > > > >           (0,0)  x\n> > > > > > >\n> > > > > > > To remove ambiguities, drop references to the visual top-left\n> > corner\n> > > > and\n> > > > > > > define the rectangle's origin corner as the corner closer to the\n> > > > > > > reference system origin point, and specify the horizontal and\n> > > > vertical\n> > > > > > > dimensions always increment along their respective axis, as in\n> > the\n> > > > > > > following example.\n> > > > > > >\n> > > > > > >           ^\n> > > > > > >           |\n> > > > > > >           |      -------------------\n> > > > > > >           |      ^                 | h\n> > > > > > >           |      |                 |\n> > > > > > >          y|      o---->-------------\n> > > > > > >           |               w\n> > > > > > >            ------------------------------->\n> > > > > > >           (0,0)  x\n> > > > > > >\n> > > > > > >           (0,0)  x\n> > > > > > >             ------------------------------>\n> > > > > > >            |              w\n> > > > > > >           y|     o---->-------------\n> > > > > > >            |     |                 | h\n> > > > > > >            |     v                 |\n> > > > > > >            |     -------------------\n> > > > > > >            |\n> > > > > > >            V\n> > > > > > >\n> > > > > > > Also rename for consistency the Rectangle::topLeft() function to\n> > > > > > > Rectangle::origin() and update its in-tree users.\n> > > > > > >\n> > > > > > > Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n> > > > > > > ---\n> > > > > > >   include/libcamera/geometry.h                  |  2 +-\n> > > > > > >   src/ipa/ipu3/algorithms/af.cpp                |  2 +-\n> > > > > > >   src/libcamera/geometry.cpp                    | 85\n> > > > ++++++++++++++-----\n> > > > > > >   .../pipeline/rpi/common/pipeline_base.cpp     |  4 +-\n> > > > > > >   src/py/libcamera/py_geometry.cpp              |  2 +-\n> > > > > > >   test/geometry.cpp                             |  8 +-\n> > > > > > >   6 files changed, 75 insertions(+), 28 deletions(-)\n> > > > > > >\n> > > > > > > diff --git a/include/libcamera/geometry.h\n> > > > b/include/libcamera/geometry.h\n> > > > > > > index 3e6f0f5d7fab..07cb0a7866fe 100644\n> > > > > > > --- a/include/libcamera/geometry.h\n> > > > > > > +++ b/include/libcamera/geometry.h\n> > > > > > > @@ -277,7 +277,7 @@ public:\n> > > > > > >               return { width, height };\n> > > > > > >       }\n> > > > > > >\n> > > > > > > -     Point topLeft() const\n> > > > > > > +     Point origin() const\n> > > > > > >       {\n> > > > > > >               return { x, y };\n> > > > > > >       }\n> > > > > > > diff --git a/src/ipa/ipu3/algorithms/af.cpp\n> > > > b/src/ipa/ipu3/algorithms/af.cpp\n> > > > > > > index cf68fb59c49b..1b707e9dd9ab 100644\n> > > > > > > --- a/src/ipa/ipu3/algorithms/af.cpp\n> > > > > > > +++ b/src/ipa/ipu3/algorithms/af.cpp\n> > > > > > > @@ -155,7 +155,7 @@ int Af::configure(IPAContext &context, const\n> > > > IPAConfigInfo &configInfo)\n> > > > > > >        * - Return the AF ROI as metadata in the Request\n> > > > > > >        */\n> > > > > > >       Rectangle roi = gridSize.centeredTo(bds.center());\n> > > > > > > -     Point start = roi.topLeft();\n> > > > > > > +     Point start = roi.origin();\n> > > > > > >\n> > > > > > >       /* x_start and y_start should be even */\n> > > > > > >       grid.x_start = utils::alignDown(start.x, 2);\n> > > > > > > diff --git a/src/libcamera/geometry.cpp\n> > b/src/libcamera/geometry.cpp\n> > > > > > > index 000151364c7f..45ba81a99920 100644\n> > > > > > > --- a/src/libcamera/geometry.cpp\n> > > > > > > +++ b/src/libcamera/geometry.cpp\n> > > > > > > @@ -593,11 +593,39 @@ std::ostream &operator<<(std::ostream &out,\n> > > > const SizeRange &sr)\n> > > > > > >    * \\brief Describe a rectangle's position and dimensions\n> > > > > > >    *\n> > > > > > >    * Rectangles are used to identify an area of an image. They\n> > are\n> > > > specified by\n> > > > > > > - * the coordinates of top-left corner and their horizontal and\n> > > > vertical size.\n> > > > > > > + * the coordinates of the corner closer to the reference\n> > system's\n> > > > origin point\n> > > > > > > + * and by horizontal and vertical increments from there.\n> > > > > > >    *\n> > > > > > > - * The measure unit of the rectangle coordinates and size, as\n> > well\n> > > > as the\n> > > > > > > - * reference point from which the Rectangle::x and Rectangle::y\n> > > > displacements\n> > > > > > > - * refers to, are defined by the context were rectangle is used.\n> > > > > > > + * The corner closer to the reference system's origin point is\n> > the\n> > > > rectangle's\n> > > > > > > + * origin corner.\n> > > > > > > + *\n> > > > > > > + * \\verbatim\n> > > > > > > +\n> > > > > > > +  o = origin corner\n> > > > > > > +\n> > > > > > > +         ^\n> > > > > > > +         |\n> > > > > > > +         |      -------------------\n> > > > > > > +         |      ^                 |\n> > > > > > > +         |      |                 |\n> > > > > > > +         |      o---->-------------\n> > > > > > > +         |\n> > > > > > > +          ------------------------------->\n> > > > > > > +         (0,0)\n> > > > > > > +\n> > > > > > > +         (0,0)\n> > > > > > > +           ------------------------------->\n> > > > > > > +          |\n> > > > > > > +          |      o---->-------------\n> > > > > > > +          |      |                 |\n> > > > > > > +          |      v                 |\n> > > > > > > +          |      -------------------\n> > > > > > > +          |\n> > > > > > > +          V\n> > > > > > > +   \\endverbatim\n> > > > > > > + *\n> > > > > > > + * The measure unit of the rectangle coordinates and size are\n> > > > defined by the\n> > > > > > > + * context were the rectangle is used.\n> > > > > > >    */\n> > > > > > >\n> > > > > > >   /**\n> > > > > > > @@ -608,35 +636,50 @@ std::ostream &operator<<(std::ostream &out,\n> > > > const SizeRange &sr)\n> > > > > > >   /**\n> > > > > > >    * \\fn Rectangle::Rectangle(int x, int y, const Size &size)\n> > > > > > >    * \\brief Construct a Rectangle with the given position and\n> > size\n> > > > > > > - * \\param[in] x The horizontal coordinate of the top-left corner\n> > > > > > > - * \\param[in] y The vertical coordinate of the top-left corner\n> > > > > > > + * \\param[in] x The horizontal coordinate of the origin corner\n> > > > > > > + * \\param[in] y The vertical coordinate of the origin corner\n> > > > > > >    * \\param[in] size The size\n> > > > > > > + *\n> > > > > > > + * The rectangle's origin corner is the corner closer to the\n> > > > reference system\n> > > > > > > + * origin point (0, 0).\n> > > > >\n> > > > > I think we should stick to the previous description:\n> > > > > `\"origin\" point defined as the point with the lower x and\n> > > > > lower y of the rectangle`, as `x` and `y` are signed integers.\n> > > > >\n> > > > > If we only support coordinates that are positive or 0, which\n> > > > > I'm not sure if it's the case, how about making the type to be\n> > > > > `unsigned int`?\n> > > > >\n> > > >\n> > > > To be honest I would rather make width and heigh signed to allow\n> > > > constructing (x, y, -w, -h)\n> > > >\n> > > >\n> > > >\n> > > >\n> > > >                -------------------\n> > > >                |                 ^\n> > > >                |            ------------->\n> > > >                |           |     |\n> > > >                ------<-----|-----o\n> > > >                            |\n> > > >                            |\n> > > >                            V\n> > > >\n> > > > Not sure if it's useful or not though\n> > > >\n> > >\n> > > Hmm... I find it pretty weird. What if all four corners have all negative\n> > > coordinates?\n> > >\n> > >\n> >\n> > Don't know, maybe if the reference system where the rectangle is used\n> > into has 4 planes and so an all-negative rectangle makes sense.\n> >\n> > My point is that we should allow users of this class to express\n> > Rectangle in any context they plan to use them. Not sure if I'm going\n> > overboard here or it makes sense.\n> >\n>\n> Yeah I agree, while doesn't that mean the description doesn't fit all\n> cases, like the corner closer to the reference system origin point of a\n> rectangle that has all negative coordinates is actually the \"bottom-right\"\n\nThis patch aims to remove all references to \"top-left\" or in general\nto any visual reference exactly for that purpose. Or have I forgot any\n?\n\n> corner, and currently libcamera::Size only allows non-negative width and\n> height [1].\n\nTrue, Size uses unsigned int. I don't think it's a big deal and I'm\nnot proposing to introduce a new constructor with signed width and\nheight now, but my point is that if the need arises we can now do\nthat.\n\n>\n> [1]:\n> https://git.libcamera.org/libcamera/libcamera.git/tree/include/libcamera/geometry.h#n65\n>\n>\n> > >\n> > >\n> > > >\n> > > > > BR,\n> > > > > Harvey\n> > > > >\n> > > > >\n> > > > > > >    */\n> > > > > > >\n> > > > > > >   /**\n> > > > > > >    * \\fn Rectangle::Rectangle(int x, int y, unsigned int width,\n> > > > unsigned int height)\n> > > > > > >    * \\brief Construct a Rectangle with the given position and\n> > size\n> > > > > > > - * \\param[in] x The horizontal coordinate of the top-left corner\n> > > > > > > - * \\param[in] y The vertical coordinate of the top-left corner\n> > > > > > > + * \\param[in] x The horizontal coordinate of the origin corner\n> > > > > > > + * \\param[in] y The vertical coordinate of the origin corner\n> > > > > > >    * \\param[in] width The width\n> > > > > > >    * \\param[in] height The height\n> > > > > > > + *\n> > > > > > > + * The rectangle's origin corner is the corner closer to the\n> > > > reference system\n> > > > > > > + * origin point (0, 0).\n> > > > > > >    */\n> > > > > > >\n> > > > > > >   /**\n> > > > > > >    * \\fn Rectangle::Rectangle(const Size &size)\n> > > > > > > - * \\brief Construct a Rectangle of \\a size with its top left\n> > corner\n> > > > located\n> > > > > > > + * \\brief Construct a Rectangle of \\a size with its origin\n> > corner\n> > > > located\n> > > > > > >    * at (0,0)\n> > > > > > >    * \\param[in] size The desired Rectangle size\n> > > > > > > + *\n> > > > > > > + * The rectangle's origin corner is the corner closer to the\n> > > > reference system\n> > > > > > > + * origin point (0, 0).\n> > > > > > >    */\n> > > > > > >\n> > > > > > >   /**\n> > > > > > >    * \\var Rectangle::x\n> > > > > > > - * \\brief The horizontal coordinate of the rectangle's top-left\n> > > > corner\n> > > > > > > + * \\brief The horizontal coordinate of the rectangle's origin\n> > corner\n> > > > > > > + *\n> > > > > > > + * The rectangle's origin corner is the corner closer to the\n> > > > reference system\n> > > > > > > + * origin point (0, 0).\n> > > > > > >    */\n> > > > > > >\n> > > > > > >   /**\n> > > > > > >    * \\var Rectangle::y\n> > > > > > > - * \\brief The vertical coordinate of the rectangle's top-left\n> > corner\n> > > > > > > + * \\brief The vertical coordinate of the rectangle's origin\n> > corner\n> > > > > > > + *\n> > > > > > > + * The rectangle's origin corner is the corner closer to the\n> > > > reference system\n> > > > > > > + * origin point (0, 0).\n> > > > > > >    */\n> > > > > > >\n> > > > > > >   /**\n> > > > > > > @@ -683,9 +726,13 @@ Point Rectangle::center() const\n> > > > > > >    */\n> > > > > > >\n> > > > > > >   /**\n> > > > > > > - * \\fn Point Rectangle::topLeft() const\n> > > > > > > - * \\brief Retrieve the coordinates of the top left corner of\n> > this\n> > > > Rectangle\n> > > > > > > - * \\return The Rectangle's top left corner\n> > > > > > > + * \\fn Point Rectangle::origin() const\n> > > > > > > + * \\brief Retrieve the coordinates of the origin corner of this\n> > > > Rectangle\n> > > > > > > + *\n> > > > > > > + * The rectangle's origin corner is the corner closer to the\n> > > > reference system\n> > > > > > > + * origin point (0, 0).\n> > > > > > > + *\n> > > > > > > + * \\return The Rectangle's origin corner\n> > > > > >\n> > > > > > I think you can drop \"corner\" from \"origin corner\"\n> > > > > >\n> > > > > > Probably throughout the patch:\n> > > > > >      s/origin corner/origin/\n> > > > > >\n> > > > > > Otherwise, LGTM\n> > > > > >\n> > > > > > Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>\n> > > > > > >    */\n> > > > > > >\n> > > > > > >   /**\n> > > > > > > @@ -740,15 +787,15 @@ Rectangle &Rectangle::translateBy(const\n> > Point\n> > > > &point)\n> > > > > > >    */\n> > > > > > >   Rectangle Rectangle::boundedTo(const Rectangle &bound) const\n> > > > > > >   {\n> > > > > > > -     int topLeftX = std::max(x, bound.x);\n> > > > > > > -     int topLeftY = std::max(y, bound.y);\n> > > > > > > +     int originX = std::max(x, bound.x);\n> > > > > > > +     int originY = std::max(y, bound.y);\n> > > > > > >       int bottomRightX = std::min<int>(x + width, bound.x +\n> > > > bound.width);\n> > > > > > >       int bottomRightY = std::min<int>(y + height, bound.y +\n> > > > bound.height);\n> > > > > > >\n> > > > > > > -     unsigned int newWidth = std::max(bottomRightX - topLeftX,\n> > 0);\n> > > > > > > -     unsigned int newHeight = std::max(bottomRightY - topLeftY,\n> > 0);\n> > > > > > > +     unsigned int newWidth = std::max(bottomRightX - originX,\n> > 0);\n> > > > > > > +     unsigned int newHeight = std::max(bottomRightY - originY,\n> > 0);\n> > > > > > >\n> > > > > > > -     return { topLeftX, topLeftY, newWidth, newHeight };\n> > > > > > > +     return { originX, originY, newWidth, newHeight };\n> > > > > > >   }\n> > > > > > >\n> > > > > > >   /**\n> > > > > > > diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n> > > > b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n> > > > > > > index 3041fd1ed9fd..8d2440026689 100644\n> > > > > > > --- a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n> > > > > > > +++ b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n> > > > > > > @@ -1289,7 +1289,7 @@ Rectangle CameraData::scaleIspCrop(const\n> > > > Rectangle &ispCrop) const\n> > > > > > >        */\n> > > > > > >       Rectangle nativeCrop =\n> > > > ispCrop.scaledBy(sensorInfo_.analogCrop.size(),\n> > > > > > >\n> > > >  sensorInfo_.outputSize);\n> > > > > > > -     nativeCrop.translateBy(sensorInfo_.analogCrop.topLeft());\n> > > > > > > +     nativeCrop.translateBy(sensorInfo_.analogCrop.origin());\n> > > > > > >       return nativeCrop;\n> > > > > > >   }\n> > > > > > >\n> > > > > > > @@ -1303,7 +1303,7 @@ void CameraData::applyScalerCrop(const\n> > > > ControlList &controls)\n> > > > > > >                       nativeCrop = { 0, 0, 1, 1 };\n> > > > > > >\n> > > > > > >               /* Create a version of the crop scaled to ISP\n> > (camera\n> > > > mode) pixels. */\n> > > > > > > -             Rectangle ispCrop =\n> > > > nativeCrop.translatedBy(-sensorInfo_.analogCrop.topLeft());\n> > > > > > > +             Rectangle ispCrop =\n> > > > nativeCrop.translatedBy(-sensorInfo_.analogCrop.origin());\n> > > > > > >               ispCrop.scaleBy(sensorInfo_.outputSize,\n> > > > sensorInfo_.analogCrop.size());\n> > > > > > >\n> > > > > > >               /*\n> > > > > > > diff --git a/src/py/libcamera/py_geometry.cpp\n> > > > b/src/py/libcamera/py_geometry.cpp\n> > > > > > > index c7e303609427..8dee365b25dd 100644\n> > > > > > > --- a/src/py/libcamera/py_geometry.cpp\n> > > > > > > +++ b/src/py/libcamera/py_geometry.cpp\n> > > > > > > @@ -105,7 +105,7 @@ void init_py_geometry(py::module &m)\n> > > > > > >               .def_property_readonly(\"is_null\",\n> > &Rectangle::isNull)\n> > > > > > >               .def_property_readonly(\"center\",\n> > &Rectangle::center)\n> > > > > > >               .def_property_readonly(\"size\", &Rectangle::size)\n> > > > > > > -             .def_property_readonly(\"topLeft\",\n> > &Rectangle::topLeft)\n> > > > > > > +             .def_property_readonly(\"origin\",\n> > &Rectangle::origin)\n> > > > > > >               .def(\"scale_by\", &Rectangle::scaleBy)\n> > > > > > >               .def(\"translate_by\", &Rectangle::translateBy)\n> > > > > > >               .def(\"bounded_to\", &Rectangle::boundedTo)\n> > > > > > > diff --git a/test/geometry.cpp b/test/geometry.cpp\n> > > > > > > index 64169206ad16..a4ee6f6e167a 100644\n> > > > > > > --- a/test/geometry.cpp\n> > > > > > > +++ b/test/geometry.cpp\n> > > > > > > @@ -363,16 +363,16 @@ protected:\n> > > > > > >                       return TestFail;\n> > > > > > >               }\n> > > > > > >\n> > > > > > > -             /* Rectangle::size(), Rectangle::topLeft() and\n> > > > Rectangle::center() tests */\n> > > > > > > +             /* Rectangle::size(), Rectangle::origin() and\n> > > > Rectangle::center() tests */\n> > > > > > >               if (Rectangle(-1, -2, 3, 4).size() != Size(3, 4) ||\n> > > > > > >                   Rectangle(0, 0, 100000, 200000).size() !=\n> > > > Size(100000, 200000)) {\n> > > > > > >                       cout << \"Rectangle::size() test failed\" <<\n> > > > endl;\n> > > > > > >                       return TestFail;\n> > > > > > >               }\n> > > > > > >\n> > > > > > > -             if (Rectangle(1, 2, 3, 4).topLeft() != Point(1, 2)\n> > ||\n> > > > > > > -                 Rectangle(-1, -2, 3, 4).topLeft() != Point(-1,\n> > > > -2)) {\n> > > > > > > -                     cout << \"Rectangle::topLeft() test failed\"\n> > <<\n> > > > endl;\n> > > > > > > +             if (Rectangle(1, 2, 3, 4).origin() != Point(1, 2)\n> > ||\n> > > > > > > +                 Rectangle(-1, -2, 3, 4).origin() != Point(-1,\n> > -2))\n> > > > {\n> > > > > > > +                     cout << \"Rectangle::origin() test failed\"\n> > <<\n> > > > endl;\n> > > > > > >                       return TestFail;\n> > > > > > >               }\n> > > > > > >\n> > > > > > > --\n> > > > > > > 2.46.1\n> > > > > > >\n> > > > > >\n> > > > >\n> > > > >\n> > > > > --\n> > > > > BR,\n> > > > > Harvey Yang\n> > > >\n> >","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 D0919C32D4\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 26 Sep 2024 09:36:46 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 4F1D263516;\n\tThu, 26 Sep 2024 11:36:46 +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 9261F6350B\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 26 Sep 2024 11:36:40 +0200 (CEST)","from ideasonboard.com (mob-5-90-51-229.net.vodafone.it\n\t[5.90.51.229])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id D23791587;\n\tThu, 26 Sep 2024 11:35:11 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"DU9QalI5\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1727343312;\n\tbh=GlqDyoBkJsCcJ3UHtB3E3/ID6RcW0gjJjd72+TrxaXQ=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=DU9QalI5/qwJm3nErH6fflFHqrpHSfvFQOqSMhdw4um0D1JEyG2Gl5ONPe4PPBBDP\n\tO9+4PaQzDKC3MyfwR1NdoMC7aDuXxjlW9YDuCA6JKEvRLFFV0a/9Gg9GVRJQz/m8sN\n\tiTGZrnpx0Xxv1M2I94Zqod7FE4Nrf6kbvR3JnjAE=","Date":"Thu, 26 Sep 2024 11:36:35 +0200","From":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>","To":"Cheng-Hao Yang <chenghaoyang@google.com>","Cc":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>, \n\tUmang Jain <umang.jain@ideasonboard.com>,\n\tlibcamera devel <libcamera-devel@lists.libcamera.org>","Subject":"Re: [PATCH] libcamera: geometry: Rename Rectangle's top-left corner","Message-ID":"<62yvkiqioilupdcm7ryjtrz273iamzojfi2pgxndmjwoyyaitb@iq46e47ke2vg>","References":"<20240924124525.95189-1-jacopo.mondi@ideasonboard.com>\n\t<d975583c-7f5d-4f5b-8e99-5cdc61396667@ideasonboard.com>\n\t<CAC=wSGUwXZDvM68ZfhqPvYKhAB0bkem=zJhFJ-Fjafc9OYhDqA@mail.gmail.com>\n\t<uzptnxdipytxx4nwqusnr62asaiwrdawylf2f3vzbmkc53onhc@nkeomtxtfw5g>\n\t<CAC=wSGWEZU7_=nEFTp+g_g74L7kcs65wK3oOeS8xwBqzMHa5wQ@mail.gmail.com>\n\t<zsszrdewqlrlovncquphk43ajxyksfoijoiorglvwem4kb2u6q@my2gscqpdzd3>\n\t<CAC=wSGXj==p2GZMidtwb9pUhmnuRrdqbGhQUF14HSNfTzgz_Cw@mail.gmail.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<CAC=wSGXj==p2GZMidtwb9pUhmnuRrdqbGhQUF14HSNfTzgz_Cw@mail.gmail.com>","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>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":31406,"web_url":"https://patchwork.libcamera.org/comment/31406/","msgid":"<CAC=wSGXgYv2YyZqwgRANhmVzPtLTkTHP4=R-_Sz+NE7wNzPJXw@mail.gmail.com>","date":"2024-09-26T14:03:55","subject":"Re: [PATCH] libcamera: geometry: Rename Rectangle's top-left corner","submitter":{"id":148,"url":"https://patchwork.libcamera.org/api/people/148/","name":"Cheng-Hao Yang","email":"chenghaoyang@google.com"},"content":"Hi Jacopo,\n\nOn Thu, Sep 26, 2024 at 5:36 PM Jacopo Mondi\n<jacopo.mondi@ideasonboard.com> wrote:\n>\n> Hi Harvey\n>\n> On Thu, Sep 26, 2024 at 05:28:13PM GMT, Cheng-Hao Yang wrote:\n> > Hi Jacopo,\n> >\n> >\n> >\n> > On Thu, Sep 26, 2024, 4:38 PM Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n> > wrote:\n> >\n> > > Hi Harvey\n> > >\n> > > On Thu, Sep 26, 2024 at 04:29:50PM GMT, Cheng-Hao Yang wrote:\n> > > > Hi Jacopo,\n> > > >\n> > > > On Thu, Sep 26, 2024, 4:03 PM Jacopo Mondi <\n> > > jacopo.mondi@ideasonboard.com>\n> > > > wrote:\n> > > >\n> > > > > Hi Harvey\n> > > > >\n> > > > > On Wed, Sep 25, 2024 at 03:09:38PM GMT, Cheng-Hao Yang wrote:\n> > > > > > Hi Jacopo,\n> > > > > >\n> > > > > > Thank you for the patch.\n> > > > > >\n> > > > > > On Wed, Sep 25, 2024 at 2:36 PM Umang Jain <\n> > > umang.jain@ideasonboard.com>\n> > > > > wrote:\n> > > > > > >\n> > > > > > > Hi Jacopo\n> > > > > > >\n> > > > > > > Thank you for the patch\n> > > > > > >\n> > > > > > > On 24/09/24 6:15 pm, Jacopo Mondi wrote:\n> > > > > > > > The libcamera::Rectangle class should allow defining rectangles\n> > > > > > > > regardless of the reference system where an instance is used in.\n> > > > > > > >\n> > > > > > > > However the class documentation assumes the reference system\n> > > origin\n> > > > > > > > point to be in the visual top-left side and that rectangles are\n> > > > > > > > constructed by specifying the top-left corner position and sizes.\n> > > > > > > >\n> > > > > > > > However this is ambiguous when using a different reference\n> > > system as,\n> > > > > > > > in example, constructing a rectangle (x, y, w, h) in the\n> > > following\n> > > > > > > > scenario, with the origin corner in the top-left position, would\n> > > > > require\n> > > > > > > > a negative decrement along the y-axis.\n> > > > > > > >\n> > > > > > > >           ^\n> > > > > > > >           |\n> > > > > > > >          y|      o------------------\n> > > > > > > >           |      |                 | h\n> > > > > > > >           |      |                 |\n> > > > > > > >           |      -------------------\n> > > > > > > >           |               w\n> > > > > > > >            ------------------------------->\n> > > > > > > >           (0,0)  x\n> > > > > > > >\n> > > > > > > > To remove ambiguities, drop references to the visual top-left\n> > > corner\n> > > > > and\n> > > > > > > > define the rectangle's origin corner as the corner closer to the\n> > > > > > > > reference system origin point, and specify the horizontal and\n> > > > > vertical\n> > > > > > > > dimensions always increment along their respective axis, as in\n> > > the\n> > > > > > > > following example.\n> > > > > > > >\n> > > > > > > >           ^\n> > > > > > > >           |\n> > > > > > > >           |      -------------------\n> > > > > > > >           |      ^                 | h\n> > > > > > > >           |      |                 |\n> > > > > > > >          y|      o---->-------------\n> > > > > > > >           |               w\n> > > > > > > >            ------------------------------->\n> > > > > > > >           (0,0)  x\n> > > > > > > >\n> > > > > > > >           (0,0)  x\n> > > > > > > >             ------------------------------>\n> > > > > > > >            |              w\n> > > > > > > >           y|     o---->-------------\n> > > > > > > >            |     |                 | h\n> > > > > > > >            |     v                 |\n> > > > > > > >            |     -------------------\n> > > > > > > >            |\n> > > > > > > >            V\n> > > > > > > >\n> > > > > > > > Also rename for consistency the Rectangle::topLeft() function to\n> > > > > > > > Rectangle::origin() and update its in-tree users.\n> > > > > > > >\n> > > > > > > > Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n> > > > > > > > ---\n> > > > > > > >   include/libcamera/geometry.h                  |  2 +-\n> > > > > > > >   src/ipa/ipu3/algorithms/af.cpp                |  2 +-\n> > > > > > > >   src/libcamera/geometry.cpp                    | 85\n> > > > > ++++++++++++++-----\n> > > > > > > >   .../pipeline/rpi/common/pipeline_base.cpp     |  4 +-\n> > > > > > > >   src/py/libcamera/py_geometry.cpp              |  2 +-\n> > > > > > > >   test/geometry.cpp                             |  8 +-\n> > > > > > > >   6 files changed, 75 insertions(+), 28 deletions(-)\n> > > > > > > >\n> > > > > > > > diff --git a/include/libcamera/geometry.h\n> > > > > b/include/libcamera/geometry.h\n> > > > > > > > index 3e6f0f5d7fab..07cb0a7866fe 100644\n> > > > > > > > --- a/include/libcamera/geometry.h\n> > > > > > > > +++ b/include/libcamera/geometry.h\n> > > > > > > > @@ -277,7 +277,7 @@ public:\n> > > > > > > >               return { width, height };\n> > > > > > > >       }\n> > > > > > > >\n> > > > > > > > -     Point topLeft() const\n> > > > > > > > +     Point origin() const\n> > > > > > > >       {\n> > > > > > > >               return { x, y };\n> > > > > > > >       }\n> > > > > > > > diff --git a/src/ipa/ipu3/algorithms/af.cpp\n> > > > > b/src/ipa/ipu3/algorithms/af.cpp\n> > > > > > > > index cf68fb59c49b..1b707e9dd9ab 100644\n> > > > > > > > --- a/src/ipa/ipu3/algorithms/af.cpp\n> > > > > > > > +++ b/src/ipa/ipu3/algorithms/af.cpp\n> > > > > > > > @@ -155,7 +155,7 @@ int Af::configure(IPAContext &context, const\n> > > > > IPAConfigInfo &configInfo)\n> > > > > > > >        * - Return the AF ROI as metadata in the Request\n> > > > > > > >        */\n> > > > > > > >       Rectangle roi = gridSize.centeredTo(bds.center());\n> > > > > > > > -     Point start = roi.topLeft();\n> > > > > > > > +     Point start = roi.origin();\n> > > > > > > >\n> > > > > > > >       /* x_start and y_start should be even */\n> > > > > > > >       grid.x_start = utils::alignDown(start.x, 2);\n> > > > > > > > diff --git a/src/libcamera/geometry.cpp\n> > > b/src/libcamera/geometry.cpp\n> > > > > > > > index 000151364c7f..45ba81a99920 100644\n> > > > > > > > --- a/src/libcamera/geometry.cpp\n> > > > > > > > +++ b/src/libcamera/geometry.cpp\n> > > > > > > > @@ -593,11 +593,39 @@ std::ostream &operator<<(std::ostream &out,\n> > > > > const SizeRange &sr)\n> > > > > > > >    * \\brief Describe a rectangle's position and dimensions\n> > > > > > > >    *\n> > > > > > > >    * Rectangles are used to identify an area of an image. They\n> > > are\n> > > > > specified by\n> > > > > > > > - * the coordinates of top-left corner and their horizontal and\n> > > > > vertical size.\n> > > > > > > > + * the coordinates of the corner closer to the reference\n> > > system's\n> > > > > origin point\n> > > > > > > > + * and by horizontal and vertical increments from there.\n> > > > > > > >    *\n> > > > > > > > - * The measure unit of the rectangle coordinates and size, as\n> > > well\n> > > > > as the\n> > > > > > > > - * reference point from which the Rectangle::x and Rectangle::y\n> > > > > displacements\n> > > > > > > > - * refers to, are defined by the context were rectangle is used.\n> > > > > > > > + * The corner closer to the reference system's origin point is\n> > > the\n> > > > > rectangle's\n> > > > > > > > + * origin corner.\n> > > > > > > > + *\n> > > > > > > > + * \\verbatim\n> > > > > > > > +\n> > > > > > > > +  o = origin corner\n> > > > > > > > +\n> > > > > > > > +         ^\n> > > > > > > > +         |\n> > > > > > > > +         |      -------------------\n> > > > > > > > +         |      ^                 |\n> > > > > > > > +         |      |                 |\n> > > > > > > > +         |      o---->-------------\n> > > > > > > > +         |\n> > > > > > > > +          ------------------------------->\n> > > > > > > > +         (0,0)\n> > > > > > > > +\n> > > > > > > > +         (0,0)\n> > > > > > > > +           ------------------------------->\n> > > > > > > > +          |\n> > > > > > > > +          |      o---->-------------\n> > > > > > > > +          |      |                 |\n> > > > > > > > +          |      v                 |\n> > > > > > > > +          |      -------------------\n> > > > > > > > +          |\n> > > > > > > > +          V\n> > > > > > > > +   \\endverbatim\n> > > > > > > > + *\n> > > > > > > > + * The measure unit of the rectangle coordinates and size are\n> > > > > defined by the\n> > > > > > > > + * context were the rectangle is used.\n> > > > > > > >    */\n> > > > > > > >\n> > > > > > > >   /**\n> > > > > > > > @@ -608,35 +636,50 @@ std::ostream &operator<<(std::ostream &out,\n> > > > > const SizeRange &sr)\n> > > > > > > >   /**\n> > > > > > > >    * \\fn Rectangle::Rectangle(int x, int y, const Size &size)\n> > > > > > > >    * \\brief Construct a Rectangle with the given position and\n> > > size\n> > > > > > > > - * \\param[in] x The horizontal coordinate of the top-left corner\n> > > > > > > > - * \\param[in] y The vertical coordinate of the top-left corner\n> > > > > > > > + * \\param[in] x The horizontal coordinate of the origin corner\n> > > > > > > > + * \\param[in] y The vertical coordinate of the origin corner\n> > > > > > > >    * \\param[in] size The size\n> > > > > > > > + *\n> > > > > > > > + * The rectangle's origin corner is the corner closer to the\n> > > > > reference system\n> > > > > > > > + * origin point (0, 0).\n> > > > > >\n> > > > > > I think we should stick to the previous description:\n> > > > > > `\"origin\" point defined as the point with the lower x and\n> > > > > > lower y of the rectangle`, as `x` and `y` are signed integers.\n> > > > > >\n> > > > > > If we only support coordinates that are positive or 0, which\n> > > > > > I'm not sure if it's the case, how about making the type to be\n> > > > > > `unsigned int`?\n> > > > > >\n> > > > >\n> > > > > To be honest I would rather make width and heigh signed to allow\n> > > > > constructing (x, y, -w, -h)\n> > > > >\n> > > > >\n> > > > >\n> > > > >\n> > > > >                -------------------\n> > > > >                |                 ^\n> > > > >                |            ------------->\n> > > > >                |           |     |\n> > > > >                ------<-----|-----o\n> > > > >                            |\n> > > > >                            |\n> > > > >                            V\n> > > > >\n> > > > > Not sure if it's useful or not though\n> > > > >\n> > > >\n> > > > Hmm... I find it pretty weird. What if all four corners have all negative\n> > > > coordinates?\n> > > >\n> > > >\n> > >\n> > > Don't know, maybe if the reference system where the rectangle is used\n> > > into has 4 planes and so an all-negative rectangle makes sense.\n> > >\n> > > My point is that we should allow users of this class to express\n> > > Rectangle in any context they plan to use them. Not sure if I'm going\n> > > overboard here or it makes sense.\n> > >\n> >\n> > Yeah I agree, while doesn't that mean the description doesn't fit all\n> > cases, like the corner closer to the reference system origin point of a\n> > rectangle that has all negative coordinates is actually the \"bottom-right\"\n>\n> This patch aims to remove all references to \"top-left\" or in general\n> to any visual reference exactly for that purpose. Or have I forgot any\n> ?\n\nIn this c'tor `\\fn Rectangle::Rectangle(int x, int y, const Size &size)`,\nthe description of `x` and `y` are updated to \"coordinates of the origin\ncorner\", where the origin corner is \"the corner closer to the reference\nsystem origin point (0, 0).\"\n\nAs currently libcamera::Size takes only non-negative width and height,\ntake rectangle [(-3, -3), (-3, -1), (-1, -3), (-1, -1)] as the example, you\ncan find that the only valid way to construct this rectangle as\nlibcamera::Rectangle is `{x = -3, y = -3, size = {2, 2}}`. However, this\ndoesn't fit with your updated description, as the corner closer to the\nreference system origin point (0, 0) is actually (-1, -1), instead of\n(-3, -3).\n\n>\n> > corner, and currently libcamera::Size only allows non-negative width and\n> > height [1].\n>\n> True, Size uses unsigned int. I don't think it's a big deal and I'm\n> not proposing to introduce a new constructor with signed width and\n> height now, but my point is that if the need arises we can now do\n> that.\n>\n> >\n> > [1]:\n> > https://git.libcamera.org/libcamera/libcamera.git/tree/include/libcamera/geometry.h#n65\n> >\n> >\n> > > >\n> > > >\n> > > > >\n> > > > > > BR,\n> > > > > > Harvey\n> > > > > >\n> > > > > >\n> > > > > > > >    */\n> > > > > > > >\n> > > > > > > >   /**\n> > > > > > > >    * \\fn Rectangle::Rectangle(int x, int y, unsigned int width,\n> > > > > unsigned int height)\n> > > > > > > >    * \\brief Construct a Rectangle with the given position and\n> > > size\n> > > > > > > > - * \\param[in] x The horizontal coordinate of the top-left corner\n> > > > > > > > - * \\param[in] y The vertical coordinate of the top-left corner\n> > > > > > > > + * \\param[in] x The horizontal coordinate of the origin corner\n> > > > > > > > + * \\param[in] y The vertical coordinate of the origin corner\n> > > > > > > >    * \\param[in] width The width\n> > > > > > > >    * \\param[in] height The height\n> > > > > > > > + *\n> > > > > > > > + * The rectangle's origin corner is the corner closer to the\n> > > > > reference system\n> > > > > > > > + * origin point (0, 0).\n> > > > > > > >    */\n> > > > > > > >\n> > > > > > > >   /**\n> > > > > > > >    * \\fn Rectangle::Rectangle(const Size &size)\n> > > > > > > > - * \\brief Construct a Rectangle of \\a size with its top left\n> > > corner\n> > > > > located\n> > > > > > > > + * \\brief Construct a Rectangle of \\a size with its origin\n> > > corner\n> > > > > located\n> > > > > > > >    * at (0,0)\n> > > > > > > >    * \\param[in] size The desired Rectangle size\n> > > > > > > > + *\n> > > > > > > > + * The rectangle's origin corner is the corner closer to the\n> > > > > reference system\n> > > > > > > > + * origin point (0, 0).\n> > > > > > > >    */\n> > > > > > > >\n> > > > > > > >   /**\n> > > > > > > >    * \\var Rectangle::x\n> > > > > > > > - * \\brief The horizontal coordinate of the rectangle's top-left\n> > > > > corner\n> > > > > > > > + * \\brief The horizontal coordinate of the rectangle's origin\n> > > corner\n> > > > > > > > + *\n> > > > > > > > + * The rectangle's origin corner is the corner closer to the\n> > > > > reference system\n> > > > > > > > + * origin point (0, 0).\n> > > > > > > >    */\n> > > > > > > >\n> > > > > > > >   /**\n> > > > > > > >    * \\var Rectangle::y\n> > > > > > > > - * \\brief The vertical coordinate of the rectangle's top-left\n> > > corner\n> > > > > > > > + * \\brief The vertical coordinate of the rectangle's origin\n> > > corner\n> > > > > > > > + *\n> > > > > > > > + * The rectangle's origin corner is the corner closer to the\n> > > > > reference system\n> > > > > > > > + * origin point (0, 0).\n> > > > > > > >    */\n> > > > > > > >\n> > > > > > > >   /**\n> > > > > > > > @@ -683,9 +726,13 @@ Point Rectangle::center() const\n> > > > > > > >    */\n> > > > > > > >\n> > > > > > > >   /**\n> > > > > > > > - * \\fn Point Rectangle::topLeft() const\n> > > > > > > > - * \\brief Retrieve the coordinates of the top left corner of\n> > > this\n> > > > > Rectangle\n> > > > > > > > - * \\return The Rectangle's top left corner\n> > > > > > > > + * \\fn Point Rectangle::origin() const\n> > > > > > > > + * \\brief Retrieve the coordinates of the origin corner of this\n> > > > > Rectangle\n> > > > > > > > + *\n> > > > > > > > + * The rectangle's origin corner is the corner closer to the\n> > > > > reference system\n> > > > > > > > + * origin point (0, 0).\n> > > > > > > > + *\n> > > > > > > > + * \\return The Rectangle's origin corner\n> > > > > > >\n> > > > > > > I think you can drop \"corner\" from \"origin corner\"\n> > > > > > >\n> > > > > > > Probably throughout the patch:\n> > > > > > >      s/origin corner/origin/\n> > > > > > >\n> > > > > > > Otherwise, LGTM\n> > > > > > >\n> > > > > > > Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>\n> > > > > > > >    */\n> > > > > > > >\n> > > > > > > >   /**\n> > > > > > > > @@ -740,15 +787,15 @@ Rectangle &Rectangle::translateBy(const\n> > > Point\n> > > > > &point)\n> > > > > > > >    */\n> > > > > > > >   Rectangle Rectangle::boundedTo(const Rectangle &bound) const\n> > > > > > > >   {\n> > > > > > > > -     int topLeftX = std::max(x, bound.x);\n> > > > > > > > -     int topLeftY = std::max(y, bound.y);\n> > > > > > > > +     int originX = std::max(x, bound.x);\n> > > > > > > > +     int originY = std::max(y, bound.y);\n> > > > > > > >       int bottomRightX = std::min<int>(x + width, bound.x +\n> > > > > bound.width);\n> > > > > > > >       int bottomRightY = std::min<int>(y + height, bound.y +\n> > > > > bound.height);\n> > > > > > > >\n> > > > > > > > -     unsigned int newWidth = std::max(bottomRightX - topLeftX,\n> > > 0);\n> > > > > > > > -     unsigned int newHeight = std::max(bottomRightY - topLeftY,\n> > > 0);\n> > > > > > > > +     unsigned int newWidth = std::max(bottomRightX - originX,\n> > > 0);\n> > > > > > > > +     unsigned int newHeight = std::max(bottomRightY - originY,\n> > > 0);\n> > > > > > > >\n> > > > > > > > -     return { topLeftX, topLeftY, newWidth, newHeight };\n> > > > > > > > +     return { originX, originY, newWidth, newHeight };\n> > > > > > > >   }\n> > > > > > > >\n> > > > > > > >   /**\n> > > > > > > > diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n> > > > > b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n> > > > > > > > index 3041fd1ed9fd..8d2440026689 100644\n> > > > > > > > --- a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n> > > > > > > > +++ b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n> > > > > > > > @@ -1289,7 +1289,7 @@ Rectangle CameraData::scaleIspCrop(const\n> > > > > Rectangle &ispCrop) const\n> > > > > > > >        */\n> > > > > > > >       Rectangle nativeCrop =\n> > > > > ispCrop.scaledBy(sensorInfo_.analogCrop.size(),\n> > > > > > > >\n> > > > >  sensorInfo_.outputSize);\n> > > > > > > > -     nativeCrop.translateBy(sensorInfo_.analogCrop.topLeft());\n> > > > > > > > +     nativeCrop.translateBy(sensorInfo_.analogCrop.origin());\n> > > > > > > >       return nativeCrop;\n> > > > > > > >   }\n> > > > > > > >\n> > > > > > > > @@ -1303,7 +1303,7 @@ void CameraData::applyScalerCrop(const\n> > > > > ControlList &controls)\n> > > > > > > >                       nativeCrop = { 0, 0, 1, 1 };\n> > > > > > > >\n> > > > > > > >               /* Create a version of the crop scaled to ISP\n> > > (camera\n> > > > > mode) pixels. */\n> > > > > > > > -             Rectangle ispCrop =\n> > > > > nativeCrop.translatedBy(-sensorInfo_.analogCrop.topLeft());\n> > > > > > > > +             Rectangle ispCrop =\n> > > > > nativeCrop.translatedBy(-sensorInfo_.analogCrop.origin());\n> > > > > > > >               ispCrop.scaleBy(sensorInfo_.outputSize,\n> > > > > sensorInfo_.analogCrop.size());\n> > > > > > > >\n> > > > > > > >               /*\n> > > > > > > > diff --git a/src/py/libcamera/py_geometry.cpp\n> > > > > b/src/py/libcamera/py_geometry.cpp\n> > > > > > > > index c7e303609427..8dee365b25dd 100644\n> > > > > > > > --- a/src/py/libcamera/py_geometry.cpp\n> > > > > > > > +++ b/src/py/libcamera/py_geometry.cpp\n> > > > > > > > @@ -105,7 +105,7 @@ void init_py_geometry(py::module &m)\n> > > > > > > >               .def_property_readonly(\"is_null\",\n> > > &Rectangle::isNull)\n> > > > > > > >               .def_property_readonly(\"center\",\n> > > &Rectangle::center)\n> > > > > > > >               .def_property_readonly(\"size\", &Rectangle::size)\n> > > > > > > > -             .def_property_readonly(\"topLeft\",\n> > > &Rectangle::topLeft)\n> > > > > > > > +             .def_property_readonly(\"origin\",\n> > > &Rectangle::origin)\n> > > > > > > >               .def(\"scale_by\", &Rectangle::scaleBy)\n> > > > > > > >               .def(\"translate_by\", &Rectangle::translateBy)\n> > > > > > > >               .def(\"bounded_to\", &Rectangle::boundedTo)\n> > > > > > > > diff --git a/test/geometry.cpp b/test/geometry.cpp\n> > > > > > > > index 64169206ad16..a4ee6f6e167a 100644\n> > > > > > > > --- a/test/geometry.cpp\n> > > > > > > > +++ b/test/geometry.cpp\n> > > > > > > > @@ -363,16 +363,16 @@ protected:\n> > > > > > > >                       return TestFail;\n> > > > > > > >               }\n> > > > > > > >\n> > > > > > > > -             /* Rectangle::size(), Rectangle::topLeft() and\n> > > > > Rectangle::center() tests */\n> > > > > > > > +             /* Rectangle::size(), Rectangle::origin() and\n> > > > > Rectangle::center() tests */\n> > > > > > > >               if (Rectangle(-1, -2, 3, 4).size() != Size(3, 4) ||\n> > > > > > > >                   Rectangle(0, 0, 100000, 200000).size() !=\n> > > > > Size(100000, 200000)) {\n> > > > > > > >                       cout << \"Rectangle::size() test failed\" <<\n> > > > > endl;\n> > > > > > > >                       return TestFail;\n> > > > > > > >               }\n> > > > > > > >\n> > > > > > > > -             if (Rectangle(1, 2, 3, 4).topLeft() != Point(1, 2)\n> > > ||\n> > > > > > > > -                 Rectangle(-1, -2, 3, 4).topLeft() != Point(-1,\n> > > > > -2)) {\n> > > > > > > > -                     cout << \"Rectangle::topLeft() test failed\"\n> > > <<\n> > > > > endl;\n> > > > > > > > +             if (Rectangle(1, 2, 3, 4).origin() != Point(1, 2)\n> > > ||\n> > > > > > > > +                 Rectangle(-1, -2, 3, 4).origin() != Point(-1,\n> > > -2))\n> > > > > {\n> > > > > > > > +                     cout << \"Rectangle::origin() test failed\"\n> > > <<\n> > > > > endl;\n> > > > > > > >                       return TestFail;\n> > > > > > > >               }\n> > > > > > > >\n> > > > > > > > --\n> > > > > > > > 2.46.1\n> > > > > > > >\n> > > > > > >\n> > > > > >\n> > > > > >\n> > > > > > --\n> > > > > > BR,\n> > > > > > Harvey Yang\n> > > > >\n> > >","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 AC69EC0F1B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 26 Sep 2024 14:04:36 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id B1C6563512;\n\tThu, 26 Sep 2024 16:04:35 +0200 (CEST)","from mail-lf1-x12d.google.com (mail-lf1-x12d.google.com\n\t[IPv6:2a00:1450:4864:20::12d])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 1F1FD63502\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 26 Sep 2024 16:04:34 +0200 (CEST)","by mail-lf1-x12d.google.com with SMTP id\n\t2adb3069b0e04-53690eb134bso9218e87.0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 26 Sep 2024 07:04:34 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key;\n\tunprotected) header.d=google.com header.i=@google.com\n\theader.b=\"c0KpdB7H\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=google.com; s=20230601; t=1727359473; x=1727964273;\n\tdarn=lists.libcamera.org; \n\th=content-transfer-encoding:cc:to:subject:message-id:date:from\n\t:in-reply-to:references:mime-version:from:to:cc:subject:date\n\t:message-id:reply-to;\n\tbh=MZk8tQ9PoKxqTBT3jso0xoIIqjQTujU4rYyaX3lHWYQ=;\n\tb=c0KpdB7HtvqG9lwds9Icq7tKC7VoJazP9VNfDeTustDtgiWgeUh7QYZJXOuQ0OGEak\n\t+pXFOkJs7Z2f9O7nIuT4Rih47injaLMnMlSv0V5eVNcaK2E/qb5xQY4ZccydR44mt4zK\n\tzsdnErXCth1isMfcWFn1FfmsOrOuV2XCBquylP+hJcPAmOFQ6KfczvFpgC7/SPDlDLaQ\n\txQKz7HnCRkPR1U+HvGHISiiAcuUBLBn0JmdEYDYq5/YWRaz49X0VuAXSH+Ljh+QYgPkM\n\tGWH1KYb1I7wQCxzSq2z+Gh5GQXjFkO5e6QsH89n/fedWFtrzneo4u4y+3rkHzA4wdTDt\n\tlR9g==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1727359473; x=1727964273;\n\th=content-transfer-encoding:cc:to:subject:message-id:date:from\n\t:in-reply-to:references:mime-version:x-gm-message-state:from:to:cc\n\t:subject:date:message-id:reply-to;\n\tbh=MZk8tQ9PoKxqTBT3jso0xoIIqjQTujU4rYyaX3lHWYQ=;\n\tb=IPpjEHTIb4FLVCPn/7ueWT/oCy4qRLoVHSIk4Lk00Fo7x1BlENuMVQ+qvpDT4U0T5s\n\t6pCik7xlmfTfXM2BgAVLdNT2hKbAiUjdUkedMXDZwU9T4DEB4mpit53yfHEOoXgySO6N\n\tWJhaZ7/YRcB/2DUm6GScxZ+ud0P6tQxTEo/edSYCwFg5YoQpsMS9fFx6PnFCKvRDkkxd\n\toKTInZ0Vtxr7QcuIvAxS2+lMgoL6qLqyktSQh0BA0716zglsP0cgJtj1D2+PqnNcZ9fJ\n\tMKWBVtTAGYOqK4iHQhlWDLLwKy8L52/wdmgFYtL+Czt+EKX+GNwLdDL5ZKvCjfCQGw4S\n\txoWQ==","X-Forwarded-Encrypted":"i=1;\n\tAJvYcCUh6eafApYToPxUSczBngPnHINv1RFSLRnloJ9DyxJgwgsiGVdfSABJkt8wEv5mgM4YmUUAWQLDUC+1T45yRT0=@lists.libcamera.org","X-Gm-Message-State":"AOJu0Yw3KCB652tEd1++4s/SZrX9SRM1bjRwsqQfO8wZ5MvyDvoRXFDS\n\tcjDtMpfs4xN+kT89CUbU8olQvvhawZiBBtm4QHc/8Qb9dqOPuQmeMJjiCSvaL2jQCd0yUJ2tcu+\n\tU3Q873ZpUzrDTHtnlXR3ZKtyXxHMv9X2k3tBk","X-Google-Smtp-Source":"AGHT+IGZBFEBPL3xXAYYqnSVKx+E2dC1RmyHv29S19J1My6QW9th9IMBP9p02MXtOIvkV0pGjtLkCNwK2TYgUOFXh0U=","X-Received":"by 2002:a05:6512:3baa:b0:52c:dd94:73f3 with SMTP id\n\t2adb3069b0e04-53898617862mr220327e87.3.1727359472706; Thu, 26 Sep 2024\n\t07:04:32 -0700 (PDT)","MIME-Version":"1.0","References":"<20240924124525.95189-1-jacopo.mondi@ideasonboard.com>\n\t<d975583c-7f5d-4f5b-8e99-5cdc61396667@ideasonboard.com>\n\t<CAC=wSGUwXZDvM68ZfhqPvYKhAB0bkem=zJhFJ-Fjafc9OYhDqA@mail.gmail.com>\n\t<uzptnxdipytxx4nwqusnr62asaiwrdawylf2f3vzbmkc53onhc@nkeomtxtfw5g>\n\t<CAC=wSGWEZU7_=nEFTp+g_g74L7kcs65wK3oOeS8xwBqzMHa5wQ@mail.gmail.com>\n\t<zsszrdewqlrlovncquphk43ajxyksfoijoiorglvwem4kb2u6q@my2gscqpdzd3>\n\t<CAC=wSGXj==p2GZMidtwb9pUhmnuRrdqbGhQUF14HSNfTzgz_Cw@mail.gmail.com>\n\t<62yvkiqioilupdcm7ryjtrz273iamzojfi2pgxndmjwoyyaitb@iq46e47ke2vg>","In-Reply-To":"<62yvkiqioilupdcm7ryjtrz273iamzojfi2pgxndmjwoyyaitb@iq46e47ke2vg>","From":"Cheng-Hao Yang <chenghaoyang@google.com>","Date":"Thu, 26 Sep 2024 22:03:55 +0800","Message-ID":"<CAC=wSGXgYv2YyZqwgRANhmVzPtLTkTHP4=R-_Sz+NE7wNzPJXw@mail.gmail.com>","Subject":"Re: [PATCH] libcamera: geometry: Rename Rectangle's top-left corner","To":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>","Cc":"Umang Jain <umang.jain@ideasonboard.com>, \n\tlibcamera devel <libcamera-devel@lists.libcamera.org>","Content-Type":"text/plain; charset=\"UTF-8\"","Content-Transfer-Encoding":"quoted-printable","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>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":31409,"web_url":"https://patchwork.libcamera.org/comment/31409/","msgid":"<6cnkhto53ixz7hafosgqebixvfdpwftc24ach46wsvv6qpjmkv@h7e25hene6yc>","date":"2024-09-26T14:35:40","subject":"Re: [PATCH] libcamera: geometry: Rename Rectangle's top-left corner","submitter":{"id":143,"url":"https://patchwork.libcamera.org/api/people/143/","name":"Jacopo Mondi","email":"jacopo.mondi@ideasonboard.com"},"content":"Hi Harvey\n\nOn Thu, Sep 26, 2024 at 10:03:55PM GMT, Cheng-Hao Yang wrote:\n> Hi Jacopo,\n>\n> On Thu, Sep 26, 2024 at 5:36 PM Jacopo Mondi\n> <jacopo.mondi@ideasonboard.com> wrote:\n> >\n> > Hi Harvey\n> >\n> > On Thu, Sep 26, 2024 at 05:28:13PM GMT, Cheng-Hao Yang wrote:\n> > > Hi Jacopo,\n> > >\n> > >\n> > >\n> > > On Thu, Sep 26, 2024, 4:38 PM Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n> > > wrote:\n> > >\n> > > > Hi Harvey\n> > > >\n> > > > On Thu, Sep 26, 2024 at 04:29:50PM GMT, Cheng-Hao Yang wrote:\n> > > > > Hi Jacopo,\n> > > > >\n> > > > > On Thu, Sep 26, 2024, 4:03 PM Jacopo Mondi <\n> > > > jacopo.mondi@ideasonboard.com>\n> > > > > wrote:\n> > > > >\n> > > > > > Hi Harvey\n> > > > > >\n> > > > > > On Wed, Sep 25, 2024 at 03:09:38PM GMT, Cheng-Hao Yang wrote:\n> > > > > > > Hi Jacopo,\n> > > > > > >\n> > > > > > > Thank you for the patch.\n> > > > > > >\n> > > > > > > On Wed, Sep 25, 2024 at 2:36 PM Umang Jain <\n> > > > umang.jain@ideasonboard.com>\n> > > > > > wrote:\n> > > > > > > >\n> > > > > > > > Hi Jacopo\n> > > > > > > >\n> > > > > > > > Thank you for the patch\n> > > > > > > >\n> > > > > > > > On 24/09/24 6:15 pm, Jacopo Mondi wrote:\n> > > > > > > > > The libcamera::Rectangle class should allow defining rectangles\n> > > > > > > > > regardless of the reference system where an instance is used in.\n> > > > > > > > >\n> > > > > > > > > However the class documentation assumes the reference system\n> > > > origin\n> > > > > > > > > point to be in the visual top-left side and that rectangles are\n> > > > > > > > > constructed by specifying the top-left corner position and sizes.\n> > > > > > > > >\n> > > > > > > > > However this is ambiguous when using a different reference\n> > > > system as,\n> > > > > > > > > in example, constructing a rectangle (x, y, w, h) in the\n> > > > following\n> > > > > > > > > scenario, with the origin corner in the top-left position, would\n> > > > > > require\n> > > > > > > > > a negative decrement along the y-axis.\n> > > > > > > > >\n> > > > > > > > >           ^\n> > > > > > > > >           |\n> > > > > > > > >          y|      o------------------\n> > > > > > > > >           |      |                 | h\n> > > > > > > > >           |      |                 |\n> > > > > > > > >           |      -------------------\n> > > > > > > > >           |               w\n> > > > > > > > >            ------------------------------->\n> > > > > > > > >           (0,0)  x\n> > > > > > > > >\n> > > > > > > > > To remove ambiguities, drop references to the visual top-left\n> > > > corner\n> > > > > > and\n> > > > > > > > > define the rectangle's origin corner as the corner closer to the\n> > > > > > > > > reference system origin point, and specify the horizontal and\n> > > > > > vertical\n> > > > > > > > > dimensions always increment along their respective axis, as in\n> > > > the\n> > > > > > > > > following example.\n> > > > > > > > >\n> > > > > > > > >           ^\n> > > > > > > > >           |\n> > > > > > > > >           |      -------------------\n> > > > > > > > >           |      ^                 | h\n> > > > > > > > >           |      |                 |\n> > > > > > > > >          y|      o---->-------------\n> > > > > > > > >           |               w\n> > > > > > > > >            ------------------------------->\n> > > > > > > > >           (0,0)  x\n> > > > > > > > >\n> > > > > > > > >           (0,0)  x\n> > > > > > > > >             ------------------------------>\n> > > > > > > > >            |              w\n> > > > > > > > >           y|     o---->-------------\n> > > > > > > > >            |     |                 | h\n> > > > > > > > >            |     v                 |\n> > > > > > > > >            |     -------------------\n> > > > > > > > >            |\n> > > > > > > > >            V\n> > > > > > > > >\n> > > > > > > > > Also rename for consistency the Rectangle::topLeft() function to\n> > > > > > > > > Rectangle::origin() and update its in-tree users.\n> > > > > > > > >\n> > > > > > > > > Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n> > > > > > > > > ---\n> > > > > > > > >   include/libcamera/geometry.h                  |  2 +-\n> > > > > > > > >   src/ipa/ipu3/algorithms/af.cpp                |  2 +-\n> > > > > > > > >   src/libcamera/geometry.cpp                    | 85\n> > > > > > ++++++++++++++-----\n> > > > > > > > >   .../pipeline/rpi/common/pipeline_base.cpp     |  4 +-\n> > > > > > > > >   src/py/libcamera/py_geometry.cpp              |  2 +-\n> > > > > > > > >   test/geometry.cpp                             |  8 +-\n> > > > > > > > >   6 files changed, 75 insertions(+), 28 deletions(-)\n> > > > > > > > >\n> > > > > > > > > diff --git a/include/libcamera/geometry.h\n> > > > > > b/include/libcamera/geometry.h\n> > > > > > > > > index 3e6f0f5d7fab..07cb0a7866fe 100644\n> > > > > > > > > --- a/include/libcamera/geometry.h\n> > > > > > > > > +++ b/include/libcamera/geometry.h\n> > > > > > > > > @@ -277,7 +277,7 @@ public:\n> > > > > > > > >               return { width, height };\n> > > > > > > > >       }\n> > > > > > > > >\n> > > > > > > > > -     Point topLeft() const\n> > > > > > > > > +     Point origin() const\n> > > > > > > > >       {\n> > > > > > > > >               return { x, y };\n> > > > > > > > >       }\n> > > > > > > > > diff --git a/src/ipa/ipu3/algorithms/af.cpp\n> > > > > > b/src/ipa/ipu3/algorithms/af.cpp\n> > > > > > > > > index cf68fb59c49b..1b707e9dd9ab 100644\n> > > > > > > > > --- a/src/ipa/ipu3/algorithms/af.cpp\n> > > > > > > > > +++ b/src/ipa/ipu3/algorithms/af.cpp\n> > > > > > > > > @@ -155,7 +155,7 @@ int Af::configure(IPAContext &context, const\n> > > > > > IPAConfigInfo &configInfo)\n> > > > > > > > >        * - Return the AF ROI as metadata in the Request\n> > > > > > > > >        */\n> > > > > > > > >       Rectangle roi = gridSize.centeredTo(bds.center());\n> > > > > > > > > -     Point start = roi.topLeft();\n> > > > > > > > > +     Point start = roi.origin();\n> > > > > > > > >\n> > > > > > > > >       /* x_start and y_start should be even */\n> > > > > > > > >       grid.x_start = utils::alignDown(start.x, 2);\n> > > > > > > > > diff --git a/src/libcamera/geometry.cpp\n> > > > b/src/libcamera/geometry.cpp\n> > > > > > > > > index 000151364c7f..45ba81a99920 100644\n> > > > > > > > > --- a/src/libcamera/geometry.cpp\n> > > > > > > > > +++ b/src/libcamera/geometry.cpp\n> > > > > > > > > @@ -593,11 +593,39 @@ std::ostream &operator<<(std::ostream &out,\n> > > > > > const SizeRange &sr)\n> > > > > > > > >    * \\brief Describe a rectangle's position and dimensions\n> > > > > > > > >    *\n> > > > > > > > >    * Rectangles are used to identify an area of an image. They\n> > > > are\n> > > > > > specified by\n> > > > > > > > > - * the coordinates of top-left corner and their horizontal and\n> > > > > > vertical size.\n> > > > > > > > > + * the coordinates of the corner closer to the reference\n> > > > system's\n> > > > > > origin point\n> > > > > > > > > + * and by horizontal and vertical increments from there.\n> > > > > > > > >    *\n> > > > > > > > > - * The measure unit of the rectangle coordinates and size, as\n> > > > well\n> > > > > > as the\n> > > > > > > > > - * reference point from which the Rectangle::x and Rectangle::y\n> > > > > > displacements\n> > > > > > > > > - * refers to, are defined by the context were rectangle is used.\n> > > > > > > > > + * The corner closer to the reference system's origin point is\n> > > > the\n> > > > > > rectangle's\n> > > > > > > > > + * origin corner.\n> > > > > > > > > + *\n> > > > > > > > > + * \\verbatim\n> > > > > > > > > +\n> > > > > > > > > +  o = origin corner\n> > > > > > > > > +\n> > > > > > > > > +         ^\n> > > > > > > > > +         |\n> > > > > > > > > +         |      -------------------\n> > > > > > > > > +         |      ^                 |\n> > > > > > > > > +         |      |                 |\n> > > > > > > > > +         |      o---->-------------\n> > > > > > > > > +         |\n> > > > > > > > > +          ------------------------------->\n> > > > > > > > > +         (0,0)\n> > > > > > > > > +\n> > > > > > > > > +         (0,0)\n> > > > > > > > > +           ------------------------------->\n> > > > > > > > > +          |\n> > > > > > > > > +          |      o---->-------------\n> > > > > > > > > +          |      |                 |\n> > > > > > > > > +          |      v                 |\n> > > > > > > > > +          |      -------------------\n> > > > > > > > > +          |\n> > > > > > > > > +          V\n> > > > > > > > > +   \\endverbatim\n> > > > > > > > > + *\n> > > > > > > > > + * The measure unit of the rectangle coordinates and size are\n> > > > > > defined by the\n> > > > > > > > > + * context were the rectangle is used.\n> > > > > > > > >    */\n> > > > > > > > >\n> > > > > > > > >   /**\n> > > > > > > > > @@ -608,35 +636,50 @@ std::ostream &operator<<(std::ostream &out,\n> > > > > > const SizeRange &sr)\n> > > > > > > > >   /**\n> > > > > > > > >    * \\fn Rectangle::Rectangle(int x, int y, const Size &size)\n> > > > > > > > >    * \\brief Construct a Rectangle with the given position and\n> > > > size\n> > > > > > > > > - * \\param[in] x The horizontal coordinate of the top-left corner\n> > > > > > > > > - * \\param[in] y The vertical coordinate of the top-left corner\n> > > > > > > > > + * \\param[in] x The horizontal coordinate of the origin corner\n> > > > > > > > > + * \\param[in] y The vertical coordinate of the origin corner\n> > > > > > > > >    * \\param[in] size The size\n> > > > > > > > > + *\n> > > > > > > > > + * The rectangle's origin corner is the corner closer to the\n> > > > > > reference system\n> > > > > > > > > + * origin point (0, 0).\n> > > > > > >\n> > > > > > > I think we should stick to the previous description:\n> > > > > > > `\"origin\" point defined as the point with the lower x and\n> > > > > > > lower y of the rectangle`, as `x` and `y` are signed integers.\n> > > > > > >\n> > > > > > > If we only support coordinates that are positive or 0, which\n> > > > > > > I'm not sure if it's the case, how about making the type to be\n> > > > > > > `unsigned int`?\n> > > > > > >\n> > > > > >\n> > > > > > To be honest I would rather make width and heigh signed to allow\n> > > > > > constructing (x, y, -w, -h)\n> > > > > >\n> > > > > >\n> > > > > >\n> > > > > >\n> > > > > >                -------------------\n> > > > > >                |                 ^\n> > > > > >                |            ------------->\n> > > > > >                |           |     |\n> > > > > >                ------<-----|-----o\n> > > > > >                            |\n> > > > > >                            |\n> > > > > >                            V\n> > > > > >\n> > > > > > Not sure if it's useful or not though\n> > > > > >\n> > > > >\n> > > > > Hmm... I find it pretty weird. What if all four corners have all negative\n> > > > > coordinates?\n> > > > >\n> > > > >\n> > > >\n> > > > Don't know, maybe if the reference system where the rectangle is used\n> > > > into has 4 planes and so an all-negative rectangle makes sense.\n> > > >\n> > > > My point is that we should allow users of this class to express\n> > > > Rectangle in any context they plan to use them. Not sure if I'm going\n> > > > overboard here or it makes sense.\n> > > >\n> > >\n> > > Yeah I agree, while doesn't that mean the description doesn't fit all\n> > > cases, like the corner closer to the reference system origin point of a\n> > > rectangle that has all negative coordinates is actually the \"bottom-right\"\n> >\n> > This patch aims to remove all references to \"top-left\" or in general\n> > to any visual reference exactly for that purpose. Or have I forgot any\n> > ?\n>\n> In this c'tor `\\fn Rectangle::Rectangle(int x, int y, const Size &size)`,\n> the description of `x` and `y` are updated to \"coordinates of the origin\n> corner\", where the origin corner is \"the corner closer to the reference\n> system origin point (0, 0).\"\n>\n> As currently libcamera::Size takes only non-negative width and height,\n> take rectangle [(-3, -3), (-3, -1), (-1, -3), (-1, -1)] as the example, you\n> can find that the only valid way to construct this rectangle as\n> libcamera::Rectangle is `{x = -3, y = -3, size = {2, 2}}`. However, this\n> doesn't fit with your updated description, as the corner closer to the\n> reference system origin point (0, 0) is actually (-1, -1), instead of\n> (-3, -3).\n>\n\nYou're right. Let's take a step back though. If we have a 4 planes reference\nsystem, we always have a visual top-left indeed. As the 4 planes have\nnegative and positive coordinates, we can describe with absolute\npositions the rectangle and all points in the system.\n\nThe problem at hands now is relevant for 1-planes reference systems,\nthat can be oriented differently, in example with the origin point\nbeing in top-left or bottom-left positions, as per the examples above.\nIn this case I think we agree that \"top-left\" is ambiguous. The x and\ny coordinates are always positive in the case with a single plane.\n\nI think we should also be concerned with 1 plane reference systems and\nmove forward with this patch that removes references to the visual\n\"top-left\" and assumes increments in width and height are always\npositive.\n\n> >\n> > > corner, and currently libcamera::Size only allows non-negative width and\n> > > height [1].\n> >\n> > True, Size uses unsigned int. I don't think it's a big deal and I'm\n> > not proposing to introduce a new constructor with signed width and\n> > height now, but my point is that if the need arises we can now do\n> > that.\n> >\n> > >\n> > > [1]:\n> > > https://git.libcamera.org/libcamera/libcamera.git/tree/include/libcamera/geometry.h#n65\n> > >\n> > >\n> > > > >\n> > > > >\n> > > > > >\n> > > > > > > BR,\n> > > > > > > Harvey\n> > > > > > >\n> > > > > > >\n> > > > > > > > >    */\n> > > > > > > > >\n> > > > > > > > >   /**\n> > > > > > > > >    * \\fn Rectangle::Rectangle(int x, int y, unsigned int width,\n> > > > > > unsigned int height)\n> > > > > > > > >    * \\brief Construct a Rectangle with the given position and\n> > > > size\n> > > > > > > > > - * \\param[in] x The horizontal coordinate of the top-left corner\n> > > > > > > > > - * \\param[in] y The vertical coordinate of the top-left corner\n> > > > > > > > > + * \\param[in] x The horizontal coordinate of the origin corner\n> > > > > > > > > + * \\param[in] y The vertical coordinate of the origin corner\n> > > > > > > > >    * \\param[in] width The width\n> > > > > > > > >    * \\param[in] height The height\n> > > > > > > > > + *\n> > > > > > > > > + * The rectangle's origin corner is the corner closer to the\n> > > > > > reference system\n> > > > > > > > > + * origin point (0, 0).\n> > > > > > > > >    */\n> > > > > > > > >\n> > > > > > > > >   /**\n> > > > > > > > >    * \\fn Rectangle::Rectangle(const Size &size)\n> > > > > > > > > - * \\brief Construct a Rectangle of \\a size with its top left\n> > > > corner\n> > > > > > located\n> > > > > > > > > + * \\brief Construct a Rectangle of \\a size with its origin\n> > > > corner\n> > > > > > located\n> > > > > > > > >    * at (0,0)\n> > > > > > > > >    * \\param[in] size The desired Rectangle size\n> > > > > > > > > + *\n> > > > > > > > > + * The rectangle's origin corner is the corner closer to the\n> > > > > > reference system\n> > > > > > > > > + * origin point (0, 0).\n> > > > > > > > >    */\n> > > > > > > > >\n> > > > > > > > >   /**\n> > > > > > > > >    * \\var Rectangle::x\n> > > > > > > > > - * \\brief The horizontal coordinate of the rectangle's top-left\n> > > > > > corner\n> > > > > > > > > + * \\brief The horizontal coordinate of the rectangle's origin\n> > > > corner\n> > > > > > > > > + *\n> > > > > > > > > + * The rectangle's origin corner is the corner closer to the\n> > > > > > reference system\n> > > > > > > > > + * origin point (0, 0).\n> > > > > > > > >    */\n> > > > > > > > >\n> > > > > > > > >   /**\n> > > > > > > > >    * \\var Rectangle::y\n> > > > > > > > > - * \\brief The vertical coordinate of the rectangle's top-left\n> > > > corner\n> > > > > > > > > + * \\brief The vertical coordinate of the rectangle's origin\n> > > > corner\n> > > > > > > > > + *\n> > > > > > > > > + * The rectangle's origin corner is the corner closer to the\n> > > > > > reference system\n> > > > > > > > > + * origin point (0, 0).\n> > > > > > > > >    */\n> > > > > > > > >\n> > > > > > > > >   /**\n> > > > > > > > > @@ -683,9 +726,13 @@ Point Rectangle::center() const\n> > > > > > > > >    */\n> > > > > > > > >\n> > > > > > > > >   /**\n> > > > > > > > > - * \\fn Point Rectangle::topLeft() const\n> > > > > > > > > - * \\brief Retrieve the coordinates of the top left corner of\n> > > > this\n> > > > > > Rectangle\n> > > > > > > > > - * \\return The Rectangle's top left corner\n> > > > > > > > > + * \\fn Point Rectangle::origin() const\n> > > > > > > > > + * \\brief Retrieve the coordinates of the origin corner of this\n> > > > > > Rectangle\n> > > > > > > > > + *\n> > > > > > > > > + * The rectangle's origin corner is the corner closer to the\n> > > > > > reference system\n> > > > > > > > > + * origin point (0, 0).\n> > > > > > > > > + *\n> > > > > > > > > + * \\return The Rectangle's origin corner\n> > > > > > > >\n> > > > > > > > I think you can drop \"corner\" from \"origin corner\"\n> > > > > > > >\n> > > > > > > > Probably throughout the patch:\n> > > > > > > >      s/origin corner/origin/\n> > > > > > > >\n> > > > > > > > Otherwise, LGTM\n> > > > > > > >\n> > > > > > > > Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>\n> > > > > > > > >    */\n> > > > > > > > >\n> > > > > > > > >   /**\n> > > > > > > > > @@ -740,15 +787,15 @@ Rectangle &Rectangle::translateBy(const\n> > > > Point\n> > > > > > &point)\n> > > > > > > > >    */\n> > > > > > > > >   Rectangle Rectangle::boundedTo(const Rectangle &bound) const\n> > > > > > > > >   {\n> > > > > > > > > -     int topLeftX = std::max(x, bound.x);\n> > > > > > > > > -     int topLeftY = std::max(y, bound.y);\n> > > > > > > > > +     int originX = std::max(x, bound.x);\n> > > > > > > > > +     int originY = std::max(y, bound.y);\n> > > > > > > > >       int bottomRightX = std::min<int>(x + width, bound.x +\n> > > > > > bound.width);\n> > > > > > > > >       int bottomRightY = std::min<int>(y + height, bound.y +\n> > > > > > bound.height);\n> > > > > > > > >\n> > > > > > > > > -     unsigned int newWidth = std::max(bottomRightX - topLeftX,\n> > > > 0);\n> > > > > > > > > -     unsigned int newHeight = std::max(bottomRightY - topLeftY,\n> > > > 0);\n> > > > > > > > > +     unsigned int newWidth = std::max(bottomRightX - originX,\n> > > > 0);\n> > > > > > > > > +     unsigned int newHeight = std::max(bottomRightY - originY,\n> > > > 0);\n> > > > > > > > >\n> > > > > > > > > -     return { topLeftX, topLeftY, newWidth, newHeight };\n> > > > > > > > > +     return { originX, originY, newWidth, newHeight };\n> > > > > > > > >   }\n> > > > > > > > >\n> > > > > > > > >   /**\n> > > > > > > > > diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n> > > > > > b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n> > > > > > > > > index 3041fd1ed9fd..8d2440026689 100644\n> > > > > > > > > --- a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n> > > > > > > > > +++ b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n> > > > > > > > > @@ -1289,7 +1289,7 @@ Rectangle CameraData::scaleIspCrop(const\n> > > > > > Rectangle &ispCrop) const\n> > > > > > > > >        */\n> > > > > > > > >       Rectangle nativeCrop =\n> > > > > > ispCrop.scaledBy(sensorInfo_.analogCrop.size(),\n> > > > > > > > >\n> > > > > >  sensorInfo_.outputSize);\n> > > > > > > > > -     nativeCrop.translateBy(sensorInfo_.analogCrop.topLeft());\n> > > > > > > > > +     nativeCrop.translateBy(sensorInfo_.analogCrop.origin());\n> > > > > > > > >       return nativeCrop;\n> > > > > > > > >   }\n> > > > > > > > >\n> > > > > > > > > @@ -1303,7 +1303,7 @@ void CameraData::applyScalerCrop(const\n> > > > > > ControlList &controls)\n> > > > > > > > >                       nativeCrop = { 0, 0, 1, 1 };\n> > > > > > > > >\n> > > > > > > > >               /* Create a version of the crop scaled to ISP\n> > > > (camera\n> > > > > > mode) pixels. */\n> > > > > > > > > -             Rectangle ispCrop =\n> > > > > > nativeCrop.translatedBy(-sensorInfo_.analogCrop.topLeft());\n> > > > > > > > > +             Rectangle ispCrop =\n> > > > > > nativeCrop.translatedBy(-sensorInfo_.analogCrop.origin());\n> > > > > > > > >               ispCrop.scaleBy(sensorInfo_.outputSize,\n> > > > > > sensorInfo_.analogCrop.size());\n> > > > > > > > >\n> > > > > > > > >               /*\n> > > > > > > > > diff --git a/src/py/libcamera/py_geometry.cpp\n> > > > > > b/src/py/libcamera/py_geometry.cpp\n> > > > > > > > > index c7e303609427..8dee365b25dd 100644\n> > > > > > > > > --- a/src/py/libcamera/py_geometry.cpp\n> > > > > > > > > +++ b/src/py/libcamera/py_geometry.cpp\n> > > > > > > > > @@ -105,7 +105,7 @@ void init_py_geometry(py::module &m)\n> > > > > > > > >               .def_property_readonly(\"is_null\",\n> > > > &Rectangle::isNull)\n> > > > > > > > >               .def_property_readonly(\"center\",\n> > > > &Rectangle::center)\n> > > > > > > > >               .def_property_readonly(\"size\", &Rectangle::size)\n> > > > > > > > > -             .def_property_readonly(\"topLeft\",\n> > > > &Rectangle::topLeft)\n> > > > > > > > > +             .def_property_readonly(\"origin\",\n> > > > &Rectangle::origin)\n> > > > > > > > >               .def(\"scale_by\", &Rectangle::scaleBy)\n> > > > > > > > >               .def(\"translate_by\", &Rectangle::translateBy)\n> > > > > > > > >               .def(\"bounded_to\", &Rectangle::boundedTo)\n> > > > > > > > > diff --git a/test/geometry.cpp b/test/geometry.cpp\n> > > > > > > > > index 64169206ad16..a4ee6f6e167a 100644\n> > > > > > > > > --- a/test/geometry.cpp\n> > > > > > > > > +++ b/test/geometry.cpp\n> > > > > > > > > @@ -363,16 +363,16 @@ protected:\n> > > > > > > > >                       return TestFail;\n> > > > > > > > >               }\n> > > > > > > > >\n> > > > > > > > > -             /* Rectangle::size(), Rectangle::topLeft() and\n> > > > > > Rectangle::center() tests */\n> > > > > > > > > +             /* Rectangle::size(), Rectangle::origin() and\n> > > > > > Rectangle::center() tests */\n> > > > > > > > >               if (Rectangle(-1, -2, 3, 4).size() != Size(3, 4) ||\n> > > > > > > > >                   Rectangle(0, 0, 100000, 200000).size() !=\n> > > > > > Size(100000, 200000)) {\n> > > > > > > > >                       cout << \"Rectangle::size() test failed\" <<\n> > > > > > endl;\n> > > > > > > > >                       return TestFail;\n> > > > > > > > >               }\n> > > > > > > > >\n> > > > > > > > > -             if (Rectangle(1, 2, 3, 4).topLeft() != Point(1, 2)\n> > > > ||\n> > > > > > > > > -                 Rectangle(-1, -2, 3, 4).topLeft() != Point(-1,\n> > > > > > -2)) {\n> > > > > > > > > -                     cout << \"Rectangle::topLeft() test failed\"\n> > > > <<\n> > > > > > endl;\n> > > > > > > > > +             if (Rectangle(1, 2, 3, 4).origin() != Point(1, 2)\n> > > > ||\n> > > > > > > > > +                 Rectangle(-1, -2, 3, 4).origin() != Point(-1,\n> > > > -2))\n> > > > > > {\n> > > > > > > > > +                     cout << \"Rectangle::origin() test failed\"\n> > > > <<\n> > > > > > endl;\n> > > > > > > > >                       return TestFail;\n> > > > > > > > >               }\n> > > > > > > > >\n> > > > > > > > > --\n> > > > > > > > > 2.46.1\n> > > > > > > > >\n> > > > > > > >\n> > > > > > >\n> > > > > > >\n> > > > > > > --\n> > > > > > > BR,\n> > > > > > > Harvey Yang\n> > > > > >\n> > > >\n>\n>\n>\n> --\n> BR,\n> Harvey Yang","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 D50ACC3257\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 26 Sep 2024 14:35:46 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id C834B6350F;\n\tThu, 26 Sep 2024 16:35:45 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id F3508634F9\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 26 Sep 2024 16:35:43 +0200 (CEST)","from ideasonboard.com (mob-5-90-51-229.net.vodafone.it\n\t[5.90.51.229])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 638A68D4;\n\tThu, 26 Sep 2024 16:34:15 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"Sr9P45fN\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1727361255;\n\tbh=WcGg7GMGSo0fE/xPJdhVt9zryq7vcQ24rDhFbEbqlkM=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=Sr9P45fNk4lNgr8YvSqQKPUWUeGkmZTyetFK9OGMHAXDZr3KqbMnWK3qVtbtomeVX\n\ts01044kvn+DYlkdoOYd1k8UsLXXBHwPGHDG3Gp+3rAqkf94V8Gt0zVVKR/zjQgcsIe\n\tFDKvJmXPDX+E6poV48eD/4hP2f83B0/5lchcN+s8=","Date":"Thu, 26 Sep 2024 16:35:40 +0200","From":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>","To":"Cheng-Hao Yang <chenghaoyang@google.com>","Cc":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>, \n\tUmang Jain <umang.jain@ideasonboard.com>,\n\tlibcamera devel <libcamera-devel@lists.libcamera.org>","Subject":"Re: [PATCH] libcamera: geometry: Rename Rectangle's top-left corner","Message-ID":"<6cnkhto53ixz7hafosgqebixvfdpwftc24ach46wsvv6qpjmkv@h7e25hene6yc>","References":"<20240924124525.95189-1-jacopo.mondi@ideasonboard.com>\n\t<d975583c-7f5d-4f5b-8e99-5cdc61396667@ideasonboard.com>\n\t<CAC=wSGUwXZDvM68ZfhqPvYKhAB0bkem=zJhFJ-Fjafc9OYhDqA@mail.gmail.com>\n\t<uzptnxdipytxx4nwqusnr62asaiwrdawylf2f3vzbmkc53onhc@nkeomtxtfw5g>\n\t<CAC=wSGWEZU7_=nEFTp+g_g74L7kcs65wK3oOeS8xwBqzMHa5wQ@mail.gmail.com>\n\t<zsszrdewqlrlovncquphk43ajxyksfoijoiorglvwem4kb2u6q@my2gscqpdzd3>\n\t<CAC=wSGXj==p2GZMidtwb9pUhmnuRrdqbGhQUF14HSNfTzgz_Cw@mail.gmail.com>\n\t<62yvkiqioilupdcm7ryjtrz273iamzojfi2pgxndmjwoyyaitb@iq46e47ke2vg>\n\t<CAC=wSGXgYv2YyZqwgRANhmVzPtLTkTHP4=R-_Sz+NE7wNzPJXw@mail.gmail.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<CAC=wSGXgYv2YyZqwgRANhmVzPtLTkTHP4=R-_Sz+NE7wNzPJXw@mail.gmail.com>","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>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":31411,"web_url":"https://patchwork.libcamera.org/comment/31411/","msgid":"<CAC=wSGU3ubNji42mp-4eXH7L34ZZE0vP_NA5Uu1fKgUsQTvG7Q@mail.gmail.com>","date":"2024-09-26T15:22:58","subject":"Re: [PATCH] libcamera: geometry: Rename Rectangle's top-left corner","submitter":{"id":148,"url":"https://patchwork.libcamera.org/api/people/148/","name":"Cheng-Hao Yang","email":"chenghaoyang@google.com"},"content":"Hi Jacopo,\n\nOn Thu, Sep 26, 2024 at 10:35 PM Jacopo Mondi\n<jacopo.mondi@ideasonboard.com> wrote:\n>\n> Hi Harvey\n>\n> On Thu, Sep 26, 2024 at 10:03:55PM GMT, Cheng-Hao Yang wrote:\n> > Hi Jacopo,\n> >\n> > On Thu, Sep 26, 2024 at 5:36 PM Jacopo Mondi\n> > <jacopo.mondi@ideasonboard.com> wrote:\n> > >\n> > > Hi Harvey\n> > >\n> > > On Thu, Sep 26, 2024 at 05:28:13PM GMT, Cheng-Hao Yang wrote:\n> > > > Hi Jacopo,\n> > > >\n> > > >\n> > > >\n> > > > On Thu, Sep 26, 2024, 4:38 PM Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n> > > > wrote:\n> > > >\n> > > > > Hi Harvey\n> > > > >\n> > > > > On Thu, Sep 26, 2024 at 04:29:50PM GMT, Cheng-Hao Yang wrote:\n> > > > > > Hi Jacopo,\n> > > > > >\n> > > > > > On Thu, Sep 26, 2024, 4:03 PM Jacopo Mondi <\n> > > > > jacopo.mondi@ideasonboard.com>\n> > > > > > wrote:\n> > > > > >\n> > > > > > > Hi Harvey\n> > > > > > >\n> > > > > > > On Wed, Sep 25, 2024 at 03:09:38PM GMT, Cheng-Hao Yang wrote:\n> > > > > > > > Hi Jacopo,\n> > > > > > > >\n> > > > > > > > Thank you for the patch.\n> > > > > > > >\n> > > > > > > > On Wed, Sep 25, 2024 at 2:36 PM Umang Jain <\n> > > > > umang.jain@ideasonboard.com>\n> > > > > > > wrote:\n> > > > > > > > >\n> > > > > > > > > Hi Jacopo\n> > > > > > > > >\n> > > > > > > > > Thank you for the patch\n> > > > > > > > >\n> > > > > > > > > On 24/09/24 6:15 pm, Jacopo Mondi wrote:\n> > > > > > > > > > The libcamera::Rectangle class should allow defining rectangles\n> > > > > > > > > > regardless of the reference system where an instance is used in.\n> > > > > > > > > >\n> > > > > > > > > > However the class documentation assumes the reference system\n> > > > > origin\n> > > > > > > > > > point to be in the visual top-left side and that rectangles are\n> > > > > > > > > > constructed by specifying the top-left corner position and sizes.\n> > > > > > > > > >\n> > > > > > > > > > However this is ambiguous when using a different reference\n> > > > > system as,\n> > > > > > > > > > in example, constructing a rectangle (x, y, w, h) in the\n> > > > > following\n> > > > > > > > > > scenario, with the origin corner in the top-left position, would\n> > > > > > > require\n> > > > > > > > > > a negative decrement along the y-axis.\n> > > > > > > > > >\n> > > > > > > > > >           ^\n> > > > > > > > > >           |\n> > > > > > > > > >          y|      o------------------\n> > > > > > > > > >           |      |                 | h\n> > > > > > > > > >           |      |                 |\n> > > > > > > > > >           |      -------------------\n> > > > > > > > > >           |               w\n> > > > > > > > > >            ------------------------------->\n> > > > > > > > > >           (0,0)  x\n> > > > > > > > > >\n> > > > > > > > > > To remove ambiguities, drop references to the visual top-left\n> > > > > corner\n> > > > > > > and\n> > > > > > > > > > define the rectangle's origin corner as the corner closer to the\n> > > > > > > > > > reference system origin point, and specify the horizontal and\n> > > > > > > vertical\n> > > > > > > > > > dimensions always increment along their respective axis, as in\n> > > > > the\n> > > > > > > > > > following example.\n> > > > > > > > > >\n> > > > > > > > > >           ^\n> > > > > > > > > >           |\n> > > > > > > > > >           |      -------------------\n> > > > > > > > > >           |      ^                 | h\n> > > > > > > > > >           |      |                 |\n> > > > > > > > > >          y|      o---->-------------\n> > > > > > > > > >           |               w\n> > > > > > > > > >            ------------------------------->\n> > > > > > > > > >           (0,0)  x\n> > > > > > > > > >\n> > > > > > > > > >           (0,0)  x\n> > > > > > > > > >             ------------------------------>\n> > > > > > > > > >            |              w\n> > > > > > > > > >           y|     o---->-------------\n> > > > > > > > > >            |     |                 | h\n> > > > > > > > > >            |     v                 |\n> > > > > > > > > >            |     -------------------\n> > > > > > > > > >            |\n> > > > > > > > > >            V\n> > > > > > > > > >\n> > > > > > > > > > Also rename for consistency the Rectangle::topLeft() function to\n> > > > > > > > > > Rectangle::origin() and update its in-tree users.\n> > > > > > > > > >\n> > > > > > > > > > Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n> > > > > > > > > > ---\n> > > > > > > > > >   include/libcamera/geometry.h                  |  2 +-\n> > > > > > > > > >   src/ipa/ipu3/algorithms/af.cpp                |  2 +-\n> > > > > > > > > >   src/libcamera/geometry.cpp                    | 85\n> > > > > > > ++++++++++++++-----\n> > > > > > > > > >   .../pipeline/rpi/common/pipeline_base.cpp     |  4 +-\n> > > > > > > > > >   src/py/libcamera/py_geometry.cpp              |  2 +-\n> > > > > > > > > >   test/geometry.cpp                             |  8 +-\n> > > > > > > > > >   6 files changed, 75 insertions(+), 28 deletions(-)\n> > > > > > > > > >\n> > > > > > > > > > diff --git a/include/libcamera/geometry.h\n> > > > > > > b/include/libcamera/geometry.h\n> > > > > > > > > > index 3e6f0f5d7fab..07cb0a7866fe 100644\n> > > > > > > > > > --- a/include/libcamera/geometry.h\n> > > > > > > > > > +++ b/include/libcamera/geometry.h\n> > > > > > > > > > @@ -277,7 +277,7 @@ public:\n> > > > > > > > > >               return { width, height };\n> > > > > > > > > >       }\n> > > > > > > > > >\n> > > > > > > > > > -     Point topLeft() const\n> > > > > > > > > > +     Point origin() const\n> > > > > > > > > >       {\n> > > > > > > > > >               return { x, y };\n> > > > > > > > > >       }\n> > > > > > > > > > diff --git a/src/ipa/ipu3/algorithms/af.cpp\n> > > > > > > b/src/ipa/ipu3/algorithms/af.cpp\n> > > > > > > > > > index cf68fb59c49b..1b707e9dd9ab 100644\n> > > > > > > > > > --- a/src/ipa/ipu3/algorithms/af.cpp\n> > > > > > > > > > +++ b/src/ipa/ipu3/algorithms/af.cpp\n> > > > > > > > > > @@ -155,7 +155,7 @@ int Af::configure(IPAContext &context, const\n> > > > > > > IPAConfigInfo &configInfo)\n> > > > > > > > > >        * - Return the AF ROI as metadata in the Request\n> > > > > > > > > >        */\n> > > > > > > > > >       Rectangle roi = gridSize.centeredTo(bds.center());\n> > > > > > > > > > -     Point start = roi.topLeft();\n> > > > > > > > > > +     Point start = roi.origin();\n> > > > > > > > > >\n> > > > > > > > > >       /* x_start and y_start should be even */\n> > > > > > > > > >       grid.x_start = utils::alignDown(start.x, 2);\n> > > > > > > > > > diff --git a/src/libcamera/geometry.cpp\n> > > > > b/src/libcamera/geometry.cpp\n> > > > > > > > > > index 000151364c7f..45ba81a99920 100644\n> > > > > > > > > > --- a/src/libcamera/geometry.cpp\n> > > > > > > > > > +++ b/src/libcamera/geometry.cpp\n> > > > > > > > > > @@ -593,11 +593,39 @@ std::ostream &operator<<(std::ostream &out,\n> > > > > > > const SizeRange &sr)\n> > > > > > > > > >    * \\brief Describe a rectangle's position and dimensions\n> > > > > > > > > >    *\n> > > > > > > > > >    * Rectangles are used to identify an area of an image. They\n> > > > > are\n> > > > > > > specified by\n> > > > > > > > > > - * the coordinates of top-left corner and their horizontal and\n> > > > > > > vertical size.\n> > > > > > > > > > + * the coordinates of the corner closer to the reference\n> > > > > system's\n> > > > > > > origin point\n> > > > > > > > > > + * and by horizontal and vertical increments from there.\n> > > > > > > > > >    *\n> > > > > > > > > > - * The measure unit of the rectangle coordinates and size, as\n> > > > > well\n> > > > > > > as the\n> > > > > > > > > > - * reference point from which the Rectangle::x and Rectangle::y\n> > > > > > > displacements\n> > > > > > > > > > - * refers to, are defined by the context were rectangle is used.\n> > > > > > > > > > + * The corner closer to the reference system's origin point is\n> > > > > the\n> > > > > > > rectangle's\n> > > > > > > > > > + * origin corner.\n> > > > > > > > > > + *\n> > > > > > > > > > + * \\verbatim\n> > > > > > > > > > +\n> > > > > > > > > > +  o = origin corner\n> > > > > > > > > > +\n> > > > > > > > > > +         ^\n> > > > > > > > > > +         |\n> > > > > > > > > > +         |      -------------------\n> > > > > > > > > > +         |      ^                 |\n> > > > > > > > > > +         |      |                 |\n> > > > > > > > > > +         |      o---->-------------\n> > > > > > > > > > +         |\n> > > > > > > > > > +          ------------------------------->\n> > > > > > > > > > +         (0,0)\n> > > > > > > > > > +\n> > > > > > > > > > +         (0,0)\n> > > > > > > > > > +           ------------------------------->\n> > > > > > > > > > +          |\n> > > > > > > > > > +          |      o---->-------------\n> > > > > > > > > > +          |      |                 |\n> > > > > > > > > > +          |      v                 |\n> > > > > > > > > > +          |      -------------------\n> > > > > > > > > > +          |\n> > > > > > > > > > +          V\n> > > > > > > > > > +   \\endverbatim\n> > > > > > > > > > + *\n> > > > > > > > > > + * The measure unit of the rectangle coordinates and size are\n> > > > > > > defined by the\n> > > > > > > > > > + * context were the rectangle is used.\n> > > > > > > > > >    */\n> > > > > > > > > >\n> > > > > > > > > >   /**\n> > > > > > > > > > @@ -608,35 +636,50 @@ std::ostream &operator<<(std::ostream &out,\n> > > > > > > const SizeRange &sr)\n> > > > > > > > > >   /**\n> > > > > > > > > >    * \\fn Rectangle::Rectangle(int x, int y, const Size &size)\n> > > > > > > > > >    * \\brief Construct a Rectangle with the given position and\n> > > > > size\n> > > > > > > > > > - * \\param[in] x The horizontal coordinate of the top-left corner\n> > > > > > > > > > - * \\param[in] y The vertical coordinate of the top-left corner\n> > > > > > > > > > + * \\param[in] x The horizontal coordinate of the origin corner\n> > > > > > > > > > + * \\param[in] y The vertical coordinate of the origin corner\n> > > > > > > > > >    * \\param[in] size The size\n> > > > > > > > > > + *\n> > > > > > > > > > + * The rectangle's origin corner is the corner closer to the\n> > > > > > > reference system\n> > > > > > > > > > + * origin point (0, 0).\n> > > > > > > >\n> > > > > > > > I think we should stick to the previous description:\n> > > > > > > > `\"origin\" point defined as the point with the lower x and\n> > > > > > > > lower y of the rectangle`, as `x` and `y` are signed integers.\n> > > > > > > >\n> > > > > > > > If we only support coordinates that are positive or 0, which\n> > > > > > > > I'm not sure if it's the case, how about making the type to be\n> > > > > > > > `unsigned int`?\n> > > > > > > >\n> > > > > > >\n> > > > > > > To be honest I would rather make width and heigh signed to allow\n> > > > > > > constructing (x, y, -w, -h)\n> > > > > > >\n> > > > > > >\n> > > > > > >\n> > > > > > >\n> > > > > > >                -------------------\n> > > > > > >                |                 ^\n> > > > > > >                |            ------------->\n> > > > > > >                |           |     |\n> > > > > > >                ------<-----|-----o\n> > > > > > >                            |\n> > > > > > >                            |\n> > > > > > >                            V\n> > > > > > >\n> > > > > > > Not sure if it's useful or not though\n> > > > > > >\n> > > > > >\n> > > > > > Hmm... I find it pretty weird. What if all four corners have all negative\n> > > > > > coordinates?\n> > > > > >\n> > > > > >\n> > > > >\n> > > > > Don't know, maybe if the reference system where the rectangle is used\n> > > > > into has 4 planes and so an all-negative rectangle makes sense.\n> > > > >\n> > > > > My point is that we should allow users of this class to express\n> > > > > Rectangle in any context they plan to use them. Not sure if I'm going\n> > > > > overboard here or it makes sense.\n> > > > >\n> > > >\n> > > > Yeah I agree, while doesn't that mean the description doesn't fit all\n> > > > cases, like the corner closer to the reference system origin point of a\n> > > > rectangle that has all negative coordinates is actually the \"bottom-right\"\n> > >\n> > > This patch aims to remove all references to \"top-left\" or in general\n> > > to any visual reference exactly for that purpose. Or have I forgot any\n> > > ?\n> >\n> > In this c'tor `\\fn Rectangle::Rectangle(int x, int y, const Size &size)`,\n> > the description of `x` and `y` are updated to \"coordinates of the origin\n> > corner\", where the origin corner is \"the corner closer to the reference\n> > system origin point (0, 0).\"\n> >\n> > As currently libcamera::Size takes only non-negative width and height,\n> > take rectangle [(-3, -3), (-3, -1), (-1, -3), (-1, -1)] as the example, you\n> > can find that the only valid way to construct this rectangle as\n> > libcamera::Rectangle is `{x = -3, y = -3, size = {2, 2}}`. However, this\n> > doesn't fit with your updated description, as the corner closer to the\n> > reference system origin point (0, 0) is actually (-1, -1), instead of\n> > (-3, -3).\n> >\n>\n> You're right. Let's take a step back though. If we have a 4 planes reference\n> system, we always have a visual top-left indeed. As the 4 planes have\n> negative and positive coordinates, we can describe with absolute\n> positions the rectangle and all points in the system.\n\nSorry, I still don't get your point...\n\nDo you mean that the new description, like\n`The horizontal coordinate of the rectangle's origin corner`,\nonly fits with the 1-plane reference system? I thought it should fit all\n2D reference systems.\n\n>\n> The problem at hands now is relevant for 1-planes reference systems,\n> that can be oriented differently, in example with the origin point\n> being in top-left or bottom-left positions, as per the examples above.\n> In this case I think we agree that \"top-left\" is ambiguous. The x and\n> y coordinates are always positive in the case with a single plane.\n>\n> I think we should also be concerned with 1 plane reference systems and\n> move forward with this patch that removes references to the visual\n> \"top-left\" and assumes increments in width and height are always\n> positive.\n>\n> > >\n> > > > corner, and currently libcamera::Size only allows non-negative width and\n> > > > height [1].\n> > >\n> > > True, Size uses unsigned int. I don't think it's a big deal and I'm\n> > > not proposing to introduce a new constructor with signed width and\n> > > height now, but my point is that if the need arises we can now do\n> > > that.\n> > >\n> > > >\n> > > > [1]:\n> > > > https://git.libcamera.org/libcamera/libcamera.git/tree/include/libcamera/geometry.h#n65\n> > > >\n> > > >\n> > > > > >\n> > > > > >\n> > > > > > >\n> > > > > > > > BR,\n> > > > > > > > Harvey\n> > > > > > > >\n> > > > > > > >\n> > > > > > > > > >    */\n> > > > > > > > > >\n> > > > > > > > > >   /**\n> > > > > > > > > >    * \\fn Rectangle::Rectangle(int x, int y, unsigned int width,\n> > > > > > > unsigned int height)\n> > > > > > > > > >    * \\brief Construct a Rectangle with the given position and\n> > > > > size\n> > > > > > > > > > - * \\param[in] x The horizontal coordinate of the top-left corner\n> > > > > > > > > > - * \\param[in] y The vertical coordinate of the top-left corner\n> > > > > > > > > > + * \\param[in] x The horizontal coordinate of the origin corner\n> > > > > > > > > > + * \\param[in] y The vertical coordinate of the origin corner\n> > > > > > > > > >    * \\param[in] width The width\n> > > > > > > > > >    * \\param[in] height The height\n> > > > > > > > > > + *\n> > > > > > > > > > + * The rectangle's origin corner is the corner closer to the\n> > > > > > > reference system\n> > > > > > > > > > + * origin point (0, 0).\n> > > > > > > > > >    */\n> > > > > > > > > >\n> > > > > > > > > >   /**\n> > > > > > > > > >    * \\fn Rectangle::Rectangle(const Size &size)\n> > > > > > > > > > - * \\brief Construct a Rectangle of \\a size with its top left\n> > > > > corner\n> > > > > > > located\n> > > > > > > > > > + * \\brief Construct a Rectangle of \\a size with its origin\n> > > > > corner\n> > > > > > > located\n> > > > > > > > > >    * at (0,0)\n> > > > > > > > > >    * \\param[in] size The desired Rectangle size\n> > > > > > > > > > + *\n> > > > > > > > > > + * The rectangle's origin corner is the corner closer to the\n> > > > > > > reference system\n> > > > > > > > > > + * origin point (0, 0).\n> > > > > > > > > >    */\n> > > > > > > > > >\n> > > > > > > > > >   /**\n> > > > > > > > > >    * \\var Rectangle::x\n> > > > > > > > > > - * \\brief The horizontal coordinate of the rectangle's top-left\n> > > > > > > corner\n> > > > > > > > > > + * \\brief The horizontal coordinate of the rectangle's origin\n> > > > > corner\n> > > > > > > > > > + *\n> > > > > > > > > > + * The rectangle's origin corner is the corner closer to the\n> > > > > > > reference system\n> > > > > > > > > > + * origin point (0, 0).\n> > > > > > > > > >    */\n> > > > > > > > > >\n> > > > > > > > > >   /**\n> > > > > > > > > >    * \\var Rectangle::y\n> > > > > > > > > > - * \\brief The vertical coordinate of the rectangle's top-left\n> > > > > corner\n> > > > > > > > > > + * \\brief The vertical coordinate of the rectangle's origin\n> > > > > corner\n> > > > > > > > > > + *\n> > > > > > > > > > + * The rectangle's origin corner is the corner closer to the\n> > > > > > > reference system\n> > > > > > > > > > + * origin point (0, 0).\n> > > > > > > > > >    */\n> > > > > > > > > >\n> > > > > > > > > >   /**\n> > > > > > > > > > @@ -683,9 +726,13 @@ Point Rectangle::center() const\n> > > > > > > > > >    */\n> > > > > > > > > >\n> > > > > > > > > >   /**\n> > > > > > > > > > - * \\fn Point Rectangle::topLeft() const\n> > > > > > > > > > - * \\brief Retrieve the coordinates of the top left corner of\n> > > > > this\n> > > > > > > Rectangle\n> > > > > > > > > > - * \\return The Rectangle's top left corner\n> > > > > > > > > > + * \\fn Point Rectangle::origin() const\n> > > > > > > > > > + * \\brief Retrieve the coordinates of the origin corner of this\n> > > > > > > Rectangle\n> > > > > > > > > > + *\n> > > > > > > > > > + * The rectangle's origin corner is the corner closer to the\n> > > > > > > reference system\n> > > > > > > > > > + * origin point (0, 0).\n> > > > > > > > > > + *\n> > > > > > > > > > + * \\return The Rectangle's origin corner\n> > > > > > > > >\n> > > > > > > > > I think you can drop \"corner\" from \"origin corner\"\n> > > > > > > > >\n> > > > > > > > > Probably throughout the patch:\n> > > > > > > > >      s/origin corner/origin/\n> > > > > > > > >\n> > > > > > > > > Otherwise, LGTM\n> > > > > > > > >\n> > > > > > > > > Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>\n> > > > > > > > > >    */\n> > > > > > > > > >\n> > > > > > > > > >   /**\n> > > > > > > > > > @@ -740,15 +787,15 @@ Rectangle &Rectangle::translateBy(const\n> > > > > Point\n> > > > > > > &point)\n> > > > > > > > > >    */\n> > > > > > > > > >   Rectangle Rectangle::boundedTo(const Rectangle &bound) const\n> > > > > > > > > >   {\n> > > > > > > > > > -     int topLeftX = std::max(x, bound.x);\n> > > > > > > > > > -     int topLeftY = std::max(y, bound.y);\n> > > > > > > > > > +     int originX = std::max(x, bound.x);\n> > > > > > > > > > +     int originY = std::max(y, bound.y);\n> > > > > > > > > >       int bottomRightX = std::min<int>(x + width, bound.x +\n> > > > > > > bound.width);\n> > > > > > > > > >       int bottomRightY = std::min<int>(y + height, bound.y +\n> > > > > > > bound.height);\n> > > > > > > > > >\n> > > > > > > > > > -     unsigned int newWidth = std::max(bottomRightX - topLeftX,\n> > > > > 0);\n> > > > > > > > > > -     unsigned int newHeight = std::max(bottomRightY - topLeftY,\n> > > > > 0);\n> > > > > > > > > > +     unsigned int newWidth = std::max(bottomRightX - originX,\n> > > > > 0);\n> > > > > > > > > > +     unsigned int newHeight = std::max(bottomRightY - originY,\n> > > > > 0);\n> > > > > > > > > >\n> > > > > > > > > > -     return { topLeftX, topLeftY, newWidth, newHeight };\n> > > > > > > > > > +     return { originX, originY, newWidth, newHeight };\n> > > > > > > > > >   }\n> > > > > > > > > >\n> > > > > > > > > >   /**\n> > > > > > > > > > diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n> > > > > > > b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n> > > > > > > > > > index 3041fd1ed9fd..8d2440026689 100644\n> > > > > > > > > > --- a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n> > > > > > > > > > +++ b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n> > > > > > > > > > @@ -1289,7 +1289,7 @@ Rectangle CameraData::scaleIspCrop(const\n> > > > > > > Rectangle &ispCrop) const\n> > > > > > > > > >        */\n> > > > > > > > > >       Rectangle nativeCrop =\n> > > > > > > ispCrop.scaledBy(sensorInfo_.analogCrop.size(),\n> > > > > > > > > >\n> > > > > > >  sensorInfo_.outputSize);\n> > > > > > > > > > -     nativeCrop.translateBy(sensorInfo_.analogCrop.topLeft());\n> > > > > > > > > > +     nativeCrop.translateBy(sensorInfo_.analogCrop.origin());\n> > > > > > > > > >       return nativeCrop;\n> > > > > > > > > >   }\n> > > > > > > > > >\n> > > > > > > > > > @@ -1303,7 +1303,7 @@ void CameraData::applyScalerCrop(const\n> > > > > > > ControlList &controls)\n> > > > > > > > > >                       nativeCrop = { 0, 0, 1, 1 };\n> > > > > > > > > >\n> > > > > > > > > >               /* Create a version of the crop scaled to ISP\n> > > > > (camera\n> > > > > > > mode) pixels. */\n> > > > > > > > > > -             Rectangle ispCrop =\n> > > > > > > nativeCrop.translatedBy(-sensorInfo_.analogCrop.topLeft());\n> > > > > > > > > > +             Rectangle ispCrop =\n> > > > > > > nativeCrop.translatedBy(-sensorInfo_.analogCrop.origin());\n> > > > > > > > > >               ispCrop.scaleBy(sensorInfo_.outputSize,\n> > > > > > > sensorInfo_.analogCrop.size());\n> > > > > > > > > >\n> > > > > > > > > >               /*\n> > > > > > > > > > diff --git a/src/py/libcamera/py_geometry.cpp\n> > > > > > > b/src/py/libcamera/py_geometry.cpp\n> > > > > > > > > > index c7e303609427..8dee365b25dd 100644\n> > > > > > > > > > --- a/src/py/libcamera/py_geometry.cpp\n> > > > > > > > > > +++ b/src/py/libcamera/py_geometry.cpp\n> > > > > > > > > > @@ -105,7 +105,7 @@ void init_py_geometry(py::module &m)\n> > > > > > > > > >               .def_property_readonly(\"is_null\",\n> > > > > &Rectangle::isNull)\n> > > > > > > > > >               .def_property_readonly(\"center\",\n> > > > > &Rectangle::center)\n> > > > > > > > > >               .def_property_readonly(\"size\", &Rectangle::size)\n> > > > > > > > > > -             .def_property_readonly(\"topLeft\",\n> > > > > &Rectangle::topLeft)\n> > > > > > > > > > +             .def_property_readonly(\"origin\",\n> > > > > &Rectangle::origin)\n> > > > > > > > > >               .def(\"scale_by\", &Rectangle::scaleBy)\n> > > > > > > > > >               .def(\"translate_by\", &Rectangle::translateBy)\n> > > > > > > > > >               .def(\"bounded_to\", &Rectangle::boundedTo)\n> > > > > > > > > > diff --git a/test/geometry.cpp b/test/geometry.cpp\n> > > > > > > > > > index 64169206ad16..a4ee6f6e167a 100644\n> > > > > > > > > > --- a/test/geometry.cpp\n> > > > > > > > > > +++ b/test/geometry.cpp\n> > > > > > > > > > @@ -363,16 +363,16 @@ protected:\n> > > > > > > > > >                       return TestFail;\n> > > > > > > > > >               }\n> > > > > > > > > >\n> > > > > > > > > > -             /* Rectangle::size(), Rectangle::topLeft() and\n> > > > > > > Rectangle::center() tests */\n> > > > > > > > > > +             /* Rectangle::size(), Rectangle::origin() and\n> > > > > > > Rectangle::center() tests */\n> > > > > > > > > >               if (Rectangle(-1, -2, 3, 4).size() != Size(3, 4) ||\n> > > > > > > > > >                   Rectangle(0, 0, 100000, 200000).size() !=\n> > > > > > > Size(100000, 200000)) {\n> > > > > > > > > >                       cout << \"Rectangle::size() test failed\" <<\n> > > > > > > endl;\n> > > > > > > > > >                       return TestFail;\n> > > > > > > > > >               }\n> > > > > > > > > >\n> > > > > > > > > > -             if (Rectangle(1, 2, 3, 4).topLeft() != Point(1, 2)\n> > > > > ||\n> > > > > > > > > > -                 Rectangle(-1, -2, 3, 4).topLeft() != Point(-1,\n> > > > > > > -2)) {\n> > > > > > > > > > -                     cout << \"Rectangle::topLeft() test failed\"\n> > > > > <<\n> > > > > > > endl;\n> > > > > > > > > > +             if (Rectangle(1, 2, 3, 4).origin() != Point(1, 2)\n> > > > > ||\n> > > > > > > > > > +                 Rectangle(-1, -2, 3, 4).origin() != Point(-1,\n> > > > > -2))\n> > > > > > > {\n> > > > > > > > > > +                     cout << \"Rectangle::origin() test failed\"\n> > > > > <<\n> > > > > > > endl;\n> > > > > > > > > >                       return TestFail;\n> > > > > > > > > >               }\n> > > > > > > > > >\n> > > > > > > > > > --\n> > > > > > > > > > 2.46.1\n> > > > > > > > > >\n> > > > > > > > >\n> > > > > > > >\n> > > > > > > >\n> > > > > > > > --\n> > > > > > > > BR,\n> > > > > > > > Harvey Yang\n> > > > > > >\n> > > > >\n> >\n> >\n> >\n> > --\n> > BR,\n> > Harvey Yang","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 E2B31C3257\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 26 Sep 2024 15:23:41 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id E1A0D6350F;\n\tThu, 26 Sep 2024 17:23:40 +0200 (CEST)","from mail-lf1-x12c.google.com (mail-lf1-x12c.google.com\n\t[IPv6:2a00:1450:4864:20::12c])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 7A24C634F9\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 26 Sep 2024 17:23:38 +0200 (CEST)","by mail-lf1-x12c.google.com with SMTP id\n\t2adb3069b0e04-536552fcc07so16173e87.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 26 Sep 2024 08:23:38 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key;\n\tunprotected) header.d=google.com header.i=@google.com\n\theader.b=\"b40tU+f6\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=google.com; s=20230601; t=1727364218; x=1727969018;\n\tdarn=lists.libcamera.org; \n\th=content-transfer-encoding:cc:to:subject:message-id:date:from\n\t:in-reply-to:references:mime-version:from:to:cc:subject:date\n\t:message-id:reply-to;\n\tbh=YY1nkEmZdEIPXEhgZLrm58s3uguokGYcxqVD6l1doDU=;\n\tb=b40tU+f6ebAF6hfgBxDB9D0Yll7T/Mf/hnvmERUSSl6YqoAf1D6902L3oZYkA823Q/\n\tK1DS3tpZ+1z3D0VnB5PFwmNtATNQMoeeIju6bNtnkXufs5qjeFr9LKFoeLL+4e1e/Sef\n\tz/plg7gGFhvoS3b9CmX4unvqj5j4fjCNguT1AD/UeLtTE4J4KqDQjMjOfpuVEK57UYFv\n\tdLTq2/qp6Y6wjmM0VcvMf6rwKBhaXrUryU3zWxkXU/w9tTE1QOLMhTh8ATESy1eyMMd0\n\t+Tv23ktJFosKn8QSLpNFn5iM4mvee2sEe+OlMxriRSvqmbhpwajh/W1h3zQcv2+VjQuh\n\t5VeQ==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1727364218; x=1727969018;\n\th=content-transfer-encoding:cc:to:subject:message-id:date:from\n\t:in-reply-to:references:mime-version:x-gm-message-state:from:to:cc\n\t:subject:date:message-id:reply-to;\n\tbh=YY1nkEmZdEIPXEhgZLrm58s3uguokGYcxqVD6l1doDU=;\n\tb=Jh4WYYGCH23cQpwzkpGi8l4c3DLHd1gedjhS+dVz3Mbg3qP32K1GAiY285nUanM8JX\n\tgdRHolx2q+HmqdIiaDs1IMNPNBR2NKOCu3hnYR828s8R97m+x+ZYn+0DQk8D43c0/jOK\n\tPMMy6gzn+wvfE/us7kPU7gfL5BQru1p8BdoXqlNU/s2RbnQrkrB5revqrRP93KNp7X+9\n\tzY0P+RXKeaNlidrZuB2E2hqOjqSOjzrOkvZJAcrKwS9DVxs+xOSRaokLWd3qN75uGyAC\n\two+uiPghPmbfvEBvK+MycZovDZsuNf3uXtViyFWdU+hgOv99bz5p4qMsw/mAmY80DGun\n\tuj3g==","X-Forwarded-Encrypted":"i=1;\n\tAJvYcCVmuHqZfCU8ExpmQUBDAeL7nzrCUujo165xLCPanKqTsYkjbLvOPIOdUiSlbXdlYtxQY2aRRpFalfYSi5vgSMI=@lists.libcamera.org","X-Gm-Message-State":"AOJu0Yz335JCn2b8TgueygnKGutPCU1VZpcaszi772owV/n5wFWn18dS\n\tI9xGm+uVwu3cx4aOEyVdJ0uLWgt4hUDHHOlqcKwQoOPlkFq5CqVVKCZwsm40TK9f/0fLp17at3p\n\t3dT1ei8paLCuyE8mn+YsnEGgcnVE6m9i+YBN+","X-Google-Smtp-Source":"AGHT+IHq07YyBeo0kKtyTMcnA+rubNpjot0kOuM5/AYeiM3VMTMh+1euorQaRxucQoYRXntl4Nvb0rSINtLbJkyHAAw=","X-Received":"by 2002:a05:6512:68:b0:538:9e44:3034 with SMTP id\n\t2adb3069b0e04-5389e4432acmr49360e87.6.1727364217127; Thu, 26 Sep 2024\n\t08:23:37 -0700 (PDT)","MIME-Version":"1.0","References":"<20240924124525.95189-1-jacopo.mondi@ideasonboard.com>\n\t<d975583c-7f5d-4f5b-8e99-5cdc61396667@ideasonboard.com>\n\t<CAC=wSGUwXZDvM68ZfhqPvYKhAB0bkem=zJhFJ-Fjafc9OYhDqA@mail.gmail.com>\n\t<uzptnxdipytxx4nwqusnr62asaiwrdawylf2f3vzbmkc53onhc@nkeomtxtfw5g>\n\t<CAC=wSGWEZU7_=nEFTp+g_g74L7kcs65wK3oOeS8xwBqzMHa5wQ@mail.gmail.com>\n\t<zsszrdewqlrlovncquphk43ajxyksfoijoiorglvwem4kb2u6q@my2gscqpdzd3>\n\t<CAC=wSGXj==p2GZMidtwb9pUhmnuRrdqbGhQUF14HSNfTzgz_Cw@mail.gmail.com>\n\t<62yvkiqioilupdcm7ryjtrz273iamzojfi2pgxndmjwoyyaitb@iq46e47ke2vg>\n\t<CAC=wSGXgYv2YyZqwgRANhmVzPtLTkTHP4=R-_Sz+NE7wNzPJXw@mail.gmail.com>\n\t<6cnkhto53ixz7hafosgqebixvfdpwftc24ach46wsvv6qpjmkv@h7e25hene6yc>","In-Reply-To":"<6cnkhto53ixz7hafosgqebixvfdpwftc24ach46wsvv6qpjmkv@h7e25hene6yc>","From":"Cheng-Hao Yang <chenghaoyang@google.com>","Date":"Thu, 26 Sep 2024 23:22:58 +0800","Message-ID":"<CAC=wSGU3ubNji42mp-4eXH7L34ZZE0vP_NA5Uu1fKgUsQTvG7Q@mail.gmail.com>","Subject":"Re: [PATCH] libcamera: geometry: Rename Rectangle's top-left corner","To":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>","Cc":"Umang Jain <umang.jain@ideasonboard.com>, \n\tlibcamera devel <libcamera-devel@lists.libcamera.org>","Content-Type":"text/plain; charset=\"UTF-8\"","Content-Transfer-Encoding":"quoted-printable","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>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":31435,"web_url":"https://patchwork.libcamera.org/comment/31435/","msgid":"<juj2axmwzwss5axiy3y6l4hetonuv72oyzgb6ekf5hbt66it73@j23uammf6fl7>","date":"2024-09-27T08:05:14","subject":"Re: [PATCH] libcamera: geometry: Rename Rectangle's top-left corner","submitter":{"id":143,"url":"https://patchwork.libcamera.org/api/people/143/","name":"Jacopo Mondi","email":"jacopo.mondi@ideasonboard.com"},"content":"Hi Harvey\n\nOn Thu, Sep 26, 2024 at 11:22:58PM GMT, Cheng-Hao Yang wrote:\n> Hi Jacopo,\n>\n> On Thu, Sep 26, 2024 at 10:35 PM Jacopo Mondi\n> <jacopo.mondi@ideasonboard.com> wrote:\n> >\n> > Hi Harvey\n> >\n> > On Thu, Sep 26, 2024 at 10:03:55PM GMT, Cheng-Hao Yang wrote:\n> > > Hi Jacopo,\n> > >\n> > > On Thu, Sep 26, 2024 at 5:36 PM Jacopo Mondi\n> > > <jacopo.mondi@ideasonboard.com> wrote:\n> > > >\n> > > > Hi Harvey\n> > > >\n> > > > On Thu, Sep 26, 2024 at 05:28:13PM GMT, Cheng-Hao Yang wrote:\n> > > > > Hi Jacopo,\n> > > > >\n> > > > >\n> > > > >\n> > > > > On Thu, Sep 26, 2024, 4:38 PM Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n> > > > > wrote:\n> > > > >\n> > > > > > Hi Harvey\n> > > > > >\n> > > > > > On Thu, Sep 26, 2024 at 04:29:50PM GMT, Cheng-Hao Yang wrote:\n> > > > > > > Hi Jacopo,\n> > > > > > >\n> > > > > > > On Thu, Sep 26, 2024, 4:03 PM Jacopo Mondi <\n> > > > > > jacopo.mondi@ideasonboard.com>\n> > > > > > > wrote:\n> > > > > > >\n> > > > > > > > Hi Harvey\n> > > > > > > >\n> > > > > > > > On Wed, Sep 25, 2024 at 03:09:38PM GMT, Cheng-Hao Yang wrote:\n> > > > > > > > > Hi Jacopo,\n> > > > > > > > >\n> > > > > > > > > Thank you for the patch.\n> > > > > > > > >\n> > > > > > > > > On Wed, Sep 25, 2024 at 2:36 PM Umang Jain <\n> > > > > > umang.jain@ideasonboard.com>\n> > > > > > > > wrote:\n> > > > > > > > > >\n> > > > > > > > > > Hi Jacopo\n> > > > > > > > > >\n> > > > > > > > > > Thank you for the patch\n> > > > > > > > > >\n> > > > > > > > > > On 24/09/24 6:15 pm, Jacopo Mondi wrote:\n> > > > > > > > > > > The libcamera::Rectangle class should allow defining rectangles\n> > > > > > > > > > > regardless of the reference system where an instance is used in.\n> > > > > > > > > > >\n> > > > > > > > > > > However the class documentation assumes the reference system\n> > > > > > origin\n> > > > > > > > > > > point to be in the visual top-left side and that rectangles are\n> > > > > > > > > > > constructed by specifying the top-left corner position and sizes.\n> > > > > > > > > > >\n> > > > > > > > > > > However this is ambiguous when using a different reference\n> > > > > > system as,\n> > > > > > > > > > > in example, constructing a rectangle (x, y, w, h) in the\n> > > > > > following\n> > > > > > > > > > > scenario, with the origin corner in the top-left position, would\n> > > > > > > > require\n> > > > > > > > > > > a negative decrement along the y-axis.\n> > > > > > > > > > >\n> > > > > > > > > > >           ^\n> > > > > > > > > > >           |\n> > > > > > > > > > >          y|      o------------------\n> > > > > > > > > > >           |      |                 | h\n> > > > > > > > > > >           |      |                 |\n> > > > > > > > > > >           |      -------------------\n> > > > > > > > > > >           |               w\n> > > > > > > > > > >            ------------------------------->\n> > > > > > > > > > >           (0,0)  x\n> > > > > > > > > > >\n> > > > > > > > > > > To remove ambiguities, drop references to the visual top-left\n> > > > > > corner\n> > > > > > > > and\n> > > > > > > > > > > define the rectangle's origin corner as the corner closer to the\n> > > > > > > > > > > reference system origin point, and specify the horizontal and\n> > > > > > > > vertical\n> > > > > > > > > > > dimensions always increment along their respective axis, as in\n> > > > > > the\n> > > > > > > > > > > following example.\n> > > > > > > > > > >\n> > > > > > > > > > >           ^\n> > > > > > > > > > >           |\n> > > > > > > > > > >           |      -------------------\n> > > > > > > > > > >           |      ^                 | h\n> > > > > > > > > > >           |      |                 |\n> > > > > > > > > > >          y|      o---->-------------\n> > > > > > > > > > >           |               w\n> > > > > > > > > > >            ------------------------------->\n> > > > > > > > > > >           (0,0)  x\n> > > > > > > > > > >\n> > > > > > > > > > >           (0,0)  x\n> > > > > > > > > > >             ------------------------------>\n> > > > > > > > > > >            |              w\n> > > > > > > > > > >           y|     o---->-------------\n> > > > > > > > > > >            |     |                 | h\n> > > > > > > > > > >            |     v                 |\n> > > > > > > > > > >            |     -------------------\n> > > > > > > > > > >            |\n> > > > > > > > > > >            V\n> > > > > > > > > > >\n> > > > > > > > > > > Also rename for consistency the Rectangle::topLeft() function to\n> > > > > > > > > > > Rectangle::origin() and update its in-tree users.\n> > > > > > > > > > >\n> > > > > > > > > > > Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n> > > > > > > > > > > ---\n> > > > > > > > > > >   include/libcamera/geometry.h                  |  2 +-\n> > > > > > > > > > >   src/ipa/ipu3/algorithms/af.cpp                |  2 +-\n> > > > > > > > > > >   src/libcamera/geometry.cpp                    | 85\n> > > > > > > > ++++++++++++++-----\n> > > > > > > > > > >   .../pipeline/rpi/common/pipeline_base.cpp     |  4 +-\n> > > > > > > > > > >   src/py/libcamera/py_geometry.cpp              |  2 +-\n> > > > > > > > > > >   test/geometry.cpp                             |  8 +-\n> > > > > > > > > > >   6 files changed, 75 insertions(+), 28 deletions(-)\n> > > > > > > > > > >\n> > > > > > > > > > > diff --git a/include/libcamera/geometry.h\n> > > > > > > > b/include/libcamera/geometry.h\n> > > > > > > > > > > index 3e6f0f5d7fab..07cb0a7866fe 100644\n> > > > > > > > > > > --- a/include/libcamera/geometry.h\n> > > > > > > > > > > +++ b/include/libcamera/geometry.h\n> > > > > > > > > > > @@ -277,7 +277,7 @@ public:\n> > > > > > > > > > >               return { width, height };\n> > > > > > > > > > >       }\n> > > > > > > > > > >\n> > > > > > > > > > > -     Point topLeft() const\n> > > > > > > > > > > +     Point origin() const\n> > > > > > > > > > >       {\n> > > > > > > > > > >               return { x, y };\n> > > > > > > > > > >       }\n> > > > > > > > > > > diff --git a/src/ipa/ipu3/algorithms/af.cpp\n> > > > > > > > b/src/ipa/ipu3/algorithms/af.cpp\n> > > > > > > > > > > index cf68fb59c49b..1b707e9dd9ab 100644\n> > > > > > > > > > > --- a/src/ipa/ipu3/algorithms/af.cpp\n> > > > > > > > > > > +++ b/src/ipa/ipu3/algorithms/af.cpp\n> > > > > > > > > > > @@ -155,7 +155,7 @@ int Af::configure(IPAContext &context, const\n> > > > > > > > IPAConfigInfo &configInfo)\n> > > > > > > > > > >        * - Return the AF ROI as metadata in the Request\n> > > > > > > > > > >        */\n> > > > > > > > > > >       Rectangle roi = gridSize.centeredTo(bds.center());\n> > > > > > > > > > > -     Point start = roi.topLeft();\n> > > > > > > > > > > +     Point start = roi.origin();\n> > > > > > > > > > >\n> > > > > > > > > > >       /* x_start and y_start should be even */\n> > > > > > > > > > >       grid.x_start = utils::alignDown(start.x, 2);\n> > > > > > > > > > > diff --git a/src/libcamera/geometry.cpp\n> > > > > > b/src/libcamera/geometry.cpp\n> > > > > > > > > > > index 000151364c7f..45ba81a99920 100644\n> > > > > > > > > > > --- a/src/libcamera/geometry.cpp\n> > > > > > > > > > > +++ b/src/libcamera/geometry.cpp\n> > > > > > > > > > > @@ -593,11 +593,39 @@ std::ostream &operator<<(std::ostream &out,\n> > > > > > > > const SizeRange &sr)\n> > > > > > > > > > >    * \\brief Describe a rectangle's position and dimensions\n> > > > > > > > > > >    *\n> > > > > > > > > > >    * Rectangles are used to identify an area of an image. They\n> > > > > > are\n> > > > > > > > specified by\n> > > > > > > > > > > - * the coordinates of top-left corner and their horizontal and\n> > > > > > > > vertical size.\n> > > > > > > > > > > + * the coordinates of the corner closer to the reference\n> > > > > > system's\n> > > > > > > > origin point\n> > > > > > > > > > > + * and by horizontal and vertical increments from there.\n> > > > > > > > > > >    *\n> > > > > > > > > > > - * The measure unit of the rectangle coordinates and size, as\n> > > > > > well\n> > > > > > > > as the\n> > > > > > > > > > > - * reference point from which the Rectangle::x and Rectangle::y\n> > > > > > > > displacements\n> > > > > > > > > > > - * refers to, are defined by the context were rectangle is used.\n> > > > > > > > > > > + * The corner closer to the reference system's origin point is\n> > > > > > the\n> > > > > > > > rectangle's\n> > > > > > > > > > > + * origin corner.\n> > > > > > > > > > > + *\n> > > > > > > > > > > + * \\verbatim\n> > > > > > > > > > > +\n> > > > > > > > > > > +  o = origin corner\n> > > > > > > > > > > +\n> > > > > > > > > > > +         ^\n> > > > > > > > > > > +         |\n> > > > > > > > > > > +         |      -------------------\n> > > > > > > > > > > +         |      ^                 |\n> > > > > > > > > > > +         |      |                 |\n> > > > > > > > > > > +         |      o---->-------------\n> > > > > > > > > > > +         |\n> > > > > > > > > > > +          ------------------------------->\n> > > > > > > > > > > +         (0,0)\n> > > > > > > > > > > +\n> > > > > > > > > > > +         (0,0)\n> > > > > > > > > > > +           ------------------------------->\n> > > > > > > > > > > +          |\n> > > > > > > > > > > +          |      o---->-------------\n> > > > > > > > > > > +          |      |                 |\n> > > > > > > > > > > +          |      v                 |\n> > > > > > > > > > > +          |      -------------------\n> > > > > > > > > > > +          |\n> > > > > > > > > > > +          V\n> > > > > > > > > > > +   \\endverbatim\n> > > > > > > > > > > + *\n> > > > > > > > > > > + * The measure unit of the rectangle coordinates and size are\n> > > > > > > > defined by the\n> > > > > > > > > > > + * context were the rectangle is used.\n> > > > > > > > > > >    */\n> > > > > > > > > > >\n> > > > > > > > > > >   /**\n> > > > > > > > > > > @@ -608,35 +636,50 @@ std::ostream &operator<<(std::ostream &out,\n> > > > > > > > const SizeRange &sr)\n> > > > > > > > > > >   /**\n> > > > > > > > > > >    * \\fn Rectangle::Rectangle(int x, int y, const Size &size)\n> > > > > > > > > > >    * \\brief Construct a Rectangle with the given position and\n> > > > > > size\n> > > > > > > > > > > - * \\param[in] x The horizontal coordinate of the top-left corner\n> > > > > > > > > > > - * \\param[in] y The vertical coordinate of the top-left corner\n> > > > > > > > > > > + * \\param[in] x The horizontal coordinate of the origin corner\n> > > > > > > > > > > + * \\param[in] y The vertical coordinate of the origin corner\n> > > > > > > > > > >    * \\param[in] size The size\n> > > > > > > > > > > + *\n> > > > > > > > > > > + * The rectangle's origin corner is the corner closer to the\n> > > > > > > > reference system\n> > > > > > > > > > > + * origin point (0, 0).\n> > > > > > > > >\n> > > > > > > > > I think we should stick to the previous description:\n> > > > > > > > > `\"origin\" point defined as the point with the lower x and\n> > > > > > > > > lower y of the rectangle`, as `x` and `y` are signed integers.\n> > > > > > > > >\n> > > > > > > > > If we only support coordinates that are positive or 0, which\n> > > > > > > > > I'm not sure if it's the case, how about making the type to be\n> > > > > > > > > `unsigned int`?\n> > > > > > > > >\n> > > > > > > >\n> > > > > > > > To be honest I would rather make width and heigh signed to allow\n> > > > > > > > constructing (x, y, -w, -h)\n> > > > > > > >\n> > > > > > > >\n> > > > > > > >\n> > > > > > > >\n> > > > > > > >                -------------------\n> > > > > > > >                |                 ^\n> > > > > > > >                |            ------------->\n> > > > > > > >                |           |     |\n> > > > > > > >                ------<-----|-----o\n> > > > > > > >                            |\n> > > > > > > >                            |\n> > > > > > > >                            V\n> > > > > > > >\n> > > > > > > > Not sure if it's useful or not though\n> > > > > > > >\n> > > > > > >\n> > > > > > > Hmm... I find it pretty weird. What if all four corners have all negative\n> > > > > > > coordinates?\n> > > > > > >\n> > > > > > >\n> > > > > >\n> > > > > > Don't know, maybe if the reference system where the rectangle is used\n> > > > > > into has 4 planes and so an all-negative rectangle makes sense.\n> > > > > >\n> > > > > > My point is that we should allow users of this class to express\n> > > > > > Rectangle in any context they plan to use them. Not sure if I'm going\n> > > > > > overboard here or it makes sense.\n> > > > > >\n> > > > >\n> > > > > Yeah I agree, while doesn't that mean the description doesn't fit all\n> > > > > cases, like the corner closer to the reference system origin point of a\n> > > > > rectangle that has all negative coordinates is actually the \"bottom-right\"\n> > > >\n> > > > This patch aims to remove all references to \"top-left\" or in general\n> > > > to any visual reference exactly for that purpose. Or have I forgot any\n> > > > ?\n> > >\n> > > In this c'tor `\\fn Rectangle::Rectangle(int x, int y, const Size &size)`,\n> > > the description of `x` and `y` are updated to \"coordinates of the origin\n> > > corner\", where the origin corner is \"the corner closer to the reference\n> > > system origin point (0, 0).\"\n> > >\n> > > As currently libcamera::Size takes only non-negative width and height,\n> > > take rectangle [(-3, -3), (-3, -1), (-1, -3), (-1, -1)] as the example, you\n> > > can find that the only valid way to construct this rectangle as\n> > > libcamera::Rectangle is `{x = -3, y = -3, size = {2, 2}}`. However, this\n> > > doesn't fit with your updated description, as the corner closer to the\n> > > reference system origin point (0, 0) is actually (-1, -1), instead of\n> > > (-3, -3).\n> > >\n> >\n> > You're right. Let's take a step back though. If we have a 4 planes reference\n> > system, we always have a visual top-left indeed. As the 4 planes have\n> > negative and positive coordinates, we can describe with absolute\n> > positions the rectangle and all points in the system.\n>\n> Sorry, I still don't get your point...\n>\n\nIf you have a 4 planes system\n\n                      ^\n                      |\n                      |\n                      |\n                      |\n        <--------------------------->\n                      |\n                      |\n                      |\n                      |\n                      V\n\nThen you always have a top, a left, and bottom and a right, you can\ndescribe width and height as negative or positive increments and your\nrectangle is always well defined as the reference system cannot be\nambiguous. The very concept of \"reference system orientation\" doesn't\nmake sense, as a 4-planes system describes the full 2-d space.\n\nThe ambiguity I'm trying to solve is about using a 1 plane reference\nsystem, as depending on how the system is oriented the definition of\nthe \"top-left\" point might change, as well as the definition of the\nhorizontal and vertical increments change as well.\n\nIn example:\n\n                      ^\n                      |\n                      |\n                      |  o-------\n                      |  |      |\n                      |  --------\n                      |\n                      ------------------------>\n\n        top-left: Smaller x and higher y\n        width: positive increment\n        height: negative increment\n\n\n\n\n                      ------------------------>\n                      |  o-------\n                      |  |      |\n                      |  --------\n                      |\n                      |\n                      V\n\n        top-left: Smaller x and smaller y\n        width: positive increment\n        height: positive increment\n\n\nI thought our Rectangle definition didn't make assumptions on the\nreference's system orientation and in fact that's what part of the\ndocumentation says, but indeed the usage of \"top-left\" is, as shown,\nambiguous.\n\nSo I went and changed that to be the \"corner closer to the origin\npoint\" and specified in documentation that vertical and horizontal\nincrements are always positive and I thought I was done with this, but\nthen I made the mistake of talking about negative increments and\n4-plane systems and here we are.\n\n\n> Do you mean that the new description, like\n> `The horizontal coordinate of the rectangle's origin corner`,\n> only fits with the 1-plane reference system? I thought it should fit all\n> 2D reference systems.\n\nI don't think that has never been the case, but indeed we have a\nconstructor that takes \"signed\" x and y.\n\nTo be honest I would not be concerned about 4-planes systems, we're\ntalking about imaging and what is relevant here is that we should be\nallowed to express rectangles on reference systems that can be\noriented differently, think of a sensor's pixel array that might be\nrepresented with the (0, 0) position in the top-left corner compared\nto a plane 2-d image that usually has its origin in the bottom-left\ncorner.\n\nI have an hard time finding a use case for expressing negative\ncoordinates in this usage context. Furthermore that if we introduce 4\nplanes we lose the ability to describe systems with different\norientation, as this:\n\n                      ------------------------>\n                      |  o-------\n                      |  |      |\n                      |  --------\n                      |\n                      |\n                      V\n\nwhen expressed in a 4-planes system becomes\n\n                      ^\n                      |\n                      |\n                      |\n                      |\n        <--------------------------->\n                      |/////////////\n                      |/////////////\n                      |// this /////\n                      |/////////////\n                      |/////////////\n                      V\n\nAnd would require you to express y and height in negative coordinates.\nSincerely, I would not go there.\n\nI can specify that the Rectangle class reference system is always a\n2-d plane with positively increasing x and y axes instead.\n\n>\n> >\n> > The problem at hands now is relevant for 1-planes reference systems,\n> > that can be oriented differently, in example with the origin point\n> > being in top-left or bottom-left positions, as per the examples above.\n> > In this case I think we agree that \"top-left\" is ambiguous. The x and\n> > y coordinates are always positive in the case with a single plane.\n> >\n> > I think we should also be concerned with 1 plane reference systems and\n> > move forward with this patch that removes references to the visual\n> > \"top-left\" and assumes increments in width and height are always\n> > positive.\n> >\n> > > >\n> > > > > corner, and currently libcamera::Size only allows non-negative width and\n> > > > > height [1].\n> > > >\n> > > > True, Size uses unsigned int. I don't think it's a big deal and I'm\n> > > > not proposing to introduce a new constructor with signed width and\n> > > > height now, but my point is that if the need arises we can now do\n> > > > that.\n> > > >\n> > > > >\n> > > > > [1]:\n> > > > > https://git.libcamera.org/libcamera/libcamera.git/tree/include/libcamera/geometry.h#n65\n> > > > >\n> > > > >\n> > > > > > >\n> > > > > > >\n> > > > > > > >\n> > > > > > > > > BR,\n> > > > > > > > > Harvey\n> > > > > > > > >\n> > > > > > > > >\n> > > > > > > > > > >    */\n> > > > > > > > > > >\n> > > > > > > > > > >   /**\n> > > > > > > > > > >    * \\fn Rectangle::Rectangle(int x, int y, unsigned int width,\n> > > > > > > > unsigned int height)\n> > > > > > > > > > >    * \\brief Construct a Rectangle with the given position and\n> > > > > > size\n> > > > > > > > > > > - * \\param[in] x The horizontal coordinate of the top-left corner\n> > > > > > > > > > > - * \\param[in] y The vertical coordinate of the top-left corner\n> > > > > > > > > > > + * \\param[in] x The horizontal coordinate of the origin corner\n> > > > > > > > > > > + * \\param[in] y The vertical coordinate of the origin corner\n> > > > > > > > > > >    * \\param[in] width The width\n> > > > > > > > > > >    * \\param[in] height The height\n> > > > > > > > > > > + *\n> > > > > > > > > > > + * The rectangle's origin corner is the corner closer to the\n> > > > > > > > reference system\n> > > > > > > > > > > + * origin point (0, 0).\n> > > > > > > > > > >    */\n> > > > > > > > > > >\n> > > > > > > > > > >   /**\n> > > > > > > > > > >    * \\fn Rectangle::Rectangle(const Size &size)\n> > > > > > > > > > > - * \\brief Construct a Rectangle of \\a size with its top left\n> > > > > > corner\n> > > > > > > > located\n> > > > > > > > > > > + * \\brief Construct a Rectangle of \\a size with its origin\n> > > > > > corner\n> > > > > > > > located\n> > > > > > > > > > >    * at (0,0)\n> > > > > > > > > > >    * \\param[in] size The desired Rectangle size\n> > > > > > > > > > > + *\n> > > > > > > > > > > + * The rectangle's origin corner is the corner closer to the\n> > > > > > > > reference system\n> > > > > > > > > > > + * origin point (0, 0).\n> > > > > > > > > > >    */\n> > > > > > > > > > >\n> > > > > > > > > > >   /**\n> > > > > > > > > > >    * \\var Rectangle::x\n> > > > > > > > > > > - * \\brief The horizontal coordinate of the rectangle's top-left\n> > > > > > > > corner\n> > > > > > > > > > > + * \\brief The horizontal coordinate of the rectangle's origin\n> > > > > > corner\n> > > > > > > > > > > + *\n> > > > > > > > > > > + * The rectangle's origin corner is the corner closer to the\n> > > > > > > > reference system\n> > > > > > > > > > > + * origin point (0, 0).\n> > > > > > > > > > >    */\n> > > > > > > > > > >\n> > > > > > > > > > >   /**\n> > > > > > > > > > >    * \\var Rectangle::y\n> > > > > > > > > > > - * \\brief The vertical coordinate of the rectangle's top-left\n> > > > > > corner\n> > > > > > > > > > > + * \\brief The vertical coordinate of the rectangle's origin\n> > > > > > corner\n> > > > > > > > > > > + *\n> > > > > > > > > > > + * The rectangle's origin corner is the corner closer to the\n> > > > > > > > reference system\n> > > > > > > > > > > + * origin point (0, 0).\n> > > > > > > > > > >    */\n> > > > > > > > > > >\n> > > > > > > > > > >   /**\n> > > > > > > > > > > @@ -683,9 +726,13 @@ Point Rectangle::center() const\n> > > > > > > > > > >    */\n> > > > > > > > > > >\n> > > > > > > > > > >   /**\n> > > > > > > > > > > - * \\fn Point Rectangle::topLeft() const\n> > > > > > > > > > > - * \\brief Retrieve the coordinates of the top left corner of\n> > > > > > this\n> > > > > > > > Rectangle\n> > > > > > > > > > > - * \\return The Rectangle's top left corner\n> > > > > > > > > > > + * \\fn Point Rectangle::origin() const\n> > > > > > > > > > > + * \\brief Retrieve the coordinates of the origin corner of this\n> > > > > > > > Rectangle\n> > > > > > > > > > > + *\n> > > > > > > > > > > + * The rectangle's origin corner is the corner closer to the\n> > > > > > > > reference system\n> > > > > > > > > > > + * origin point (0, 0).\n> > > > > > > > > > > + *\n> > > > > > > > > > > + * \\return The Rectangle's origin corner\n> > > > > > > > > >\n> > > > > > > > > > I think you can drop \"corner\" from \"origin corner\"\n> > > > > > > > > >\n> > > > > > > > > > Probably throughout the patch:\n> > > > > > > > > >      s/origin corner/origin/\n> > > > > > > > > >\n> > > > > > > > > > Otherwise, LGTM\n> > > > > > > > > >\n> > > > > > > > > > Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>\n> > > > > > > > > > >    */\n> > > > > > > > > > >\n> > > > > > > > > > >   /**\n> > > > > > > > > > > @@ -740,15 +787,15 @@ Rectangle &Rectangle::translateBy(const\n> > > > > > Point\n> > > > > > > > &point)\n> > > > > > > > > > >    */\n> > > > > > > > > > >   Rectangle Rectangle::boundedTo(const Rectangle &bound) const\n> > > > > > > > > > >   {\n> > > > > > > > > > > -     int topLeftX = std::max(x, bound.x);\n> > > > > > > > > > > -     int topLeftY = std::max(y, bound.y);\n> > > > > > > > > > > +     int originX = std::max(x, bound.x);\n> > > > > > > > > > > +     int originY = std::max(y, bound.y);\n> > > > > > > > > > >       int bottomRightX = std::min<int>(x + width, bound.x +\n> > > > > > > > bound.width);\n> > > > > > > > > > >       int bottomRightY = std::min<int>(y + height, bound.y +\n> > > > > > > > bound.height);\n> > > > > > > > > > >\n> > > > > > > > > > > -     unsigned int newWidth = std::max(bottomRightX - topLeftX,\n> > > > > > 0);\n> > > > > > > > > > > -     unsigned int newHeight = std::max(bottomRightY - topLeftY,\n> > > > > > 0);\n> > > > > > > > > > > +     unsigned int newWidth = std::max(bottomRightX - originX,\n> > > > > > 0);\n> > > > > > > > > > > +     unsigned int newHeight = std::max(bottomRightY - originY,\n> > > > > > 0);\n> > > > > > > > > > >\n> > > > > > > > > > > -     return { topLeftX, topLeftY, newWidth, newHeight };\n> > > > > > > > > > > +     return { originX, originY, newWidth, newHeight };\n> > > > > > > > > > >   }\n> > > > > > > > > > >\n> > > > > > > > > > >   /**\n> > > > > > > > > > > diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n> > > > > > > > b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n> > > > > > > > > > > index 3041fd1ed9fd..8d2440026689 100644\n> > > > > > > > > > > --- a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n> > > > > > > > > > > +++ b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n> > > > > > > > > > > @@ -1289,7 +1289,7 @@ Rectangle CameraData::scaleIspCrop(const\n> > > > > > > > Rectangle &ispCrop) const\n> > > > > > > > > > >        */\n> > > > > > > > > > >       Rectangle nativeCrop =\n> > > > > > > > ispCrop.scaledBy(sensorInfo_.analogCrop.size(),\n> > > > > > > > > > >\n> > > > > > > >  sensorInfo_.outputSize);\n> > > > > > > > > > > -     nativeCrop.translateBy(sensorInfo_.analogCrop.topLeft());\n> > > > > > > > > > > +     nativeCrop.translateBy(sensorInfo_.analogCrop.origin());\n> > > > > > > > > > >       return nativeCrop;\n> > > > > > > > > > >   }\n> > > > > > > > > > >\n> > > > > > > > > > > @@ -1303,7 +1303,7 @@ void CameraData::applyScalerCrop(const\n> > > > > > > > ControlList &controls)\n> > > > > > > > > > >                       nativeCrop = { 0, 0, 1, 1 };\n> > > > > > > > > > >\n> > > > > > > > > > >               /* Create a version of the crop scaled to ISP\n> > > > > > (camera\n> > > > > > > > mode) pixels. */\n> > > > > > > > > > > -             Rectangle ispCrop =\n> > > > > > > > nativeCrop.translatedBy(-sensorInfo_.analogCrop.topLeft());\n> > > > > > > > > > > +             Rectangle ispCrop =\n> > > > > > > > nativeCrop.translatedBy(-sensorInfo_.analogCrop.origin());\n> > > > > > > > > > >               ispCrop.scaleBy(sensorInfo_.outputSize,\n> > > > > > > > sensorInfo_.analogCrop.size());\n> > > > > > > > > > >\n> > > > > > > > > > >               /*\n> > > > > > > > > > > diff --git a/src/py/libcamera/py_geometry.cpp\n> > > > > > > > b/src/py/libcamera/py_geometry.cpp\n> > > > > > > > > > > index c7e303609427..8dee365b25dd 100644\n> > > > > > > > > > > --- a/src/py/libcamera/py_geometry.cpp\n> > > > > > > > > > > +++ b/src/py/libcamera/py_geometry.cpp\n> > > > > > > > > > > @@ -105,7 +105,7 @@ void init_py_geometry(py::module &m)\n> > > > > > > > > > >               .def_property_readonly(\"is_null\",\n> > > > > > &Rectangle::isNull)\n> > > > > > > > > > >               .def_property_readonly(\"center\",\n> > > > > > &Rectangle::center)\n> > > > > > > > > > >               .def_property_readonly(\"size\", &Rectangle::size)\n> > > > > > > > > > > -             .def_property_readonly(\"topLeft\",\n> > > > > > &Rectangle::topLeft)\n> > > > > > > > > > > +             .def_property_readonly(\"origin\",\n> > > > > > &Rectangle::origin)\n> > > > > > > > > > >               .def(\"scale_by\", &Rectangle::scaleBy)\n> > > > > > > > > > >               .def(\"translate_by\", &Rectangle::translateBy)\n> > > > > > > > > > >               .def(\"bounded_to\", &Rectangle::boundedTo)\n> > > > > > > > > > > diff --git a/test/geometry.cpp b/test/geometry.cpp\n> > > > > > > > > > > index 64169206ad16..a4ee6f6e167a 100644\n> > > > > > > > > > > --- a/test/geometry.cpp\n> > > > > > > > > > > +++ b/test/geometry.cpp\n> > > > > > > > > > > @@ -363,16 +363,16 @@ protected:\n> > > > > > > > > > >                       return TestFail;\n> > > > > > > > > > >               }\n> > > > > > > > > > >\n> > > > > > > > > > > -             /* Rectangle::size(), Rectangle::topLeft() and\n> > > > > > > > Rectangle::center() tests */\n> > > > > > > > > > > +             /* Rectangle::size(), Rectangle::origin() and\n> > > > > > > > Rectangle::center() tests */\n> > > > > > > > > > >               if (Rectangle(-1, -2, 3, 4).size() != Size(3, 4) ||\n> > > > > > > > > > >                   Rectangle(0, 0, 100000, 200000).size() !=\n> > > > > > > > Size(100000, 200000)) {\n> > > > > > > > > > >                       cout << \"Rectangle::size() test failed\" <<\n> > > > > > > > endl;\n> > > > > > > > > > >                       return TestFail;\n> > > > > > > > > > >               }\n> > > > > > > > > > >\n> > > > > > > > > > > -             if (Rectangle(1, 2, 3, 4).topLeft() != Point(1, 2)\n> > > > > > ||\n> > > > > > > > > > > -                 Rectangle(-1, -2, 3, 4).topLeft() != Point(-1,\n> > > > > > > > -2)) {\n> > > > > > > > > > > -                     cout << \"Rectangle::topLeft() test failed\"\n> > > > > > <<\n> > > > > > > > endl;\n> > > > > > > > > > > +             if (Rectangle(1, 2, 3, 4).origin() != Point(1, 2)\n> > > > > > ||\n> > > > > > > > > > > +                 Rectangle(-1, -2, 3, 4).origin() != Point(-1,\n> > > > > > -2))\n> > > > > > > > {\n> > > > > > > > > > > +                     cout << \"Rectangle::origin() test failed\"\n> > > > > > <<\n> > > > > > > > endl;\n> > > > > > > > > > >                       return TestFail;\n> > > > > > > > > > >               }\n> > > > > > > > > > >\n> > > > > > > > > > > --\n> > > > > > > > > > > 2.46.1\n> > > > > > > > > > >\n> > > > > > > > > >\n> > > > > > > > >\n> > > > > > > > >\n> > > > > > > > > --\n> > > > > > > > > BR,\n> > > > > > > > > Harvey Yang\n> > > > > > > >\n> > > > > >\n> > >\n> > >\n> > >\n> > > --\n> > > BR,\n> > > Harvey Yang\n>\n>\n>\n> --\n> BR,\n> Harvey Yang","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 724F5C0F1B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 27 Sep 2024 08:05:24 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 95BB56350F;\n\tFri, 27 Sep 2024 10:05:23 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 19C5D618DB\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 27 Sep 2024 10:05:21 +0200 (CEST)","from ideasonboard.com (mob-5-90-58-180.net.vodafone.it\n\t[5.90.58.180])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 5AA7583D;\n\tFri, 27 Sep 2024 10:03:49 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"dibYuNgA\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1727424232;\n\tbh=dxuR43uW+i3N8yfFddimaldkeZGuaDYpqRLurQTe9dg=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=dibYuNgAzPjq5csyuBTQOT+VxM4aTbtTHVuwBGP9c7B5J4nRHOmOraJBZaXDZWBD/\n\tqVmf07DCPckXZtcaWTciFM/lXUrBhyZL4yWrPXH17Bpl7p8nF/vN2S1qVBibbgRzdj\n\tMOla1UOe25OsV4IQCbJqSavyFVwzlLIHcxolOU90=","Date":"Fri, 27 Sep 2024 10:05:14 +0200","From":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>","To":"Cheng-Hao Yang <chenghaoyang@google.com>","Cc":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>, \n\tUmang Jain <umang.jain@ideasonboard.com>,\n\tlibcamera devel <libcamera-devel@lists.libcamera.org>","Subject":"Re: [PATCH] libcamera: geometry: Rename Rectangle's top-left corner","Message-ID":"<juj2axmwzwss5axiy3y6l4hetonuv72oyzgb6ekf5hbt66it73@j23uammf6fl7>","References":"<d975583c-7f5d-4f5b-8e99-5cdc61396667@ideasonboard.com>\n\t<CAC=wSGUwXZDvM68ZfhqPvYKhAB0bkem=zJhFJ-Fjafc9OYhDqA@mail.gmail.com>\n\t<uzptnxdipytxx4nwqusnr62asaiwrdawylf2f3vzbmkc53onhc@nkeomtxtfw5g>\n\t<CAC=wSGWEZU7_=nEFTp+g_g74L7kcs65wK3oOeS8xwBqzMHa5wQ@mail.gmail.com>\n\t<zsszrdewqlrlovncquphk43ajxyksfoijoiorglvwem4kb2u6q@my2gscqpdzd3>\n\t<CAC=wSGXj==p2GZMidtwb9pUhmnuRrdqbGhQUF14HSNfTzgz_Cw@mail.gmail.com>\n\t<62yvkiqioilupdcm7ryjtrz273iamzojfi2pgxndmjwoyyaitb@iq46e47ke2vg>\n\t<CAC=wSGXgYv2YyZqwgRANhmVzPtLTkTHP4=R-_Sz+NE7wNzPJXw@mail.gmail.com>\n\t<6cnkhto53ixz7hafosgqebixvfdpwftc24ach46wsvv6qpjmkv@h7e25hene6yc>\n\t<CAC=wSGU3ubNji42mp-4eXH7L34ZZE0vP_NA5Uu1fKgUsQTvG7Q@mail.gmail.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<CAC=wSGU3ubNji42mp-4eXH7L34ZZE0vP_NA5Uu1fKgUsQTvG7Q@mail.gmail.com>","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>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":31437,"web_url":"https://patchwork.libcamera.org/comment/31437/","msgid":"<CAC=wSGVEjJ-fHo4W31OGU2Qk8=OhhzYNCW4qFxqLLdtTu0kGrw@mail.gmail.com>","date":"2024-09-27T08:46:06","subject":"Re: [PATCH] libcamera: geometry: Rename Rectangle's top-left corner","submitter":{"id":148,"url":"https://patchwork.libcamera.org/api/people/148/","name":"Cheng-Hao Yang","email":"chenghaoyang@google.com"},"content":"Hi Jacopo,\n\nOn Fri, Sep 27, 2024 at 4:05 PM Jacopo Mondi\n<jacopo.mondi@ideasonboard.com> wrote:\n>\n> Hi Harvey\n>\n> On Thu, Sep 26, 2024 at 11:22:58PM GMT, Cheng-Hao Yang wrote:\n> > Hi Jacopo,\n> >\n> > On Thu, Sep 26, 2024 at 10:35 PM Jacopo Mondi\n> > <jacopo.mondi@ideasonboard.com> wrote:\n> > >\n> > > Hi Harvey\n> > >\n> > > On Thu, Sep 26, 2024 at 10:03:55PM GMT, Cheng-Hao Yang wrote:\n> > > > Hi Jacopo,\n> > > >\n> > > > On Thu, Sep 26, 2024 at 5:36 PM Jacopo Mondi\n> > > > <jacopo.mondi@ideasonboard.com> wrote:\n> > > > >\n> > > > > Hi Harvey\n> > > > >\n> > > > > On Thu, Sep 26, 2024 at 05:28:13PM GMT, Cheng-Hao Yang wrote:\n> > > > > > Hi Jacopo,\n> > > > > >\n> > > > > >\n> > > > > >\n> > > > > > On Thu, Sep 26, 2024, 4:38 PM Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n> > > > > > wrote:\n> > > > > >\n> > > > > > > Hi Harvey\n> > > > > > >\n> > > > > > > On Thu, Sep 26, 2024 at 04:29:50PM GMT, Cheng-Hao Yang wrote:\n> > > > > > > > Hi Jacopo,\n> > > > > > > >\n> > > > > > > > On Thu, Sep 26, 2024, 4:03 PM Jacopo Mondi <\n> > > > > > > jacopo.mondi@ideasonboard.com>\n> > > > > > > > wrote:\n> > > > > > > >\n> > > > > > > > > Hi Harvey\n> > > > > > > > >\n> > > > > > > > > On Wed, Sep 25, 2024 at 03:09:38PM GMT, Cheng-Hao Yang wrote:\n> > > > > > > > > > Hi Jacopo,\n> > > > > > > > > >\n> > > > > > > > > > Thank you for the patch.\n> > > > > > > > > >\n> > > > > > > > > > On Wed, Sep 25, 2024 at 2:36 PM Umang Jain <\n> > > > > > > umang.jain@ideasonboard.com>\n> > > > > > > > > wrote:\n> > > > > > > > > > >\n> > > > > > > > > > > Hi Jacopo\n> > > > > > > > > > >\n> > > > > > > > > > > Thank you for the patch\n> > > > > > > > > > >\n> > > > > > > > > > > On 24/09/24 6:15 pm, Jacopo Mondi wrote:\n> > > > > > > > > > > > The libcamera::Rectangle class should allow defining rectangles\n> > > > > > > > > > > > regardless of the reference system where an instance is used in.\n> > > > > > > > > > > >\n> > > > > > > > > > > > However the class documentation assumes the reference system\n> > > > > > > origin\n> > > > > > > > > > > > point to be in the visual top-left side and that rectangles are\n> > > > > > > > > > > > constructed by specifying the top-left corner position and sizes.\n> > > > > > > > > > > >\n> > > > > > > > > > > > However this is ambiguous when using a different reference\n> > > > > > > system as,\n> > > > > > > > > > > > in example, constructing a rectangle (x, y, w, h) in the\n> > > > > > > following\n> > > > > > > > > > > > scenario, with the origin corner in the top-left position, would\n> > > > > > > > > require\n> > > > > > > > > > > > a negative decrement along the y-axis.\n> > > > > > > > > > > >\n> > > > > > > > > > > >           ^\n> > > > > > > > > > > >           |\n> > > > > > > > > > > >          y|      o------------------\n> > > > > > > > > > > >           |      |                 | h\n> > > > > > > > > > > >           |      |                 |\n> > > > > > > > > > > >           |      -------------------\n> > > > > > > > > > > >           |               w\n> > > > > > > > > > > >            ------------------------------->\n> > > > > > > > > > > >           (0,0)  x\n> > > > > > > > > > > >\n> > > > > > > > > > > > To remove ambiguities, drop references to the visual top-left\n> > > > > > > corner\n> > > > > > > > > and\n> > > > > > > > > > > > define the rectangle's origin corner as the corner closer to the\n> > > > > > > > > > > > reference system origin point, and specify the horizontal and\n> > > > > > > > > vertical\n> > > > > > > > > > > > dimensions always increment along their respective axis, as in\n> > > > > > > the\n> > > > > > > > > > > > following example.\n> > > > > > > > > > > >\n> > > > > > > > > > > >           ^\n> > > > > > > > > > > >           |\n> > > > > > > > > > > >           |      -------------------\n> > > > > > > > > > > >           |      ^                 | h\n> > > > > > > > > > > >           |      |                 |\n> > > > > > > > > > > >          y|      o---->-------------\n> > > > > > > > > > > >           |               w\n> > > > > > > > > > > >            ------------------------------->\n> > > > > > > > > > > >           (0,0)  x\n> > > > > > > > > > > >\n> > > > > > > > > > > >           (0,0)  x\n> > > > > > > > > > > >             ------------------------------>\n> > > > > > > > > > > >            |              w\n> > > > > > > > > > > >           y|     o---->-------------\n> > > > > > > > > > > >            |     |                 | h\n> > > > > > > > > > > >            |     v                 |\n> > > > > > > > > > > >            |     -------------------\n> > > > > > > > > > > >            |\n> > > > > > > > > > > >            V\n> > > > > > > > > > > >\n> > > > > > > > > > > > Also rename for consistency the Rectangle::topLeft() function to\n> > > > > > > > > > > > Rectangle::origin() and update its in-tree users.\n> > > > > > > > > > > >\n> > > > > > > > > > > > Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n> > > > > > > > > > > > ---\n> > > > > > > > > > > >   include/libcamera/geometry.h                  |  2 +-\n> > > > > > > > > > > >   src/ipa/ipu3/algorithms/af.cpp                |  2 +-\n> > > > > > > > > > > >   src/libcamera/geometry.cpp                    | 85\n> > > > > > > > > ++++++++++++++-----\n> > > > > > > > > > > >   .../pipeline/rpi/common/pipeline_base.cpp     |  4 +-\n> > > > > > > > > > > >   src/py/libcamera/py_geometry.cpp              |  2 +-\n> > > > > > > > > > > >   test/geometry.cpp                             |  8 +-\n> > > > > > > > > > > >   6 files changed, 75 insertions(+), 28 deletions(-)\n> > > > > > > > > > > >\n> > > > > > > > > > > > diff --git a/include/libcamera/geometry.h\n> > > > > > > > > b/include/libcamera/geometry.h\n> > > > > > > > > > > > index 3e6f0f5d7fab..07cb0a7866fe 100644\n> > > > > > > > > > > > --- a/include/libcamera/geometry.h\n> > > > > > > > > > > > +++ b/include/libcamera/geometry.h\n> > > > > > > > > > > > @@ -277,7 +277,7 @@ public:\n> > > > > > > > > > > >               return { width, height };\n> > > > > > > > > > > >       }\n> > > > > > > > > > > >\n> > > > > > > > > > > > -     Point topLeft() const\n> > > > > > > > > > > > +     Point origin() const\n> > > > > > > > > > > >       {\n> > > > > > > > > > > >               return { x, y };\n> > > > > > > > > > > >       }\n> > > > > > > > > > > > diff --git a/src/ipa/ipu3/algorithms/af.cpp\n> > > > > > > > > b/src/ipa/ipu3/algorithms/af.cpp\n> > > > > > > > > > > > index cf68fb59c49b..1b707e9dd9ab 100644\n> > > > > > > > > > > > --- a/src/ipa/ipu3/algorithms/af.cpp\n> > > > > > > > > > > > +++ b/src/ipa/ipu3/algorithms/af.cpp\n> > > > > > > > > > > > @@ -155,7 +155,7 @@ int Af::configure(IPAContext &context, const\n> > > > > > > > > IPAConfigInfo &configInfo)\n> > > > > > > > > > > >        * - Return the AF ROI as metadata in the Request\n> > > > > > > > > > > >        */\n> > > > > > > > > > > >       Rectangle roi = gridSize.centeredTo(bds.center());\n> > > > > > > > > > > > -     Point start = roi.topLeft();\n> > > > > > > > > > > > +     Point start = roi.origin();\n> > > > > > > > > > > >\n> > > > > > > > > > > >       /* x_start and y_start should be even */\n> > > > > > > > > > > >       grid.x_start = utils::alignDown(start.x, 2);\n> > > > > > > > > > > > diff --git a/src/libcamera/geometry.cpp\n> > > > > > > b/src/libcamera/geometry.cpp\n> > > > > > > > > > > > index 000151364c7f..45ba81a99920 100644\n> > > > > > > > > > > > --- a/src/libcamera/geometry.cpp\n> > > > > > > > > > > > +++ b/src/libcamera/geometry.cpp\n> > > > > > > > > > > > @@ -593,11 +593,39 @@ std::ostream &operator<<(std::ostream &out,\n> > > > > > > > > const SizeRange &sr)\n> > > > > > > > > > > >    * \\brief Describe a rectangle's position and dimensions\n> > > > > > > > > > > >    *\n> > > > > > > > > > > >    * Rectangles are used to identify an area of an image. They\n> > > > > > > are\n> > > > > > > > > specified by\n> > > > > > > > > > > > - * the coordinates of top-left corner and their horizontal and\n> > > > > > > > > vertical size.\n> > > > > > > > > > > > + * the coordinates of the corner closer to the reference\n> > > > > > > system's\n> > > > > > > > > origin point\n> > > > > > > > > > > > + * and by horizontal and vertical increments from there.\n> > > > > > > > > > > >    *\n> > > > > > > > > > > > - * The measure unit of the rectangle coordinates and size, as\n> > > > > > > well\n> > > > > > > > > as the\n> > > > > > > > > > > > - * reference point from which the Rectangle::x and Rectangle::y\n> > > > > > > > > displacements\n> > > > > > > > > > > > - * refers to, are defined by the context were rectangle is used.\n> > > > > > > > > > > > + * The corner closer to the reference system's origin point is\n> > > > > > > the\n> > > > > > > > > rectangle's\n> > > > > > > > > > > > + * origin corner.\n> > > > > > > > > > > > + *\n> > > > > > > > > > > > + * \\verbatim\n> > > > > > > > > > > > +\n> > > > > > > > > > > > +  o = origin corner\n> > > > > > > > > > > > +\n> > > > > > > > > > > > +         ^\n> > > > > > > > > > > > +         |\n> > > > > > > > > > > > +         |      -------------------\n> > > > > > > > > > > > +         |      ^                 |\n> > > > > > > > > > > > +         |      |                 |\n> > > > > > > > > > > > +         |      o---->-------------\n> > > > > > > > > > > > +         |\n> > > > > > > > > > > > +          ------------------------------->\n> > > > > > > > > > > > +         (0,0)\n> > > > > > > > > > > > +\n> > > > > > > > > > > > +         (0,0)\n> > > > > > > > > > > > +           ------------------------------->\n> > > > > > > > > > > > +          |\n> > > > > > > > > > > > +          |      o---->-------------\n> > > > > > > > > > > > +          |      |                 |\n> > > > > > > > > > > > +          |      v                 |\n> > > > > > > > > > > > +          |      -------------------\n> > > > > > > > > > > > +          |\n> > > > > > > > > > > > +          V\n> > > > > > > > > > > > +   \\endverbatim\n> > > > > > > > > > > > + *\n> > > > > > > > > > > > + * The measure unit of the rectangle coordinates and size are\n> > > > > > > > > defined by the\n> > > > > > > > > > > > + * context were the rectangle is used.\n> > > > > > > > > > > >    */\n> > > > > > > > > > > >\n> > > > > > > > > > > >   /**\n> > > > > > > > > > > > @@ -608,35 +636,50 @@ std::ostream &operator<<(std::ostream &out,\n> > > > > > > > > const SizeRange &sr)\n> > > > > > > > > > > >   /**\n> > > > > > > > > > > >    * \\fn Rectangle::Rectangle(int x, int y, const Size &size)\n> > > > > > > > > > > >    * \\brief Construct a Rectangle with the given position and\n> > > > > > > size\n> > > > > > > > > > > > - * \\param[in] x The horizontal coordinate of the top-left corner\n> > > > > > > > > > > > - * \\param[in] y The vertical coordinate of the top-left corner\n> > > > > > > > > > > > + * \\param[in] x The horizontal coordinate of the origin corner\n> > > > > > > > > > > > + * \\param[in] y The vertical coordinate of the origin corner\n> > > > > > > > > > > >    * \\param[in] size The size\n> > > > > > > > > > > > + *\n> > > > > > > > > > > > + * The rectangle's origin corner is the corner closer to the\n> > > > > > > > > reference system\n> > > > > > > > > > > > + * origin point (0, 0).\n> > > > > > > > > >\n> > > > > > > > > > I think we should stick to the previous description:\n> > > > > > > > > > `\"origin\" point defined as the point with the lower x and\n> > > > > > > > > > lower y of the rectangle`, as `x` and `y` are signed integers.\n> > > > > > > > > >\n> > > > > > > > > > If we only support coordinates that are positive or 0, which\n> > > > > > > > > > I'm not sure if it's the case, how about making the type to be\n> > > > > > > > > > `unsigned int`?\n> > > > > > > > > >\n> > > > > > > > >\n> > > > > > > > > To be honest I would rather make width and heigh signed to allow\n> > > > > > > > > constructing (x, y, -w, -h)\n> > > > > > > > >\n> > > > > > > > >\n> > > > > > > > >\n> > > > > > > > >\n> > > > > > > > >                -------------------\n> > > > > > > > >                |                 ^\n> > > > > > > > >                |            ------------->\n> > > > > > > > >                |           |     |\n> > > > > > > > >                ------<-----|-----o\n> > > > > > > > >                            |\n> > > > > > > > >                            |\n> > > > > > > > >                            V\n> > > > > > > > >\n> > > > > > > > > Not sure if it's useful or not though\n> > > > > > > > >\n> > > > > > > >\n> > > > > > > > Hmm... I find it pretty weird. What if all four corners have all negative\n> > > > > > > > coordinates?\n> > > > > > > >\n> > > > > > > >\n> > > > > > >\n> > > > > > > Don't know, maybe if the reference system where the rectangle is used\n> > > > > > > into has 4 planes and so an all-negative rectangle makes sense.\n> > > > > > >\n> > > > > > > My point is that we should allow users of this class to express\n> > > > > > > Rectangle in any context they plan to use them. Not sure if I'm going\n> > > > > > > overboard here or it makes sense.\n> > > > > > >\n> > > > > >\n> > > > > > Yeah I agree, while doesn't that mean the description doesn't fit all\n> > > > > > cases, like the corner closer to the reference system origin point of a\n> > > > > > rectangle that has all negative coordinates is actually the \"bottom-right\"\n> > > > >\n> > > > > This patch aims to remove all references to \"top-left\" or in general\n> > > > > to any visual reference exactly for that purpose. Or have I forgot any\n> > > > > ?\n> > > >\n> > > > In this c'tor `\\fn Rectangle::Rectangle(int x, int y, const Size &size)`,\n> > > > the description of `x` and `y` are updated to \"coordinates of the origin\n> > > > corner\", where the origin corner is \"the corner closer to the reference\n> > > > system origin point (0, 0).\"\n> > > >\n> > > > As currently libcamera::Size takes only non-negative width and height,\n> > > > take rectangle [(-3, -3), (-3, -1), (-1, -3), (-1, -1)] as the example, you\n> > > > can find that the only valid way to construct this rectangle as\n> > > > libcamera::Rectangle is `{x = -3, y = -3, size = {2, 2}}`. However, this\n> > > > doesn't fit with your updated description, as the corner closer to the\n> > > > reference system origin point (0, 0) is actually (-1, -1), instead of\n> > > > (-3, -3).\n> > > >\n> > >\n> > > You're right. Let's take a step back though. If we have a 4 planes reference\n> > > system, we always have a visual top-left indeed. As the 4 planes have\n> > > negative and positive coordinates, we can describe with absolute\n> > > positions the rectangle and all points in the system.\n> >\n> > Sorry, I still don't get your point...\n> >\n>\n> If you have a 4 planes system\n>\n>                       ^\n>                       |\n>                       |\n>                       |\n>                       |\n>         <--------------------------->\n>                       |\n>                       |\n>                       |\n>                       |\n>                       V\n>\n> Then you always have a top, a left, and bottom and a right, you can\n> describe width and height as negative or positive increments and your\n> rectangle is always well defined as the reference system cannot be\n> ambiguous. The very concept of \"reference system orientation\" doesn't\n> make sense, as a 4-planes system describes the full 2-d space.\n>\n> The ambiguity I'm trying to solve is about using a 1 plane reference\n> system, as depending on how the system is oriented the definition of\n> the \"top-left\" point might change, as well as the definition of the\n> horizontal and vertical increments change as well.\n>\n> In example:\n>\n>                       ^\n>                       |\n>                       |\n>                       |  o-------\n>                       |  |      |\n>                       |  --------\n>                       |\n>                       ------------------------>\n>\n>         top-left: Smaller x and higher y\n>         width: positive increment\n>         height: negative increment\n>\n>\n>\n>\n>                       ------------------------>\n>                       |  o-------\n>                       |  |      |\n>                       |  --------\n>                       |\n>                       |\n>                       V\n>\n>         top-left: Smaller x and smaller y\n>         width: positive increment\n>         height: positive increment\n>\n>\n> I thought our Rectangle definition didn't make assumptions on the\n> reference's system orientation and in fact that's what part of the\n> documentation says, but indeed the usage of \"top-left\" is, as shown,\n> ambiguous.\n>\n> So I went and changed that to be the \"corner closer to the origin\n> point\" and specified in documentation that vertical and horizontal\n> increments are always positive and I thought I was done with this, but\n> then I made the mistake of talking about negative increments and\n> 4-plane systems and here we are.\n>\n>\n> > Do you mean that the new description, like\n> > `The horizontal coordinate of the rectangle's origin corner`,\n> > only fits with the 1-plane reference system? I thought it should fit all\n> > 2D reference systems.\n>\n> I don't think that has never been the case, but indeed we have a\n> constructor that takes \"signed\" x and y.\n\nIIUC, you mean `you don't think that has ever been the case`, right?\n\n>\n> To be honest I would not be concerned about 4-planes systems, we're\n> talking about imaging and what is relevant here is that we should be\n> allowed to express rectangles on reference systems that can be\n> oriented differently, think of a sensor's pixel array that might be\n> represented with the (0, 0) position in the top-left corner compared\n> to a plane 2-d image that usually has its origin in the bottom-left\n> corner.\n>\n> I have an hard time finding a use case for expressing negative\n> coordinates in this usage context. Furthermore that if we introduce 4\n> planes we lose the ability to describe systems with different\n> orientation, as this:\n>\n>                       ------------------------>\n>                       |  o-------\n>                       |  |      |\n>                       |  --------\n>                       |\n>                       |\n>                       V\n>\n> when expressed in a 4-planes system becomes\n>\n>                       ^\n>                       |\n>                       |\n>                       |\n>                       |\n>         <--------------------------->\n>                       |/////////////\n>                       |/////////////\n>                       |// this /////\n>                       |/////////////\n>                       |/////////////\n>                       V\n>\n> And would require you to express y and height in negative coordinates.\n> Sincerely, I would not go there.\n>\n> I can specify that the Rectangle class reference system is always a\n> 2-d plane with positively increasing x and y axes instead.\n\nYeah I think specifying that is a great idea, and maybe a TODO to\nset `x` and `y` to be unsigned int.\nI hope no pipeline handlers is using signed coordinates when we\nmake the change in the API.\n\nSorry for the chaos.\n\n>\n> >\n> > >\n> > > The problem at hands now is relevant for 1-planes reference systems,\n> > > that can be oriented differently, in example with the origin point\n> > > being in top-left or bottom-left positions, as per the examples above.\n> > > In this case I think we agree that \"top-left\" is ambiguous. The x and\n> > > y coordinates are always positive in the case with a single plane.\n> > >\n> > > I think we should also be concerned with 1 plane reference systems and\n> > > move forward with this patch that removes references to the visual\n> > > \"top-left\" and assumes increments in width and height are always\n> > > positive.\n> > >\n> > > > >\n> > > > > > corner, and currently libcamera::Size only allows non-negative width and\n> > > > > > height [1].\n> > > > >\n> > > > > True, Size uses unsigned int. I don't think it's a big deal and I'm\n> > > > > not proposing to introduce a new constructor with signed width and\n> > > > > height now, but my point is that if the need arises we can now do\n> > > > > that.\n> > > > >\n> > > > > >\n> > > > > > [1]:\n> > > > > > https://git.libcamera.org/libcamera/libcamera.git/tree/include/libcamera/geometry.h#n65\n> > > > > >\n> > > > > >\n> > > > > > > >\n> > > > > > > >\n> > > > > > > > >\n> > > > > > > > > > BR,\n> > > > > > > > > > Harvey\n> > > > > > > > > >\n> > > > > > > > > >\n> > > > > > > > > > > >    */\n> > > > > > > > > > > >\n> > > > > > > > > > > >   /**\n> > > > > > > > > > > >    * \\fn Rectangle::Rectangle(int x, int y, unsigned int width,\n> > > > > > > > > unsigned int height)\n> > > > > > > > > > > >    * \\brief Construct a Rectangle with the given position and\n> > > > > > > size\n> > > > > > > > > > > > - * \\param[in] x The horizontal coordinate of the top-left corner\n> > > > > > > > > > > > - * \\param[in] y The vertical coordinate of the top-left corner\n> > > > > > > > > > > > + * \\param[in] x The horizontal coordinate of the origin corner\n> > > > > > > > > > > > + * \\param[in] y The vertical coordinate of the origin corner\n> > > > > > > > > > > >    * \\param[in] width The width\n> > > > > > > > > > > >    * \\param[in] height The height\n> > > > > > > > > > > > + *\n> > > > > > > > > > > > + * The rectangle's origin corner is the corner closer to the\n> > > > > > > > > reference system\n> > > > > > > > > > > > + * origin point (0, 0).\n> > > > > > > > > > > >    */\n> > > > > > > > > > > >\n> > > > > > > > > > > >   /**\n> > > > > > > > > > > >    * \\fn Rectangle::Rectangle(const Size &size)\n> > > > > > > > > > > > - * \\brief Construct a Rectangle of \\a size with its top left\n> > > > > > > corner\n> > > > > > > > > located\n> > > > > > > > > > > > + * \\brief Construct a Rectangle of \\a size with its origin\n> > > > > > > corner\n> > > > > > > > > located\n> > > > > > > > > > > >    * at (0,0)\n> > > > > > > > > > > >    * \\param[in] size The desired Rectangle size\n> > > > > > > > > > > > + *\n> > > > > > > > > > > > + * The rectangle's origin corner is the corner closer to the\n> > > > > > > > > reference system\n> > > > > > > > > > > > + * origin point (0, 0).\n> > > > > > > > > > > >    */\n> > > > > > > > > > > >\n> > > > > > > > > > > >   /**\n> > > > > > > > > > > >    * \\var Rectangle::x\n> > > > > > > > > > > > - * \\brief The horizontal coordinate of the rectangle's top-left\n> > > > > > > > > corner\n> > > > > > > > > > > > + * \\brief The horizontal coordinate of the rectangle's origin\n> > > > > > > corner\n> > > > > > > > > > > > + *\n> > > > > > > > > > > > + * The rectangle's origin corner is the corner closer to the\n> > > > > > > > > reference system\n> > > > > > > > > > > > + * origin point (0, 0).\n> > > > > > > > > > > >    */\n> > > > > > > > > > > >\n> > > > > > > > > > > >   /**\n> > > > > > > > > > > >    * \\var Rectangle::y\n> > > > > > > > > > > > - * \\brief The vertical coordinate of the rectangle's top-left\n> > > > > > > corner\n> > > > > > > > > > > > + * \\brief The vertical coordinate of the rectangle's origin\n> > > > > > > corner\n> > > > > > > > > > > > + *\n> > > > > > > > > > > > + * The rectangle's origin corner is the corner closer to the\n> > > > > > > > > reference system\n> > > > > > > > > > > > + * origin point (0, 0).\n> > > > > > > > > > > >    */\n> > > > > > > > > > > >\n> > > > > > > > > > > >   /**\n> > > > > > > > > > > > @@ -683,9 +726,13 @@ Point Rectangle::center() const\n> > > > > > > > > > > >    */\n> > > > > > > > > > > >\n> > > > > > > > > > > >   /**\n> > > > > > > > > > > > - * \\fn Point Rectangle::topLeft() const\n> > > > > > > > > > > > - * \\brief Retrieve the coordinates of the top left corner of\n> > > > > > > this\n> > > > > > > > > Rectangle\n> > > > > > > > > > > > - * \\return The Rectangle's top left corner\n> > > > > > > > > > > > + * \\fn Point Rectangle::origin() const\n> > > > > > > > > > > > + * \\brief Retrieve the coordinates of the origin corner of this\n> > > > > > > > > Rectangle\n> > > > > > > > > > > > + *\n> > > > > > > > > > > > + * The rectangle's origin corner is the corner closer to the\n> > > > > > > > > reference system\n> > > > > > > > > > > > + * origin point (0, 0).\n> > > > > > > > > > > > + *\n> > > > > > > > > > > > + * \\return The Rectangle's origin corner\n> > > > > > > > > > >\n> > > > > > > > > > > I think you can drop \"corner\" from \"origin corner\"\n> > > > > > > > > > >\n> > > > > > > > > > > Probably throughout the patch:\n> > > > > > > > > > >      s/origin corner/origin/\n> > > > > > > > > > >\n> > > > > > > > > > > Otherwise, LGTM\n> > > > > > > > > > >\n> > > > > > > > > > > Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>\n> > > > > > > > > > > >    */\n> > > > > > > > > > > >\n> > > > > > > > > > > >   /**\n> > > > > > > > > > > > @@ -740,15 +787,15 @@ Rectangle &Rectangle::translateBy(const\n> > > > > > > Point\n> > > > > > > > > &point)\n> > > > > > > > > > > >    */\n> > > > > > > > > > > >   Rectangle Rectangle::boundedTo(const Rectangle &bound) const\n> > > > > > > > > > > >   {\n> > > > > > > > > > > > -     int topLeftX = std::max(x, bound.x);\n> > > > > > > > > > > > -     int topLeftY = std::max(y, bound.y);\n> > > > > > > > > > > > +     int originX = std::max(x, bound.x);\n> > > > > > > > > > > > +     int originY = std::max(y, bound.y);\n> > > > > > > > > > > >       int bottomRightX = std::min<int>(x + width, bound.x +\n> > > > > > > > > bound.width);\n> > > > > > > > > > > >       int bottomRightY = std::min<int>(y + height, bound.y +\n> > > > > > > > > bound.height);\n> > > > > > > > > > > >\n> > > > > > > > > > > > -     unsigned int newWidth = std::max(bottomRightX - topLeftX,\n> > > > > > > 0);\n> > > > > > > > > > > > -     unsigned int newHeight = std::max(bottomRightY - topLeftY,\n> > > > > > > 0);\n> > > > > > > > > > > > +     unsigned int newWidth = std::max(bottomRightX - originX,\n> > > > > > > 0);\n> > > > > > > > > > > > +     unsigned int newHeight = std::max(bottomRightY - originY,\n> > > > > > > 0);\n> > > > > > > > > > > >\n> > > > > > > > > > > > -     return { topLeftX, topLeftY, newWidth, newHeight };\n> > > > > > > > > > > > +     return { originX, originY, newWidth, newHeight };\n> > > > > > > > > > > >   }\n> > > > > > > > > > > >\n> > > > > > > > > > > >   /**\n> > > > > > > > > > > > diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n> > > > > > > > > b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n> > > > > > > > > > > > index 3041fd1ed9fd..8d2440026689 100644\n> > > > > > > > > > > > --- a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n> > > > > > > > > > > > +++ b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n> > > > > > > > > > > > @@ -1289,7 +1289,7 @@ Rectangle CameraData::scaleIspCrop(const\n> > > > > > > > > Rectangle &ispCrop) const\n> > > > > > > > > > > >        */\n> > > > > > > > > > > >       Rectangle nativeCrop =\n> > > > > > > > > ispCrop.scaledBy(sensorInfo_.analogCrop.size(),\n> > > > > > > > > > > >\n> > > > > > > > >  sensorInfo_.outputSize);\n> > > > > > > > > > > > -     nativeCrop.translateBy(sensorInfo_.analogCrop.topLeft());\n> > > > > > > > > > > > +     nativeCrop.translateBy(sensorInfo_.analogCrop.origin());\n> > > > > > > > > > > >       return nativeCrop;\n> > > > > > > > > > > >   }\n> > > > > > > > > > > >\n> > > > > > > > > > > > @@ -1303,7 +1303,7 @@ void CameraData::applyScalerCrop(const\n> > > > > > > > > ControlList &controls)\n> > > > > > > > > > > >                       nativeCrop = { 0, 0, 1, 1 };\n> > > > > > > > > > > >\n> > > > > > > > > > > >               /* Create a version of the crop scaled to ISP\n> > > > > > > (camera\n> > > > > > > > > mode) pixels. */\n> > > > > > > > > > > > -             Rectangle ispCrop =\n> > > > > > > > > nativeCrop.translatedBy(-sensorInfo_.analogCrop.topLeft());\n> > > > > > > > > > > > +             Rectangle ispCrop =\n> > > > > > > > > nativeCrop.translatedBy(-sensorInfo_.analogCrop.origin());\n> > > > > > > > > > > >               ispCrop.scaleBy(sensorInfo_.outputSize,\n> > > > > > > > > sensorInfo_.analogCrop.size());\n> > > > > > > > > > > >\n> > > > > > > > > > > >               /*\n> > > > > > > > > > > > diff --git a/src/py/libcamera/py_geometry.cpp\n> > > > > > > > > b/src/py/libcamera/py_geometry.cpp\n> > > > > > > > > > > > index c7e303609427..8dee365b25dd 100644\n> > > > > > > > > > > > --- a/src/py/libcamera/py_geometry.cpp\n> > > > > > > > > > > > +++ b/src/py/libcamera/py_geometry.cpp\n> > > > > > > > > > > > @@ -105,7 +105,7 @@ void init_py_geometry(py::module &m)\n> > > > > > > > > > > >               .def_property_readonly(\"is_null\",\n> > > > > > > &Rectangle::isNull)\n> > > > > > > > > > > >               .def_property_readonly(\"center\",\n> > > > > > > &Rectangle::center)\n> > > > > > > > > > > >               .def_property_readonly(\"size\", &Rectangle::size)\n> > > > > > > > > > > > -             .def_property_readonly(\"topLeft\",\n> > > > > > > &Rectangle::topLeft)\n> > > > > > > > > > > > +             .def_property_readonly(\"origin\",\n> > > > > > > &Rectangle::origin)\n> > > > > > > > > > > >               .def(\"scale_by\", &Rectangle::scaleBy)\n> > > > > > > > > > > >               .def(\"translate_by\", &Rectangle::translateBy)\n> > > > > > > > > > > >               .def(\"bounded_to\", &Rectangle::boundedTo)\n> > > > > > > > > > > > diff --git a/test/geometry.cpp b/test/geometry.cpp\n> > > > > > > > > > > > index 64169206ad16..a4ee6f6e167a 100644\n> > > > > > > > > > > > --- a/test/geometry.cpp\n> > > > > > > > > > > > +++ b/test/geometry.cpp\n> > > > > > > > > > > > @@ -363,16 +363,16 @@ protected:\n> > > > > > > > > > > >                       return TestFail;\n> > > > > > > > > > > >               }\n> > > > > > > > > > > >\n> > > > > > > > > > > > -             /* Rectangle::size(), Rectangle::topLeft() and\n> > > > > > > > > Rectangle::center() tests */\n> > > > > > > > > > > > +             /* Rectangle::size(), Rectangle::origin() and\n> > > > > > > > > Rectangle::center() tests */\n> > > > > > > > > > > >               if (Rectangle(-1, -2, 3, 4).size() != Size(3, 4) ||\n> > > > > > > > > > > >                   Rectangle(0, 0, 100000, 200000).size() !=\n> > > > > > > > > Size(100000, 200000)) {\n> > > > > > > > > > > >                       cout << \"Rectangle::size() test failed\" <<\n> > > > > > > > > endl;\n> > > > > > > > > > > >                       return TestFail;\n> > > > > > > > > > > >               }\n> > > > > > > > > > > >\n> > > > > > > > > > > > -             if (Rectangle(1, 2, 3, 4).topLeft() != Point(1, 2)\n> > > > > > > ||\n> > > > > > > > > > > > -                 Rectangle(-1, -2, 3, 4).topLeft() != Point(-1,\n> > > > > > > > > -2)) {\n> > > > > > > > > > > > -                     cout << \"Rectangle::topLeft() test failed\"\n> > > > > > > <<\n> > > > > > > > > endl;\n> > > > > > > > > > > > +             if (Rectangle(1, 2, 3, 4).origin() != Point(1, 2)\n> > > > > > > ||\n> > > > > > > > > > > > +                 Rectangle(-1, -2, 3, 4).origin() != Point(-1,\n> > > > > > > -2))\n> > > > > > > > > {\n> > > > > > > > > > > > +                     cout << \"Rectangle::origin() test failed\"\n> > > > > > > <<\n> > > > > > > > > endl;\n> > > > > > > > > > > >                       return TestFail;\n> > > > > > > > > > > >               }\n> > > > > > > > > > > >\n> > > > > > > > > > > > --\n> > > > > > > > > > > > 2.46.1\n> > > > > > > > > > > >\n> > > > > > > > > > >\n> > > > > > > > > >\n> > > > > > > > > >\n> > > > > > > > > > --\n> > > > > > > > > > BR,\n> > > > > > > > > > Harvey Yang\n> > > > > > > > >\n> > > > > > >\n> > > >\n> > > >\n> > > >\n> > > > --\n> > > > BR,\n> > > > Harvey Yang\n> >\n> >\n> >\n> > --\n> > BR,\n> > Harvey Yang","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 3AC09C3257\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 27 Sep 2024 08:46:48 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 2B2166350F;\n\tFri, 27 Sep 2024 10:46:47 +0200 (CEST)","from mail-lf1-x129.google.com (mail-lf1-x129.google.com\n\t[IPv6:2a00:1450:4864:20::129])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 41805618DB\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 27 Sep 2024 10:46:45 +0200 (CEST)","by mail-lf1-x129.google.com with SMTP id\n\t2adb3069b0e04-536552fcc07so13716e87.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 27 Sep 2024 01:46:45 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key;\n\tunprotected) header.d=google.com header.i=@google.com\n\theader.b=\"qlEEI3wh\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=google.com; s=20230601; t=1727426804; x=1728031604;\n\tdarn=lists.libcamera.org; \n\th=content-transfer-encoding:cc:to:subject:message-id:date:from\n\t:in-reply-to:references:mime-version:from:to:cc:subject:date\n\t:message-id:reply-to;\n\tbh=5wXF3rFLe7b4HU1GJ3AcQ1u6+NN3aOcCNwT1GLvXqnY=;\n\tb=qlEEI3wh5qTIWIpNn7G7zNP6VQ7dzmXniNPo7R7QhSjFAzNdKrEPOgA4QxUlj24Iue\n\tPl75Y6YlZfvKta+hoF19PcrkzNFSvQfuj8rrjd7O7oapkJMAd8lK5kqu4eppdb+4FrDF\n\tArgAMN8YCmtj6gxTSRjURxx3jLWNSIJ8jGTeHp7THhhyPSX53o1dOb/hW336XeSf9TDg\n\tT6Tzu2RNL1F721jg1qHIqsE7z3q5p7YO80cgNgPeRroIxkd9sF9Okg5XhrJxVHsIjiTc\n\tiKiWCWez46ePK+2n/7I423UU7OWQGIeD+cAqx6mkGO7AeYnqOSQmr0c/Zfu3aglcVIet\n\t/rNA==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1727426804; x=1728031604;\n\th=content-transfer-encoding:cc:to:subject:message-id:date:from\n\t:in-reply-to:references:mime-version:x-gm-message-state:from:to:cc\n\t:subject:date:message-id:reply-to;\n\tbh=5wXF3rFLe7b4HU1GJ3AcQ1u6+NN3aOcCNwT1GLvXqnY=;\n\tb=AP2nr5jSM2CDyxt5v1A6SmRlZtuUpi/lGQr2s2T0zQbIQZmTutbiI9DIPCjTMoZCar\n\tWXnMD7/aoGEan5SusJpo02RHVTMsSM15G1MQE4p/nes6fbRn4uR9SfpPmPz4lFAQyu6N\n\tpfqJGBGC7yLUJ70UwZDstsqSQjE9fClXbaUEqV/2wWfTH/T1dIP1pc0pemwjGrdvIzcD\n\thlocxCu5zodLyLBmgvbqxTNzlUA7CHeNShj+sZ4+sVfplC6E9CaEJgfYb94dhuXQ5bup\n\tAtisNmk8BfgTTD+yQX7VeVcLDAmUyRVWN2EXiqUpAxLzS+vYFXC3AWrq/hexrsPemrBT\n\tX9Fg==","X-Forwarded-Encrypted":"i=1;\n\tAJvYcCVGSEvu+kMj18rpdg9YZr9wYBIPvlcrAE82exSskxZZdunMMS+XJgvUWEGjzA4h9JfnBDdLZKz2dLag10/3BM8=@lists.libcamera.org","X-Gm-Message-State":"AOJu0YyqJbeQh49fCI3hPHwYf7iyBRxvqyzlFueqUTNKPhb+Fa46gUb1\n\t7e+Lm+wB2hGUVn5dGPiSKyxhB5gb9GjDpV0Xs2pOwEIfMMvGs3zhPk5mdiRQGENd47qD0HMYD8y\n\tYkojK58kVvEbu8uL12AJ9MhHW+YW8/Gazox+v2W+ZlO2GZYns+g==","X-Google-Smtp-Source":"AGHT+IHyV+DI65mwPCci1RLTs7bN3+oMWx9suC0d6UnXmTS3pVzOHHNDmpQUNI7arDbGdtL3MG/YVHkZZ+Hbpuem5x8=","X-Received":"by 2002:a05:6512:2253:b0:536:52dc:291d with SMTP id\n\t2adb3069b0e04-5394ba866a9mr238342e87.1.1727426803986; Fri, 27 Sep 2024\n\t01:46:43 -0700 (PDT)","MIME-Version":"1.0","References":"<d975583c-7f5d-4f5b-8e99-5cdc61396667@ideasonboard.com>\n\t<CAC=wSGUwXZDvM68ZfhqPvYKhAB0bkem=zJhFJ-Fjafc9OYhDqA@mail.gmail.com>\n\t<uzptnxdipytxx4nwqusnr62asaiwrdawylf2f3vzbmkc53onhc@nkeomtxtfw5g>\n\t<CAC=wSGWEZU7_=nEFTp+g_g74L7kcs65wK3oOeS8xwBqzMHa5wQ@mail.gmail.com>\n\t<zsszrdewqlrlovncquphk43ajxyksfoijoiorglvwem4kb2u6q@my2gscqpdzd3>\n\t<CAC=wSGXj==p2GZMidtwb9pUhmnuRrdqbGhQUF14HSNfTzgz_Cw@mail.gmail.com>\n\t<62yvkiqioilupdcm7ryjtrz273iamzojfi2pgxndmjwoyyaitb@iq46e47ke2vg>\n\t<CAC=wSGXgYv2YyZqwgRANhmVzPtLTkTHP4=R-_Sz+NE7wNzPJXw@mail.gmail.com>\n\t<6cnkhto53ixz7hafosgqebixvfdpwftc24ach46wsvv6qpjmkv@h7e25hene6yc>\n\t<CAC=wSGU3ubNji42mp-4eXH7L34ZZE0vP_NA5Uu1fKgUsQTvG7Q@mail.gmail.com>\n\t<juj2axmwzwss5axiy3y6l4hetonuv72oyzgb6ekf5hbt66it73@j23uammf6fl7>","In-Reply-To":"<juj2axmwzwss5axiy3y6l4hetonuv72oyzgb6ekf5hbt66it73@j23uammf6fl7>","From":"Cheng-Hao Yang <chenghaoyang@google.com>","Date":"Fri, 27 Sep 2024 16:46:06 +0800","Message-ID":"<CAC=wSGVEjJ-fHo4W31OGU2Qk8=OhhzYNCW4qFxqLLdtTu0kGrw@mail.gmail.com>","Subject":"Re: [PATCH] libcamera: geometry: Rename Rectangle's top-left corner","To":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>","Cc":"Umang Jain <umang.jain@ideasonboard.com>, \n\tlibcamera devel <libcamera-devel@lists.libcamera.org>","Content-Type":"text/plain; charset=\"UTF-8\"","Content-Transfer-Encoding":"quoted-printable","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>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":31438,"web_url":"https://patchwork.libcamera.org/comment/31438/","msgid":"<cdtdrnjxni6trvlsmejd24ihlbujtqo4sxq4x7gwktitzua4rz@msm5if6yuae5>","date":"2024-09-27T08:54:20","subject":"Re: [PATCH] libcamera: geometry: Rename Rectangle's top-left corner","submitter":{"id":143,"url":"https://patchwork.libcamera.org/api/people/143/","name":"Jacopo Mondi","email":"jacopo.mondi@ideasonboard.com"},"content":"Hi Harvey\n\nOn Fri, Sep 27, 2024 at 04:46:06PM GMT, Cheng-Hao Yang wrote:\n> Hi Jacopo,\n>\n> On Fri, Sep 27, 2024 at 4:05 PM Jacopo Mondi\n> <jacopo.mondi@ideasonboard.com> wrote:\n> >\n> > Hi Harvey\n> >\n> > On Thu, Sep 26, 2024 at 11:22:58PM GMT, Cheng-Hao Yang wrote:\n> > > Hi Jacopo,\n> > >\n> > > On Thu, Sep 26, 2024 at 10:35 PM Jacopo Mondi\n> > > <jacopo.mondi@ideasonboard.com> wrote:\n> > > >\n> > > > Hi Harvey\n> > > >\n> > > > On Thu, Sep 26, 2024 at 10:03:55PM GMT, Cheng-Hao Yang wrote:\n> > > > > Hi Jacopo,\n> > > > >\n> > > > > On Thu, Sep 26, 2024 at 5:36 PM Jacopo Mondi\n> > > > > <jacopo.mondi@ideasonboard.com> wrote:\n> > > > > >\n> > > > > > Hi Harvey\n> > > > > >\n> > > > > > On Thu, Sep 26, 2024 at 05:28:13PM GMT, Cheng-Hao Yang wrote:\n> > > > > > > Hi Jacopo,\n> > > > > > >\n> > > > > > >\n> > > > > > >\n> > > > > > > On Thu, Sep 26, 2024, 4:38 PM Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n> > > > > > > wrote:\n> > > > > > >\n> > > > > > > > Hi Harvey\n> > > > > > > >\n> > > > > > > > On Thu, Sep 26, 2024 at 04:29:50PM GMT, Cheng-Hao Yang wrote:\n> > > > > > > > > Hi Jacopo,\n> > > > > > > > >\n> > > > > > > > > On Thu, Sep 26, 2024, 4:03 PM Jacopo Mondi <\n> > > > > > > > jacopo.mondi@ideasonboard.com>\n> > > > > > > > > wrote:\n> > > > > > > > >\n> > > > > > > > > > Hi Harvey\n> > > > > > > > > >\n> > > > > > > > > > On Wed, Sep 25, 2024 at 03:09:38PM GMT, Cheng-Hao Yang wrote:\n> > > > > > > > > > > Hi Jacopo,\n> > > > > > > > > > >\n> > > > > > > > > > > Thank you for the patch.\n> > > > > > > > > > >\n> > > > > > > > > > > On Wed, Sep 25, 2024 at 2:36 PM Umang Jain <\n> > > > > > > > umang.jain@ideasonboard.com>\n> > > > > > > > > > wrote:\n> > > > > > > > > > > >\n> > > > > > > > > > > > Hi Jacopo\n> > > > > > > > > > > >\n> > > > > > > > > > > > Thank you for the patch\n> > > > > > > > > > > >\n> > > > > > > > > > > > On 24/09/24 6:15 pm, Jacopo Mondi wrote:\n> > > > > > > > > > > > > The libcamera::Rectangle class should allow defining rectangles\n> > > > > > > > > > > > > regardless of the reference system where an instance is used in.\n> > > > > > > > > > > > >\n> > > > > > > > > > > > > However the class documentation assumes the reference system\n> > > > > > > > origin\n> > > > > > > > > > > > > point to be in the visual top-left side and that rectangles are\n> > > > > > > > > > > > > constructed by specifying the top-left corner position and sizes.\n> > > > > > > > > > > > >\n> > > > > > > > > > > > > However this is ambiguous when using a different reference\n> > > > > > > > system as,\n> > > > > > > > > > > > > in example, constructing a rectangle (x, y, w, h) in the\n> > > > > > > > following\n> > > > > > > > > > > > > scenario, with the origin corner in the top-left position, would\n> > > > > > > > > > require\n> > > > > > > > > > > > > a negative decrement along the y-axis.\n> > > > > > > > > > > > >\n> > > > > > > > > > > > >           ^\n> > > > > > > > > > > > >           |\n> > > > > > > > > > > > >          y|      o------------------\n> > > > > > > > > > > > >           |      |                 | h\n> > > > > > > > > > > > >           |      |                 |\n> > > > > > > > > > > > >           |      -------------------\n> > > > > > > > > > > > >           |               w\n> > > > > > > > > > > > >            ------------------------------->\n> > > > > > > > > > > > >           (0,0)  x\n> > > > > > > > > > > > >\n> > > > > > > > > > > > > To remove ambiguities, drop references to the visual top-left\n> > > > > > > > corner\n> > > > > > > > > > and\n> > > > > > > > > > > > > define the rectangle's origin corner as the corner closer to the\n> > > > > > > > > > > > > reference system origin point, and specify the horizontal and\n> > > > > > > > > > vertical\n> > > > > > > > > > > > > dimensions always increment along their respective axis, as in\n> > > > > > > > the\n> > > > > > > > > > > > > following example.\n> > > > > > > > > > > > >\n> > > > > > > > > > > > >           ^\n> > > > > > > > > > > > >           |\n> > > > > > > > > > > > >           |      -------------------\n> > > > > > > > > > > > >           |      ^                 | h\n> > > > > > > > > > > > >           |      |                 |\n> > > > > > > > > > > > >          y|      o---->-------------\n> > > > > > > > > > > > >           |               w\n> > > > > > > > > > > > >            ------------------------------->\n> > > > > > > > > > > > >           (0,0)  x\n> > > > > > > > > > > > >\n> > > > > > > > > > > > >           (0,0)  x\n> > > > > > > > > > > > >             ------------------------------>\n> > > > > > > > > > > > >            |              w\n> > > > > > > > > > > > >           y|     o---->-------------\n> > > > > > > > > > > > >            |     |                 | h\n> > > > > > > > > > > > >            |     v                 |\n> > > > > > > > > > > > >            |     -------------------\n> > > > > > > > > > > > >            |\n> > > > > > > > > > > > >            V\n> > > > > > > > > > > > >\n> > > > > > > > > > > > > Also rename for consistency the Rectangle::topLeft() function to\n> > > > > > > > > > > > > Rectangle::origin() and update its in-tree users.\n> > > > > > > > > > > > >\n> > > > > > > > > > > > > Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n> > > > > > > > > > > > > ---\n> > > > > > > > > > > > >   include/libcamera/geometry.h                  |  2 +-\n> > > > > > > > > > > > >   src/ipa/ipu3/algorithms/af.cpp                |  2 +-\n> > > > > > > > > > > > >   src/libcamera/geometry.cpp                    | 85\n> > > > > > > > > > ++++++++++++++-----\n> > > > > > > > > > > > >   .../pipeline/rpi/common/pipeline_base.cpp     |  4 +-\n> > > > > > > > > > > > >   src/py/libcamera/py_geometry.cpp              |  2 +-\n> > > > > > > > > > > > >   test/geometry.cpp                             |  8 +-\n> > > > > > > > > > > > >   6 files changed, 75 insertions(+), 28 deletions(-)\n> > > > > > > > > > > > >\n> > > > > > > > > > > > > diff --git a/include/libcamera/geometry.h\n> > > > > > > > > > b/include/libcamera/geometry.h\n> > > > > > > > > > > > > index 3e6f0f5d7fab..07cb0a7866fe 100644\n> > > > > > > > > > > > > --- a/include/libcamera/geometry.h\n> > > > > > > > > > > > > +++ b/include/libcamera/geometry.h\n> > > > > > > > > > > > > @@ -277,7 +277,7 @@ public:\n> > > > > > > > > > > > >               return { width, height };\n> > > > > > > > > > > > >       }\n> > > > > > > > > > > > >\n> > > > > > > > > > > > > -     Point topLeft() const\n> > > > > > > > > > > > > +     Point origin() const\n> > > > > > > > > > > > >       {\n> > > > > > > > > > > > >               return { x, y };\n> > > > > > > > > > > > >       }\n> > > > > > > > > > > > > diff --git a/src/ipa/ipu3/algorithms/af.cpp\n> > > > > > > > > > b/src/ipa/ipu3/algorithms/af.cpp\n> > > > > > > > > > > > > index cf68fb59c49b..1b707e9dd9ab 100644\n> > > > > > > > > > > > > --- a/src/ipa/ipu3/algorithms/af.cpp\n> > > > > > > > > > > > > +++ b/src/ipa/ipu3/algorithms/af.cpp\n> > > > > > > > > > > > > @@ -155,7 +155,7 @@ int Af::configure(IPAContext &context, const\n> > > > > > > > > > IPAConfigInfo &configInfo)\n> > > > > > > > > > > > >        * - Return the AF ROI as metadata in the Request\n> > > > > > > > > > > > >        */\n> > > > > > > > > > > > >       Rectangle roi = gridSize.centeredTo(bds.center());\n> > > > > > > > > > > > > -     Point start = roi.topLeft();\n> > > > > > > > > > > > > +     Point start = roi.origin();\n> > > > > > > > > > > > >\n> > > > > > > > > > > > >       /* x_start and y_start should be even */\n> > > > > > > > > > > > >       grid.x_start = utils::alignDown(start.x, 2);\n> > > > > > > > > > > > > diff --git a/src/libcamera/geometry.cpp\n> > > > > > > > b/src/libcamera/geometry.cpp\n> > > > > > > > > > > > > index 000151364c7f..45ba81a99920 100644\n> > > > > > > > > > > > > --- a/src/libcamera/geometry.cpp\n> > > > > > > > > > > > > +++ b/src/libcamera/geometry.cpp\n> > > > > > > > > > > > > @@ -593,11 +593,39 @@ std::ostream &operator<<(std::ostream &out,\n> > > > > > > > > > const SizeRange &sr)\n> > > > > > > > > > > > >    * \\brief Describe a rectangle's position and dimensions\n> > > > > > > > > > > > >    *\n> > > > > > > > > > > > >    * Rectangles are used to identify an area of an image. They\n> > > > > > > > are\n> > > > > > > > > > specified by\n> > > > > > > > > > > > > - * the coordinates of top-left corner and their horizontal and\n> > > > > > > > > > vertical size.\n> > > > > > > > > > > > > + * the coordinates of the corner closer to the reference\n> > > > > > > > system's\n> > > > > > > > > > origin point\n> > > > > > > > > > > > > + * and by horizontal and vertical increments from there.\n> > > > > > > > > > > > >    *\n> > > > > > > > > > > > > - * The measure unit of the rectangle coordinates and size, as\n> > > > > > > > well\n> > > > > > > > > > as the\n> > > > > > > > > > > > > - * reference point from which the Rectangle::x and Rectangle::y\n> > > > > > > > > > displacements\n> > > > > > > > > > > > > - * refers to, are defined by the context were rectangle is used.\n> > > > > > > > > > > > > + * The corner closer to the reference system's origin point is\n> > > > > > > > the\n> > > > > > > > > > rectangle's\n> > > > > > > > > > > > > + * origin corner.\n> > > > > > > > > > > > > + *\n> > > > > > > > > > > > > + * \\verbatim\n> > > > > > > > > > > > > +\n> > > > > > > > > > > > > +  o = origin corner\n> > > > > > > > > > > > > +\n> > > > > > > > > > > > > +         ^\n> > > > > > > > > > > > > +         |\n> > > > > > > > > > > > > +         |      -------------------\n> > > > > > > > > > > > > +         |      ^                 |\n> > > > > > > > > > > > > +         |      |                 |\n> > > > > > > > > > > > > +         |      o---->-------------\n> > > > > > > > > > > > > +         |\n> > > > > > > > > > > > > +          ------------------------------->\n> > > > > > > > > > > > > +         (0,0)\n> > > > > > > > > > > > > +\n> > > > > > > > > > > > > +         (0,0)\n> > > > > > > > > > > > > +           ------------------------------->\n> > > > > > > > > > > > > +          |\n> > > > > > > > > > > > > +          |      o---->-------------\n> > > > > > > > > > > > > +          |      |                 |\n> > > > > > > > > > > > > +          |      v                 |\n> > > > > > > > > > > > > +          |      -------------------\n> > > > > > > > > > > > > +          |\n> > > > > > > > > > > > > +          V\n> > > > > > > > > > > > > +   \\endverbatim\n> > > > > > > > > > > > > + *\n> > > > > > > > > > > > > + * The measure unit of the rectangle coordinates and size are\n> > > > > > > > > > defined by the\n> > > > > > > > > > > > > + * context were the rectangle is used.\n> > > > > > > > > > > > >    */\n> > > > > > > > > > > > >\n> > > > > > > > > > > > >   /**\n> > > > > > > > > > > > > @@ -608,35 +636,50 @@ std::ostream &operator<<(std::ostream &out,\n> > > > > > > > > > const SizeRange &sr)\n> > > > > > > > > > > > >   /**\n> > > > > > > > > > > > >    * \\fn Rectangle::Rectangle(int x, int y, const Size &size)\n> > > > > > > > > > > > >    * \\brief Construct a Rectangle with the given position and\n> > > > > > > > size\n> > > > > > > > > > > > > - * \\param[in] x The horizontal coordinate of the top-left corner\n> > > > > > > > > > > > > - * \\param[in] y The vertical coordinate of the top-left corner\n> > > > > > > > > > > > > + * \\param[in] x The horizontal coordinate of the origin corner\n> > > > > > > > > > > > > + * \\param[in] y The vertical coordinate of the origin corner\n> > > > > > > > > > > > >    * \\param[in] size The size\n> > > > > > > > > > > > > + *\n> > > > > > > > > > > > > + * The rectangle's origin corner is the corner closer to the\n> > > > > > > > > > reference system\n> > > > > > > > > > > > > + * origin point (0, 0).\n> > > > > > > > > > >\n> > > > > > > > > > > I think we should stick to the previous description:\n> > > > > > > > > > > `\"origin\" point defined as the point with the lower x and\n> > > > > > > > > > > lower y of the rectangle`, as `x` and `y` are signed integers.\n> > > > > > > > > > >\n> > > > > > > > > > > If we only support coordinates that are positive or 0, which\n> > > > > > > > > > > I'm not sure if it's the case, how about making the type to be\n> > > > > > > > > > > `unsigned int`?\n> > > > > > > > > > >\n> > > > > > > > > >\n> > > > > > > > > > To be honest I would rather make width and heigh signed to allow\n> > > > > > > > > > constructing (x, y, -w, -h)\n> > > > > > > > > >\n> > > > > > > > > >\n> > > > > > > > > >\n> > > > > > > > > >\n> > > > > > > > > >                -------------------\n> > > > > > > > > >                |                 ^\n> > > > > > > > > >                |            ------------->\n> > > > > > > > > >                |           |     |\n> > > > > > > > > >                ------<-----|-----o\n> > > > > > > > > >                            |\n> > > > > > > > > >                            |\n> > > > > > > > > >                            V\n> > > > > > > > > >\n> > > > > > > > > > Not sure if it's useful or not though\n> > > > > > > > > >\n> > > > > > > > >\n> > > > > > > > > Hmm... I find it pretty weird. What if all four corners have all negative\n> > > > > > > > > coordinates?\n> > > > > > > > >\n> > > > > > > > >\n> > > > > > > >\n> > > > > > > > Don't know, maybe if the reference system where the rectangle is used\n> > > > > > > > into has 4 planes and so an all-negative rectangle makes sense.\n> > > > > > > >\n> > > > > > > > My point is that we should allow users of this class to express\n> > > > > > > > Rectangle in any context they plan to use them. Not sure if I'm going\n> > > > > > > > overboard here or it makes sense.\n> > > > > > > >\n> > > > > > >\n> > > > > > > Yeah I agree, while doesn't that mean the description doesn't fit all\n> > > > > > > cases, like the corner closer to the reference system origin point of a\n> > > > > > > rectangle that has all negative coordinates is actually the \"bottom-right\"\n> > > > > >\n> > > > > > This patch aims to remove all references to \"top-left\" or in general\n> > > > > > to any visual reference exactly for that purpose. Or have I forgot any\n> > > > > > ?\n> > > > >\n> > > > > In this c'tor `\\fn Rectangle::Rectangle(int x, int y, const Size &size)`,\n> > > > > the description of `x` and `y` are updated to \"coordinates of the origin\n> > > > > corner\", where the origin corner is \"the corner closer to the reference\n> > > > > system origin point (0, 0).\"\n> > > > >\n> > > > > As currently libcamera::Size takes only non-negative width and height,\n> > > > > take rectangle [(-3, -3), (-3, -1), (-1, -3), (-1, -1)] as the example, you\n> > > > > can find that the only valid way to construct this rectangle as\n> > > > > libcamera::Rectangle is `{x = -3, y = -3, size = {2, 2}}`. However, this\n> > > > > doesn't fit with your updated description, as the corner closer to the\n> > > > > reference system origin point (0, 0) is actually (-1, -1), instead of\n> > > > > (-3, -3).\n> > > > >\n> > > >\n> > > > You're right. Let's take a step back though. If we have a 4 planes reference\n> > > > system, we always have a visual top-left indeed. As the 4 planes have\n> > > > negative and positive coordinates, we can describe with absolute\n> > > > positions the rectangle and all points in the system.\n> > >\n> > > Sorry, I still don't get your point...\n> > >\n> >\n> > If you have a 4 planes system\n> >\n> >                       ^\n> >                       |\n> >                       |\n> >                       |\n> >                       |\n> >         <--------------------------->\n> >                       |\n> >                       |\n> >                       |\n> >                       |\n> >                       V\n> >\n> > Then you always have a top, a left, and bottom and a right, you can\n> > describe width and height as negative or positive increments and your\n> > rectangle is always well defined as the reference system cannot be\n> > ambiguous. The very concept of \"reference system orientation\" doesn't\n> > make sense, as a 4-planes system describes the full 2-d space.\n> >\n> > The ambiguity I'm trying to solve is about using a 1 plane reference\n> > system, as depending on how the system is oriented the definition of\n> > the \"top-left\" point might change, as well as the definition of the\n> > horizontal and vertical increments change as well.\n> >\n> > In example:\n> >\n> >                       ^\n> >                       |\n> >                       |\n> >                       |  o-------\n> >                       |  |      |\n> >                       |  --------\n> >                       |\n> >                       ------------------------>\n> >\n> >         top-left: Smaller x and higher y\n> >         width: positive increment\n> >         height: negative increment\n> >\n> >\n> >\n> >\n> >                       ------------------------>\n> >                       |  o-------\n> >                       |  |      |\n> >                       |  --------\n> >                       |\n> >                       |\n> >                       V\n> >\n> >         top-left: Smaller x and smaller y\n> >         width: positive increment\n> >         height: positive increment\n> >\n> >\n> > I thought our Rectangle definition didn't make assumptions on the\n> > reference's system orientation and in fact that's what part of the\n> > documentation says, but indeed the usage of \"top-left\" is, as shown,\n> > ambiguous.\n> >\n> > So I went and changed that to be the \"corner closer to the origin\n> > point\" and specified in documentation that vertical and horizontal\n> > increments are always positive and I thought I was done with this, but\n> > then I made the mistake of talking about negative increments and\n> > 4-plane systems and here we are.\n> >\n> >\n> > > Do you mean that the new description, like\n> > > `The horizontal coordinate of the rectangle's origin corner`,\n> > > only fits with the 1-plane reference system? I thought it should fit all\n> > > 2D reference systems.\n> >\n> > I don't think that has never been the case, but indeed we have a\n> > constructor that takes \"signed\" x and y.\n>\n> IIUC, you mean `you don't think that has ever been the case`, right?\n>\n\n\nNo, I meant \"I don't think the Rectangle class has been designed\nto fit all 2D reference systems\".\n\n> >\n> > To be honest I would not be concerned about 4-planes systems, we're\n> > talking about imaging and what is relevant here is that we should be\n> > allowed to express rectangles on reference systems that can be\n> > oriented differently, think of a sensor's pixel array that might be\n> > represented with the (0, 0) position in the top-left corner compared\n> > to a plane 2-d image that usually has its origin in the bottom-left\n> > corner.\n> >\n> > I have an hard time finding a use case for expressing negative\n> > coordinates in this usage context. Furthermore that if we introduce 4\n> > planes we lose the ability to describe systems with different\n> > orientation, as this:\n> >\n> >                       ------------------------>\n> >                       |  o-------\n> >                       |  |      |\n> >                       |  --------\n> >                       |\n> >                       |\n> >                       V\n> >\n> > when expressed in a 4-planes system becomes\n> >\n> >                       ^\n> >                       |\n> >                       |\n> >                       |\n> >                       |\n> >         <--------------------------->\n> >                       |/////////////\n> >                       |/////////////\n> >                       |// this /////\n> >                       |/////////////\n> >                       |/////////////\n> >                       V\n> >\n> > And would require you to express y and height in negative coordinates.\n> > Sincerely, I would not go there.\n> >\n> > I can specify that the Rectangle class reference system is always a\n> > 2-d plane with positively increasing x and y axes instead.\n>\n> Yeah I think specifying that is a great idea, and maybe a TODO to\n> set `x` and `y` to be unsigned int.\n\nI can try to do this right away and see if any compiler complains\nabout that.\n\n> I hope no pipeline handlers is using signed coordinates when we\n> make the change in the API.\n\nHowever, geometry.h is public API, some applications might be affected\nby this change.\n\n>\n> Sorry for the chaos.\n>\n\nnp, if it helps to make the final result better chaos is welcome.\n\n> >\n> > >\n> > > >\n> > > > The problem at hands now is relevant for 1-planes reference systems,\n> > > > that can be oriented differently, in example with the origin point\n> > > > being in top-left or bottom-left positions, as per the examples above.\n> > > > In this case I think we agree that \"top-left\" is ambiguous. The x and\n> > > > y coordinates are always positive in the case with a single plane.\n> > > >\n> > > > I think we should also be concerned with 1 plane reference systems and\n> > > > move forward with this patch that removes references to the visual\n> > > > \"top-left\" and assumes increments in width and height are always\n> > > > positive.\n> > > >\n> > > > > >\n> > > > > > > corner, and currently libcamera::Size only allows non-negative width and\n> > > > > > > height [1].\n> > > > > >\n> > > > > > True, Size uses unsigned int. I don't think it's a big deal and I'm\n> > > > > > not proposing to introduce a new constructor with signed width and\n> > > > > > height now, but my point is that if the need arises we can now do\n> > > > > > that.\n> > > > > >\n> > > > > > >\n> > > > > > > [1]:\n> > > > > > > https://git.libcamera.org/libcamera/libcamera.git/tree/include/libcamera/geometry.h#n65\n> > > > > > >\n> > > > > > >\n> > > > > > > > >\n> > > > > > > > >\n> > > > > > > > > >\n> > > > > > > > > > > BR,\n> > > > > > > > > > > Harvey\n> > > > > > > > > > >\n> > > > > > > > > > >\n> > > > > > > > > > > > >    */\n> > > > > > > > > > > > >\n> > > > > > > > > > > > >   /**\n> > > > > > > > > > > > >    * \\fn Rectangle::Rectangle(int x, int y, unsigned int width,\n> > > > > > > > > > unsigned int height)\n> > > > > > > > > > > > >    * \\brief Construct a Rectangle with the given position and\n> > > > > > > > size\n> > > > > > > > > > > > > - * \\param[in] x The horizontal coordinate of the top-left corner\n> > > > > > > > > > > > > - * \\param[in] y The vertical coordinate of the top-left corner\n> > > > > > > > > > > > > + * \\param[in] x The horizontal coordinate of the origin corner\n> > > > > > > > > > > > > + * \\param[in] y The vertical coordinate of the origin corner\n> > > > > > > > > > > > >    * \\param[in] width The width\n> > > > > > > > > > > > >    * \\param[in] height The height\n> > > > > > > > > > > > > + *\n> > > > > > > > > > > > > + * The rectangle's origin corner is the corner closer to the\n> > > > > > > > > > reference system\n> > > > > > > > > > > > > + * origin point (0, 0).\n> > > > > > > > > > > > >    */\n> > > > > > > > > > > > >\n> > > > > > > > > > > > >   /**\n> > > > > > > > > > > > >    * \\fn Rectangle::Rectangle(const Size &size)\n> > > > > > > > > > > > > - * \\brief Construct a Rectangle of \\a size with its top left\n> > > > > > > > corner\n> > > > > > > > > > located\n> > > > > > > > > > > > > + * \\brief Construct a Rectangle of \\a size with its origin\n> > > > > > > > corner\n> > > > > > > > > > located\n> > > > > > > > > > > > >    * at (0,0)\n> > > > > > > > > > > > >    * \\param[in] size The desired Rectangle size\n> > > > > > > > > > > > > + *\n> > > > > > > > > > > > > + * The rectangle's origin corner is the corner closer to the\n> > > > > > > > > > reference system\n> > > > > > > > > > > > > + * origin point (0, 0).\n> > > > > > > > > > > > >    */\n> > > > > > > > > > > > >\n> > > > > > > > > > > > >   /**\n> > > > > > > > > > > > >    * \\var Rectangle::x\n> > > > > > > > > > > > > - * \\brief The horizontal coordinate of the rectangle's top-left\n> > > > > > > > > > corner\n> > > > > > > > > > > > > + * \\brief The horizontal coordinate of the rectangle's origin\n> > > > > > > > corner\n> > > > > > > > > > > > > + *\n> > > > > > > > > > > > > + * The rectangle's origin corner is the corner closer to the\n> > > > > > > > > > reference system\n> > > > > > > > > > > > > + * origin point (0, 0).\n> > > > > > > > > > > > >    */\n> > > > > > > > > > > > >\n> > > > > > > > > > > > >   /**\n> > > > > > > > > > > > >    * \\var Rectangle::y\n> > > > > > > > > > > > > - * \\brief The vertical coordinate of the rectangle's top-left\n> > > > > > > > corner\n> > > > > > > > > > > > > + * \\brief The vertical coordinate of the rectangle's origin\n> > > > > > > > corner\n> > > > > > > > > > > > > + *\n> > > > > > > > > > > > > + * The rectangle's origin corner is the corner closer to the\n> > > > > > > > > > reference system\n> > > > > > > > > > > > > + * origin point (0, 0).\n> > > > > > > > > > > > >    */\n> > > > > > > > > > > > >\n> > > > > > > > > > > > >   /**\n> > > > > > > > > > > > > @@ -683,9 +726,13 @@ Point Rectangle::center() const\n> > > > > > > > > > > > >    */\n> > > > > > > > > > > > >\n> > > > > > > > > > > > >   /**\n> > > > > > > > > > > > > - * \\fn Point Rectangle::topLeft() const\n> > > > > > > > > > > > > - * \\brief Retrieve the coordinates of the top left corner of\n> > > > > > > > this\n> > > > > > > > > > Rectangle\n> > > > > > > > > > > > > - * \\return The Rectangle's top left corner\n> > > > > > > > > > > > > + * \\fn Point Rectangle::origin() const\n> > > > > > > > > > > > > + * \\brief Retrieve the coordinates of the origin corner of this\n> > > > > > > > > > Rectangle\n> > > > > > > > > > > > > + *\n> > > > > > > > > > > > > + * The rectangle's origin corner is the corner closer to the\n> > > > > > > > > > reference system\n> > > > > > > > > > > > > + * origin point (0, 0).\n> > > > > > > > > > > > > + *\n> > > > > > > > > > > > > + * \\return The Rectangle's origin corner\n> > > > > > > > > > > >\n> > > > > > > > > > > > I think you can drop \"corner\" from \"origin corner\"\n> > > > > > > > > > > >\n> > > > > > > > > > > > Probably throughout the patch:\n> > > > > > > > > > > >      s/origin corner/origin/\n> > > > > > > > > > > >\n> > > > > > > > > > > > Otherwise, LGTM\n> > > > > > > > > > > >\n> > > > > > > > > > > > Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>\n> > > > > > > > > > > > >    */\n> > > > > > > > > > > > >\n> > > > > > > > > > > > >   /**\n> > > > > > > > > > > > > @@ -740,15 +787,15 @@ Rectangle &Rectangle::translateBy(const\n> > > > > > > > Point\n> > > > > > > > > > &point)\n> > > > > > > > > > > > >    */\n> > > > > > > > > > > > >   Rectangle Rectangle::boundedTo(const Rectangle &bound) const\n> > > > > > > > > > > > >   {\n> > > > > > > > > > > > > -     int topLeftX = std::max(x, bound.x);\n> > > > > > > > > > > > > -     int topLeftY = std::max(y, bound.y);\n> > > > > > > > > > > > > +     int originX = std::max(x, bound.x);\n> > > > > > > > > > > > > +     int originY = std::max(y, bound.y);\n> > > > > > > > > > > > >       int bottomRightX = std::min<int>(x + width, bound.x +\n> > > > > > > > > > bound.width);\n> > > > > > > > > > > > >       int bottomRightY = std::min<int>(y + height, bound.y +\n> > > > > > > > > > bound.height);\n> > > > > > > > > > > > >\n> > > > > > > > > > > > > -     unsigned int newWidth = std::max(bottomRightX - topLeftX,\n> > > > > > > > 0);\n> > > > > > > > > > > > > -     unsigned int newHeight = std::max(bottomRightY - topLeftY,\n> > > > > > > > 0);\n> > > > > > > > > > > > > +     unsigned int newWidth = std::max(bottomRightX - originX,\n> > > > > > > > 0);\n> > > > > > > > > > > > > +     unsigned int newHeight = std::max(bottomRightY - originY,\n> > > > > > > > 0);\n> > > > > > > > > > > > >\n> > > > > > > > > > > > > -     return { topLeftX, topLeftY, newWidth, newHeight };\n> > > > > > > > > > > > > +     return { originX, originY, newWidth, newHeight };\n> > > > > > > > > > > > >   }\n> > > > > > > > > > > > >\n> > > > > > > > > > > > >   /**\n> > > > > > > > > > > > > diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n> > > > > > > > > > b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n> > > > > > > > > > > > > index 3041fd1ed9fd..8d2440026689 100644\n> > > > > > > > > > > > > --- a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n> > > > > > > > > > > > > +++ b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n> > > > > > > > > > > > > @@ -1289,7 +1289,7 @@ Rectangle CameraData::scaleIspCrop(const\n> > > > > > > > > > Rectangle &ispCrop) const\n> > > > > > > > > > > > >        */\n> > > > > > > > > > > > >       Rectangle nativeCrop =\n> > > > > > > > > > ispCrop.scaledBy(sensorInfo_.analogCrop.size(),\n> > > > > > > > > > > > >\n> > > > > > > > > >  sensorInfo_.outputSize);\n> > > > > > > > > > > > > -     nativeCrop.translateBy(sensorInfo_.analogCrop.topLeft());\n> > > > > > > > > > > > > +     nativeCrop.translateBy(sensorInfo_.analogCrop.origin());\n> > > > > > > > > > > > >       return nativeCrop;\n> > > > > > > > > > > > >   }\n> > > > > > > > > > > > >\n> > > > > > > > > > > > > @@ -1303,7 +1303,7 @@ void CameraData::applyScalerCrop(const\n> > > > > > > > > > ControlList &controls)\n> > > > > > > > > > > > >                       nativeCrop = { 0, 0, 1, 1 };\n> > > > > > > > > > > > >\n> > > > > > > > > > > > >               /* Create a version of the crop scaled to ISP\n> > > > > > > > (camera\n> > > > > > > > > > mode) pixels. */\n> > > > > > > > > > > > > -             Rectangle ispCrop =\n> > > > > > > > > > nativeCrop.translatedBy(-sensorInfo_.analogCrop.topLeft());\n> > > > > > > > > > > > > +             Rectangle ispCrop =\n> > > > > > > > > > nativeCrop.translatedBy(-sensorInfo_.analogCrop.origin());\n> > > > > > > > > > > > >               ispCrop.scaleBy(sensorInfo_.outputSize,\n> > > > > > > > > > sensorInfo_.analogCrop.size());\n> > > > > > > > > > > > >\n> > > > > > > > > > > > >               /*\n> > > > > > > > > > > > > diff --git a/src/py/libcamera/py_geometry.cpp\n> > > > > > > > > > b/src/py/libcamera/py_geometry.cpp\n> > > > > > > > > > > > > index c7e303609427..8dee365b25dd 100644\n> > > > > > > > > > > > > --- a/src/py/libcamera/py_geometry.cpp\n> > > > > > > > > > > > > +++ b/src/py/libcamera/py_geometry.cpp\n> > > > > > > > > > > > > @@ -105,7 +105,7 @@ void init_py_geometry(py::module &m)\n> > > > > > > > > > > > >               .def_property_readonly(\"is_null\",\n> > > > > > > > &Rectangle::isNull)\n> > > > > > > > > > > > >               .def_property_readonly(\"center\",\n> > > > > > > > &Rectangle::center)\n> > > > > > > > > > > > >               .def_property_readonly(\"size\", &Rectangle::size)\n> > > > > > > > > > > > > -             .def_property_readonly(\"topLeft\",\n> > > > > > > > &Rectangle::topLeft)\n> > > > > > > > > > > > > +             .def_property_readonly(\"origin\",\n> > > > > > > > &Rectangle::origin)\n> > > > > > > > > > > > >               .def(\"scale_by\", &Rectangle::scaleBy)\n> > > > > > > > > > > > >               .def(\"translate_by\", &Rectangle::translateBy)\n> > > > > > > > > > > > >               .def(\"bounded_to\", &Rectangle::boundedTo)\n> > > > > > > > > > > > > diff --git a/test/geometry.cpp b/test/geometry.cpp\n> > > > > > > > > > > > > index 64169206ad16..a4ee6f6e167a 100644\n> > > > > > > > > > > > > --- a/test/geometry.cpp\n> > > > > > > > > > > > > +++ b/test/geometry.cpp\n> > > > > > > > > > > > > @@ -363,16 +363,16 @@ protected:\n> > > > > > > > > > > > >                       return TestFail;\n> > > > > > > > > > > > >               }\n> > > > > > > > > > > > >\n> > > > > > > > > > > > > -             /* Rectangle::size(), Rectangle::topLeft() and\n> > > > > > > > > > Rectangle::center() tests */\n> > > > > > > > > > > > > +             /* Rectangle::size(), Rectangle::origin() and\n> > > > > > > > > > Rectangle::center() tests */\n> > > > > > > > > > > > >               if (Rectangle(-1, -2, 3, 4).size() != Size(3, 4) ||\n> > > > > > > > > > > > >                   Rectangle(0, 0, 100000, 200000).size() !=\n> > > > > > > > > > Size(100000, 200000)) {\n> > > > > > > > > > > > >                       cout << \"Rectangle::size() test failed\" <<\n> > > > > > > > > > endl;\n> > > > > > > > > > > > >                       return TestFail;\n> > > > > > > > > > > > >               }\n> > > > > > > > > > > > >\n> > > > > > > > > > > > > -             if (Rectangle(1, 2, 3, 4).topLeft() != Point(1, 2)\n> > > > > > > > ||\n> > > > > > > > > > > > > -                 Rectangle(-1, -2, 3, 4).topLeft() != Point(-1,\n> > > > > > > > > > -2)) {\n> > > > > > > > > > > > > -                     cout << \"Rectangle::topLeft() test failed\"\n> > > > > > > > <<\n> > > > > > > > > > endl;\n> > > > > > > > > > > > > +             if (Rectangle(1, 2, 3, 4).origin() != Point(1, 2)\n> > > > > > > > ||\n> > > > > > > > > > > > > +                 Rectangle(-1, -2, 3, 4).origin() != Point(-1,\n> > > > > > > > -2))\n> > > > > > > > > > {\n> > > > > > > > > > > > > +                     cout << \"Rectangle::origin() test failed\"\n> > > > > > > > <<\n> > > > > > > > > > endl;\n> > > > > > > > > > > > >                       return TestFail;\n> > > > > > > > > > > > >               }\n> > > > > > > > > > > > >\n> > > > > > > > > > > > > --\n> > > > > > > > > > > > > 2.46.1\n> > > > > > > > > > > > >\n> > > > > > > > > > > >\n> > > > > > > > > > >\n> > > > > > > > > > >\n> > > > > > > > > > > --\n> > > > > > > > > > > BR,\n> > > > > > > > > > > Harvey Yang\n> > > > > > > > > >\n> > > > > > > >\n> > > > >\n> > > > >\n> > > > >\n> > > > > --\n> > > > > BR,\n> > > > > Harvey Yang\n> > >\n> > >\n> > >\n> > > --\n> > > BR,\n> > > Harvey Yang\n>\n>\n>\n> --\n> BR,\n> Harvey Yang","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 373D7C0F1B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 27 Sep 2024 08:54:29 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 2F65E6350F;\n\tFri, 27 Sep 2024 10:54:28 +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 5B79F618DB\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 27 Sep 2024 10:54:26 +0200 (CEST)","from ideasonboard.com (mob-5-90-58-180.net.vodafone.it\n\t[5.90.58.180])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 7CE5D83D;\n\tFri, 27 Sep 2024 10:52:56 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"gH2SV0Bv\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1727427177;\n\tbh=KPmvfiLgqbO4BAHPVTT9dN5ViuKrmSGOljRpSKTEWwE=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=gH2SV0BvmVOXZmr1Eax8q3cV2adqruzytSM1DYRERVxqrkXMUJlAAmPb7Jc/pfYG7\n\t+5xvJNUt1h+D5S+4ceUsBa31iX0vpsGt+ApHL484NOL908W4E0Ki31XYa8m2oxgW7n\n\tnTXFbLdofOhn4WDQ3dYIgzheMgweRPURLIqe5fXU=","Date":"Fri, 27 Sep 2024 10:54:20 +0200","From":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>","To":"Cheng-Hao Yang <chenghaoyang@google.com>","Cc":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>, \n\tUmang Jain <umang.jain@ideasonboard.com>,\n\tlibcamera devel <libcamera-devel@lists.libcamera.org>","Subject":"Re: [PATCH] libcamera: geometry: Rename Rectangle's top-left corner","Message-ID":"<cdtdrnjxni6trvlsmejd24ihlbujtqo4sxq4x7gwktitzua4rz@msm5if6yuae5>","References":"<uzptnxdipytxx4nwqusnr62asaiwrdawylf2f3vzbmkc53onhc@nkeomtxtfw5g>\n\t<CAC=wSGWEZU7_=nEFTp+g_g74L7kcs65wK3oOeS8xwBqzMHa5wQ@mail.gmail.com>\n\t<zsszrdewqlrlovncquphk43ajxyksfoijoiorglvwem4kb2u6q@my2gscqpdzd3>\n\t<CAC=wSGXj==p2GZMidtwb9pUhmnuRrdqbGhQUF14HSNfTzgz_Cw@mail.gmail.com>\n\t<62yvkiqioilupdcm7ryjtrz273iamzojfi2pgxndmjwoyyaitb@iq46e47ke2vg>\n\t<CAC=wSGXgYv2YyZqwgRANhmVzPtLTkTHP4=R-_Sz+NE7wNzPJXw@mail.gmail.com>\n\t<6cnkhto53ixz7hafosgqebixvfdpwftc24ach46wsvv6qpjmkv@h7e25hene6yc>\n\t<CAC=wSGU3ubNji42mp-4eXH7L34ZZE0vP_NA5Uu1fKgUsQTvG7Q@mail.gmail.com>\n\t<juj2axmwzwss5axiy3y6l4hetonuv72oyzgb6ekf5hbt66it73@j23uammf6fl7>\n\t<CAC=wSGVEjJ-fHo4W31OGU2Qk8=OhhzYNCW4qFxqLLdtTu0kGrw@mail.gmail.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<CAC=wSGVEjJ-fHo4W31OGU2Qk8=OhhzYNCW4qFxqLLdtTu0kGrw@mail.gmail.com>","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>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":31447,"web_url":"https://patchwork.libcamera.org/comment/31447/","msgid":"<jhm5lkl4kkjs3e2dydelkdeju3hqwwobxq3l6pg36knebrppdv@lrjdkupwnogu>","date":"2024-09-27T14:50:47","subject":"Re: [PATCH] libcamera: geometry: Rename Rectangle's top-left corner","submitter":{"id":143,"url":"https://patchwork.libcamera.org/api/people/143/","name":"Jacopo Mondi","email":"jacopo.mondi@ideasonboard.com"},"content":"Hi again\n\nOn Fri, Sep 27, 2024 at 10:54:20AM GMT, Jacopo Mondi wrote:\n> Hi Harvey\n>\n> On Fri, Sep 27, 2024 at 04:46:06PM GMT, Cheng-Hao Yang wrote:\n> > Hi Jacopo,\n> >\n> > On Fri, Sep 27, 2024 at 4:05 PM Jacopo Mondi\n> > <jacopo.mondi@ideasonboard.com> wrote:\n> > >\n> > > Hi Harvey\n> > >\n> > > On Thu, Sep 26, 2024 at 11:22:58PM GMT, Cheng-Hao Yang wrote:\n> > > > Hi Jacopo,\n> > > >\n> > > > On Thu, Sep 26, 2024 at 10:35 PM Jacopo Mondi\n> > > > <jacopo.mondi@ideasonboard.com> wrote:\n> > > > >\n> > > > > Hi Harvey\n> > > > >\n> > > > > On Thu, Sep 26, 2024 at 10:03:55PM GMT, Cheng-Hao Yang wrote:\n> > > > > > Hi Jacopo,\n> > > > > >\n> > > > > > On Thu, Sep 26, 2024 at 5:36 PM Jacopo Mondi\n> > > > > > <jacopo.mondi@ideasonboard.com> wrote:\n> > > > > > >\n> > > > > > > Hi Harvey\n> > > > > > >\n> > > > > > > On Thu, Sep 26, 2024 at 05:28:13PM GMT, Cheng-Hao Yang wrote:\n> > > > > > > > Hi Jacopo,\n> > > > > > > >\n> > > > > > > >\n> > > > > > > >\n> > > > > > > > On Thu, Sep 26, 2024, 4:38 PM Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n> > > > > > > > wrote:\n> > > > > > > >\n> > > > > > > > > Hi Harvey\n> > > > > > > > >\n> > > > > > > > > On Thu, Sep 26, 2024 at 04:29:50PM GMT, Cheng-Hao Yang wrote:\n> > > > > > > > > > Hi Jacopo,\n> > > > > > > > > >\n> > > > > > > > > > On Thu, Sep 26, 2024, 4:03 PM Jacopo Mondi <\n> > > > > > > > > jacopo.mondi@ideasonboard.com>\n> > > > > > > > > > wrote:\n> > > > > > > > > >\n> > > > > > > > > > > Hi Harvey\n> > > > > > > > > > >\n> > > > > > > > > > > On Wed, Sep 25, 2024 at 03:09:38PM GMT, Cheng-Hao Yang wrote:\n> > > > > > > > > > > > Hi Jacopo,\n> > > > > > > > > > > >\n> > > > > > > > > > > > Thank you for the patch.\n> > > > > > > > > > > >\n> > > > > > > > > > > > On Wed, Sep 25, 2024 at 2:36 PM Umang Jain <\n> > > > > > > > > umang.jain@ideasonboard.com>\n> > > > > > > > > > > wrote:\n> > > > > > > > > > > > >\n> > > > > > > > > > > > > Hi Jacopo\n> > > > > > > > > > > > >\n> > > > > > > > > > > > > Thank you for the patch\n> > > > > > > > > > > > >\n> > > > > > > > > > > > > On 24/09/24 6:15 pm, Jacopo Mondi wrote:\n> > > > > > > > > > > > > > The libcamera::Rectangle class should allow defining rectangles\n> > > > > > > > > > > > > > regardless of the reference system where an instance is used in.\n> > > > > > > > > > > > > >\n> > > > > > > > > > > > > > However the class documentation assumes the reference system\n> > > > > > > > > origin\n> > > > > > > > > > > > > > point to be in the visual top-left side and that rectangles are\n> > > > > > > > > > > > > > constructed by specifying the top-left corner position and sizes.\n> > > > > > > > > > > > > >\n> > > > > > > > > > > > > > However this is ambiguous when using a different reference\n> > > > > > > > > system as,\n> > > > > > > > > > > > > > in example, constructing a rectangle (x, y, w, h) in the\n> > > > > > > > > following\n> > > > > > > > > > > > > > scenario, with the origin corner in the top-left position, would\n> > > > > > > > > > > require\n> > > > > > > > > > > > > > a negative decrement along the y-axis.\n> > > > > > > > > > > > > >\n> > > > > > > > > > > > > >           ^\n> > > > > > > > > > > > > >           |\n> > > > > > > > > > > > > >          y|      o------------------\n> > > > > > > > > > > > > >           |      |                 | h\n> > > > > > > > > > > > > >           |      |                 |\n> > > > > > > > > > > > > >           |      -------------------\n> > > > > > > > > > > > > >           |               w\n> > > > > > > > > > > > > >            ------------------------------->\n> > > > > > > > > > > > > >           (0,0)  x\n> > > > > > > > > > > > > >\n> > > > > > > > > > > > > > To remove ambiguities, drop references to the visual top-left\n> > > > > > > > > corner\n> > > > > > > > > > > and\n> > > > > > > > > > > > > > define the rectangle's origin corner as the corner closer to the\n> > > > > > > > > > > > > > reference system origin point, and specify the horizontal and\n> > > > > > > > > > > vertical\n> > > > > > > > > > > > > > dimensions always increment along their respective axis, as in\n> > > > > > > > > the\n> > > > > > > > > > > > > > following example.\n> > > > > > > > > > > > > >\n> > > > > > > > > > > > > >           ^\n> > > > > > > > > > > > > >           |\n> > > > > > > > > > > > > >           |      -------------------\n> > > > > > > > > > > > > >           |      ^                 | h\n> > > > > > > > > > > > > >           |      |                 |\n> > > > > > > > > > > > > >          y|      o---->-------------\n> > > > > > > > > > > > > >           |               w\n> > > > > > > > > > > > > >            ------------------------------->\n> > > > > > > > > > > > > >           (0,0)  x\n> > > > > > > > > > > > > >\n> > > > > > > > > > > > > >           (0,0)  x\n> > > > > > > > > > > > > >             ------------------------------>\n> > > > > > > > > > > > > >            |              w\n> > > > > > > > > > > > > >           y|     o---->-------------\n> > > > > > > > > > > > > >            |     |                 | h\n> > > > > > > > > > > > > >            |     v                 |\n> > > > > > > > > > > > > >            |     -------------------\n> > > > > > > > > > > > > >            |\n> > > > > > > > > > > > > >            V\n> > > > > > > > > > > > > >\n> > > > > > > > > > > > > > Also rename for consistency the Rectangle::topLeft() function to\n> > > > > > > > > > > > > > Rectangle::origin() and update its in-tree users.\n> > > > > > > > > > > > > >\n> > > > > > > > > > > > > > Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n> > > > > > > > > > > > > > ---\n> > > > > > > > > > > > > >   include/libcamera/geometry.h                  |  2 +-\n> > > > > > > > > > > > > >   src/ipa/ipu3/algorithms/af.cpp                |  2 +-\n> > > > > > > > > > > > > >   src/libcamera/geometry.cpp                    | 85\n> > > > > > > > > > > ++++++++++++++-----\n> > > > > > > > > > > > > >   .../pipeline/rpi/common/pipeline_base.cpp     |  4 +-\n> > > > > > > > > > > > > >   src/py/libcamera/py_geometry.cpp              |  2 +-\n> > > > > > > > > > > > > >   test/geometry.cpp                             |  8 +-\n> > > > > > > > > > > > > >   6 files changed, 75 insertions(+), 28 deletions(-)\n> > > > > > > > > > > > > >\n> > > > > > > > > > > > > > diff --git a/include/libcamera/geometry.h\n> > > > > > > > > > > b/include/libcamera/geometry.h\n> > > > > > > > > > > > > > index 3e6f0f5d7fab..07cb0a7866fe 100644\n> > > > > > > > > > > > > > --- a/include/libcamera/geometry.h\n> > > > > > > > > > > > > > +++ b/include/libcamera/geometry.h\n> > > > > > > > > > > > > > @@ -277,7 +277,7 @@ public:\n> > > > > > > > > > > > > >               return { width, height };\n> > > > > > > > > > > > > >       }\n> > > > > > > > > > > > > >\n> > > > > > > > > > > > > > -     Point topLeft() const\n> > > > > > > > > > > > > > +     Point origin() const\n> > > > > > > > > > > > > >       {\n> > > > > > > > > > > > > >               return { x, y };\n> > > > > > > > > > > > > >       }\n> > > > > > > > > > > > > > diff --git a/src/ipa/ipu3/algorithms/af.cpp\n> > > > > > > > > > > b/src/ipa/ipu3/algorithms/af.cpp\n> > > > > > > > > > > > > > index cf68fb59c49b..1b707e9dd9ab 100644\n> > > > > > > > > > > > > > --- a/src/ipa/ipu3/algorithms/af.cpp\n> > > > > > > > > > > > > > +++ b/src/ipa/ipu3/algorithms/af.cpp\n> > > > > > > > > > > > > > @@ -155,7 +155,7 @@ int Af::configure(IPAContext &context, const\n> > > > > > > > > > > IPAConfigInfo &configInfo)\n> > > > > > > > > > > > > >        * - Return the AF ROI as metadata in the Request\n> > > > > > > > > > > > > >        */\n> > > > > > > > > > > > > >       Rectangle roi = gridSize.centeredTo(bds.center());\n> > > > > > > > > > > > > > -     Point start = roi.topLeft();\n> > > > > > > > > > > > > > +     Point start = roi.origin();\n> > > > > > > > > > > > > >\n> > > > > > > > > > > > > >       /* x_start and y_start should be even */\n> > > > > > > > > > > > > >       grid.x_start = utils::alignDown(start.x, 2);\n> > > > > > > > > > > > > > diff --git a/src/libcamera/geometry.cpp\n> > > > > > > > > b/src/libcamera/geometry.cpp\n> > > > > > > > > > > > > > index 000151364c7f..45ba81a99920 100644\n> > > > > > > > > > > > > > --- a/src/libcamera/geometry.cpp\n> > > > > > > > > > > > > > +++ b/src/libcamera/geometry.cpp\n> > > > > > > > > > > > > > @@ -593,11 +593,39 @@ std::ostream &operator<<(std::ostream &out,\n> > > > > > > > > > > const SizeRange &sr)\n> > > > > > > > > > > > > >    * \\brief Describe a rectangle's position and dimensions\n> > > > > > > > > > > > > >    *\n> > > > > > > > > > > > > >    * Rectangles are used to identify an area of an image. They\n> > > > > > > > > are\n> > > > > > > > > > > specified by\n> > > > > > > > > > > > > > - * the coordinates of top-left corner and their horizontal and\n> > > > > > > > > > > vertical size.\n> > > > > > > > > > > > > > + * the coordinates of the corner closer to the reference\n> > > > > > > > > system's\n> > > > > > > > > > > origin point\n> > > > > > > > > > > > > > + * and by horizontal and vertical increments from there.\n> > > > > > > > > > > > > >    *\n> > > > > > > > > > > > > > - * The measure unit of the rectangle coordinates and size, as\n> > > > > > > > > well\n> > > > > > > > > > > as the\n> > > > > > > > > > > > > > - * reference point from which the Rectangle::x and Rectangle::y\n> > > > > > > > > > > displacements\n> > > > > > > > > > > > > > - * refers to, are defined by the context were rectangle is used.\n> > > > > > > > > > > > > > + * The corner closer to the reference system's origin point is\n> > > > > > > > > the\n> > > > > > > > > > > rectangle's\n> > > > > > > > > > > > > > + * origin corner.\n> > > > > > > > > > > > > > + *\n> > > > > > > > > > > > > > + * \\verbatim\n> > > > > > > > > > > > > > +\n> > > > > > > > > > > > > > +  o = origin corner\n> > > > > > > > > > > > > > +\n> > > > > > > > > > > > > > +         ^\n> > > > > > > > > > > > > > +         |\n> > > > > > > > > > > > > > +         |      -------------------\n> > > > > > > > > > > > > > +         |      ^                 |\n> > > > > > > > > > > > > > +         |      |                 |\n> > > > > > > > > > > > > > +         |      o---->-------------\n> > > > > > > > > > > > > > +         |\n> > > > > > > > > > > > > > +          ------------------------------->\n> > > > > > > > > > > > > > +         (0,0)\n> > > > > > > > > > > > > > +\n> > > > > > > > > > > > > > +         (0,0)\n> > > > > > > > > > > > > > +           ------------------------------->\n> > > > > > > > > > > > > > +          |\n> > > > > > > > > > > > > > +          |      o---->-------------\n> > > > > > > > > > > > > > +          |      |                 |\n> > > > > > > > > > > > > > +          |      v                 |\n> > > > > > > > > > > > > > +          |      -------------------\n> > > > > > > > > > > > > > +          |\n> > > > > > > > > > > > > > +          V\n> > > > > > > > > > > > > > +   \\endverbatim\n> > > > > > > > > > > > > > + *\n> > > > > > > > > > > > > > + * The measure unit of the rectangle coordinates and size are\n> > > > > > > > > > > defined by the\n> > > > > > > > > > > > > > + * context were the rectangle is used.\n> > > > > > > > > > > > > >    */\n> > > > > > > > > > > > > >\n> > > > > > > > > > > > > >   /**\n> > > > > > > > > > > > > > @@ -608,35 +636,50 @@ std::ostream &operator<<(std::ostream &out,\n> > > > > > > > > > > const SizeRange &sr)\n> > > > > > > > > > > > > >   /**\n> > > > > > > > > > > > > >    * \\fn Rectangle::Rectangle(int x, int y, const Size &size)\n> > > > > > > > > > > > > >    * \\brief Construct a Rectangle with the given position and\n> > > > > > > > > size\n> > > > > > > > > > > > > > - * \\param[in] x The horizontal coordinate of the top-left corner\n> > > > > > > > > > > > > > - * \\param[in] y The vertical coordinate of the top-left corner\n> > > > > > > > > > > > > > + * \\param[in] x The horizontal coordinate of the origin corner\n> > > > > > > > > > > > > > + * \\param[in] y The vertical coordinate of the origin corner\n> > > > > > > > > > > > > >    * \\param[in] size The size\n> > > > > > > > > > > > > > + *\n> > > > > > > > > > > > > > + * The rectangle's origin corner is the corner closer to the\n> > > > > > > > > > > reference system\n> > > > > > > > > > > > > > + * origin point (0, 0).\n> > > > > > > > > > > >\n> > > > > > > > > > > > I think we should stick to the previous description:\n> > > > > > > > > > > > `\"origin\" point defined as the point with the lower x and\n> > > > > > > > > > > > lower y of the rectangle`, as `x` and `y` are signed integers.\n> > > > > > > > > > > >\n> > > > > > > > > > > > If we only support coordinates that are positive or 0, which\n> > > > > > > > > > > > I'm not sure if it's the case, how about making the type to be\n> > > > > > > > > > > > `unsigned int`?\n> > > > > > > > > > > >\n> > > > > > > > > > >\n> > > > > > > > > > > To be honest I would rather make width and heigh signed to allow\n> > > > > > > > > > > constructing (x, y, -w, -h)\n> > > > > > > > > > >\n> > > > > > > > > > >\n> > > > > > > > > > >\n> > > > > > > > > > >\n> > > > > > > > > > >                -------------------\n> > > > > > > > > > >                |                 ^\n> > > > > > > > > > >                |            ------------->\n> > > > > > > > > > >                |           |     |\n> > > > > > > > > > >                ------<-----|-----o\n> > > > > > > > > > >                            |\n> > > > > > > > > > >                            |\n> > > > > > > > > > >                            V\n> > > > > > > > > > >\n> > > > > > > > > > > Not sure if it's useful or not though\n> > > > > > > > > > >\n> > > > > > > > > >\n> > > > > > > > > > Hmm... I find it pretty weird. What if all four corners have all negative\n> > > > > > > > > > coordinates?\n> > > > > > > > > >\n> > > > > > > > > >\n> > > > > > > > >\n> > > > > > > > > Don't know, maybe if the reference system where the rectangle is used\n> > > > > > > > > into has 4 planes and so an all-negative rectangle makes sense.\n> > > > > > > > >\n> > > > > > > > > My point is that we should allow users of this class to express\n> > > > > > > > > Rectangle in any context they plan to use them. Not sure if I'm going\n> > > > > > > > > overboard here or it makes sense.\n> > > > > > > > >\n> > > > > > > >\n> > > > > > > > Yeah I agree, while doesn't that mean the description doesn't fit all\n> > > > > > > > cases, like the corner closer to the reference system origin point of a\n> > > > > > > > rectangle that has all negative coordinates is actually the \"bottom-right\"\n> > > > > > >\n> > > > > > > This patch aims to remove all references to \"top-left\" or in general\n> > > > > > > to any visual reference exactly for that purpose. Or have I forgot any\n> > > > > > > ?\n> > > > > >\n> > > > > > In this c'tor `\\fn Rectangle::Rectangle(int x, int y, const Size &size)`,\n> > > > > > the description of `x` and `y` are updated to \"coordinates of the origin\n> > > > > > corner\", where the origin corner is \"the corner closer to the reference\n> > > > > > system origin point (0, 0).\"\n> > > > > >\n> > > > > > As currently libcamera::Size takes only non-negative width and height,\n> > > > > > take rectangle [(-3, -3), (-3, -1), (-1, -3), (-1, -1)] as the example, you\n> > > > > > can find that the only valid way to construct this rectangle as\n> > > > > > libcamera::Rectangle is `{x = -3, y = -3, size = {2, 2}}`. However, this\n> > > > > > doesn't fit with your updated description, as the corner closer to the\n> > > > > > reference system origin point (0, 0) is actually (-1, -1), instead of\n> > > > > > (-3, -3).\n> > > > > >\n> > > > >\n> > > > > You're right. Let's take a step back though. If we have a 4 planes reference\n> > > > > system, we always have a visual top-left indeed. As the 4 planes have\n> > > > > negative and positive coordinates, we can describe with absolute\n> > > > > positions the rectangle and all points in the system.\n> > > >\n> > > > Sorry, I still don't get your point...\n> > > >\n> > >\n> > > If you have a 4 planes system\n> > >\n> > >                       ^\n> > >                       |\n> > >                       |\n> > >                       |\n> > >                       |\n> > >         <--------------------------->\n> > >                       |\n> > >                       |\n> > >                       |\n> > >                       |\n> > >                       V\n> > >\n> > > Then you always have a top, a left, and bottom and a right, you can\n> > > describe width and height as negative or positive increments and your\n> > > rectangle is always well defined as the reference system cannot be\n> > > ambiguous. The very concept of \"reference system orientation\" doesn't\n> > > make sense, as a 4-planes system describes the full 2-d space.\n> > >\n> > > The ambiguity I'm trying to solve is about using a 1 plane reference\n> > > system, as depending on how the system is oriented the definition of\n> > > the \"top-left\" point might change, as well as the definition of the\n> > > horizontal and vertical increments change as well.\n> > >\n> > > In example:\n> > >\n> > >                       ^\n> > >                       |\n> > >                       |\n> > >                       |  o-------\n> > >                       |  |      |\n> > >                       |  --------\n> > >                       |\n> > >                       ------------------------>\n> > >\n> > >         top-left: Smaller x and higher y\n> > >         width: positive increment\n> > >         height: negative increment\n> > >\n> > >\n> > >\n> > >\n> > >                       ------------------------>\n> > >                       |  o-------\n> > >                       |  |      |\n> > >                       |  --------\n> > >                       |\n> > >                       |\n> > >                       V\n> > >\n> > >         top-left: Smaller x and smaller y\n> > >         width: positive increment\n> > >         height: positive increment\n> > >\n> > >\n> > > I thought our Rectangle definition didn't make assumptions on the\n> > > reference's system orientation and in fact that's what part of the\n> > > documentation says, but indeed the usage of \"top-left\" is, as shown,\n> > > ambiguous.\n> > >\n> > > So I went and changed that to be the \"corner closer to the origin\n> > > point\" and specified in documentation that vertical and horizontal\n> > > increments are always positive and I thought I was done with this, but\n> > > then I made the mistake of talking about negative increments and\n> > > 4-plane systems and here we are.\n> > >\n> > >\n> > > > Do you mean that the new description, like\n> > > > `The horizontal coordinate of the rectangle's origin corner`,\n> > > > only fits with the 1-plane reference system? I thought it should fit all\n> > > > 2D reference systems.\n> > >\n> > > I don't think that has never been the case, but indeed we have a\n> > > constructor that takes \"signed\" x and y.\n> >\n> > IIUC, you mean `you don't think that has ever been the case`, right?\n> >\n>\n>\n> No, I meant \"I don't think the Rectangle class has been designed\n> to fit all 2D reference systems\".\n>\n> > >\n> > > To be honest I would not be concerned about 4-planes systems, we're\n> > > talking about imaging and what is relevant here is that we should be\n> > > allowed to express rectangles on reference systems that can be\n> > > oriented differently, think of a sensor's pixel array that might be\n> > > represented with the (0, 0) position in the top-left corner compared\n> > > to a plane 2-d image that usually has its origin in the bottom-left\n> > > corner.\n> > >\n> > > I have an hard time finding a use case for expressing negative\n> > > coordinates in this usage context. Furthermore that if we introduce 4\n> > > planes we lose the ability to describe systems with different\n> > > orientation, as this:\n> > >\n> > >                       ------------------------>\n> > >                       |  o-------\n> > >                       |  |      |\n> > >                       |  --------\n> > >                       |\n> > >                       |\n> > >                       V\n> > >\n> > > when expressed in a 4-planes system becomes\n> > >\n> > >                       ^\n> > >                       |\n> > >                       |\n> > >                       |\n> > >                       |\n> > >         <--------------------------->\n> > >                       |/////////////\n> > >                       |/////////////\n> > >                       |// this /////\n> > >                       |/////////////\n> > >                       |/////////////\n> > >                       V\n> > >\n> > > And would require you to express y and height in negative coordinates.\n> > > Sincerely, I would not go there.\n> > >\n> > > I can specify that the Rectangle class reference system is always a\n> > > 2-d plane with positively increasing x and y axes instead.\n> >\n> > Yeah I think specifying that is a great idea, and maybe a TODO to\n> > set `x` and `y` to be unsigned int.\n>\n> I can try to do this right away and see if any compiler complains\n> about that.\n>\n> > I hope no pipeline handlers is using signed coordinates when we\n> > make the change in the API.\n>\n> However, geometry.h is public API, some applications might be affected\n> by this change.\n>\n> >\n> > Sorry for the chaos.\n> >\n>\n> np, if it helps to make the final result better chaos is welcome.\n\nSeems like I made even more chaos\n\nI tried to standardize the gemotry library to work with a single\nquadrant (what I called 'plane' in the previous email is actually a\n'quadrant') but it's a mess, we translate and move rectangles and\ndefining the behaviour when it happens to get into negative\ncoordinates is tricky and I don't like the result.\n\nI also have gone through the issue with Laurent and it's probably\nbetter to take a step back\n\n1) let's define top-left as the point with smallest x and smallest y\n(even if it's not actually top-left), I'll send a patch to update the doc\n2) You 2 points constructors could be re-implemented on this by taking\nthe min(p1.x, p2.x) and min(p1.y, p2.y), this shouldn't be ambiguous\nanymore if we always take the \"smallest\" point\n4) with your ack I'll rebase your series on my patch and will send out\na new version\n\nonce reviewed I'll merge them\n\nThanks and sorry for this long thread\n\n>\n> > >\n> > > >\n> > > > >\n> > > > > The problem at hands now is relevant for 1-planes reference systems,\n> > > > > that can be oriented differently, in example with the origin point\n> > > > > being in top-left or bottom-left positions, as per the examples above.\n> > > > > In this case I think we agree that \"top-left\" is ambiguous. The x and\n> > > > > y coordinates are always positive in the case with a single plane.\n> > > > >\n> > > > > I think we should also be concerned with 1 plane reference systems and\n> > > > > move forward with this patch that removes references to the visual\n> > > > > \"top-left\" and assumes increments in width and height are always\n> > > > > positive.\n> > > > >\n> > > > > > >\n> > > > > > > > corner, and currently libcamera::Size only allows non-negative width and\n> > > > > > > > height [1].\n> > > > > > >\n> > > > > > > True, Size uses unsigned int. I don't think it's a big deal and I'm\n> > > > > > > not proposing to introduce a new constructor with signed width and\n> > > > > > > height now, but my point is that if the need arises we can now do\n> > > > > > > that.\n> > > > > > >\n> > > > > > > >\n> > > > > > > > [1]:\n> > > > > > > > https://git.libcamera.org/libcamera/libcamera.git/tree/include/libcamera/geometry.h#n65\n> > > > > > > >\n> > > > > > > >\n> > > > > > > > > >\n> > > > > > > > > >\n> > > > > > > > > > >\n> > > > > > > > > > > > BR,\n> > > > > > > > > > > > Harvey\n> > > > > > > > > > > >\n> > > > > > > > > > > >\n> > > > > > > > > > > > > >    */\n> > > > > > > > > > > > > >\n> > > > > > > > > > > > > >   /**\n> > > > > > > > > > > > > >    * \\fn Rectangle::Rectangle(int x, int y, unsigned int width,\n> > > > > > > > > > > unsigned int height)\n> > > > > > > > > > > > > >    * \\brief Construct a Rectangle with the given position and\n> > > > > > > > > size\n> > > > > > > > > > > > > > - * \\param[in] x The horizontal coordinate of the top-left corner\n> > > > > > > > > > > > > > - * \\param[in] y The vertical coordinate of the top-left corner\n> > > > > > > > > > > > > > + * \\param[in] x The horizontal coordinate of the origin corner\n> > > > > > > > > > > > > > + * \\param[in] y The vertical coordinate of the origin corner\n> > > > > > > > > > > > > >    * \\param[in] width The width\n> > > > > > > > > > > > > >    * \\param[in] height The height\n> > > > > > > > > > > > > > + *\n> > > > > > > > > > > > > > + * The rectangle's origin corner is the corner closer to the\n> > > > > > > > > > > reference system\n> > > > > > > > > > > > > > + * origin point (0, 0).\n> > > > > > > > > > > > > >    */\n> > > > > > > > > > > > > >\n> > > > > > > > > > > > > >   /**\n> > > > > > > > > > > > > >    * \\fn Rectangle::Rectangle(const Size &size)\n> > > > > > > > > > > > > > - * \\brief Construct a Rectangle of \\a size with its top left\n> > > > > > > > > corner\n> > > > > > > > > > > located\n> > > > > > > > > > > > > > + * \\brief Construct a Rectangle of \\a size with its origin\n> > > > > > > > > corner\n> > > > > > > > > > > located\n> > > > > > > > > > > > > >    * at (0,0)\n> > > > > > > > > > > > > >    * \\param[in] size The desired Rectangle size\n> > > > > > > > > > > > > > + *\n> > > > > > > > > > > > > > + * The rectangle's origin corner is the corner closer to the\n> > > > > > > > > > > reference system\n> > > > > > > > > > > > > > + * origin point (0, 0).\n> > > > > > > > > > > > > >    */\n> > > > > > > > > > > > > >\n> > > > > > > > > > > > > >   /**\n> > > > > > > > > > > > > >    * \\var Rectangle::x\n> > > > > > > > > > > > > > - * \\brief The horizontal coordinate of the rectangle's top-left\n> > > > > > > > > > > corner\n> > > > > > > > > > > > > > + * \\brief The horizontal coordinate of the rectangle's origin\n> > > > > > > > > corner\n> > > > > > > > > > > > > > + *\n> > > > > > > > > > > > > > + * The rectangle's origin corner is the corner closer to the\n> > > > > > > > > > > reference system\n> > > > > > > > > > > > > > + * origin point (0, 0).\n> > > > > > > > > > > > > >    */\n> > > > > > > > > > > > > >\n> > > > > > > > > > > > > >   /**\n> > > > > > > > > > > > > >    * \\var Rectangle::y\n> > > > > > > > > > > > > > - * \\brief The vertical coordinate of the rectangle's top-left\n> > > > > > > > > corner\n> > > > > > > > > > > > > > + * \\brief The vertical coordinate of the rectangle's origin\n> > > > > > > > > corner\n> > > > > > > > > > > > > > + *\n> > > > > > > > > > > > > > + * The rectangle's origin corner is the corner closer to the\n> > > > > > > > > > > reference system\n> > > > > > > > > > > > > > + * origin point (0, 0).\n> > > > > > > > > > > > > >    */\n> > > > > > > > > > > > > >\n> > > > > > > > > > > > > >   /**\n> > > > > > > > > > > > > > @@ -683,9 +726,13 @@ Point Rectangle::center() const\n> > > > > > > > > > > > > >    */\n> > > > > > > > > > > > > >\n> > > > > > > > > > > > > >   /**\n> > > > > > > > > > > > > > - * \\fn Point Rectangle::topLeft() const\n> > > > > > > > > > > > > > - * \\brief Retrieve the coordinates of the top left corner of\n> > > > > > > > > this\n> > > > > > > > > > > Rectangle\n> > > > > > > > > > > > > > - * \\return The Rectangle's top left corner\n> > > > > > > > > > > > > > + * \\fn Point Rectangle::origin() const\n> > > > > > > > > > > > > > + * \\brief Retrieve the coordinates of the origin corner of this\n> > > > > > > > > > > Rectangle\n> > > > > > > > > > > > > > + *\n> > > > > > > > > > > > > > + * The rectangle's origin corner is the corner closer to the\n> > > > > > > > > > > reference system\n> > > > > > > > > > > > > > + * origin point (0, 0).\n> > > > > > > > > > > > > > + *\n> > > > > > > > > > > > > > + * \\return The Rectangle's origin corner\n> > > > > > > > > > > > >\n> > > > > > > > > > > > > I think you can drop \"corner\" from \"origin corner\"\n> > > > > > > > > > > > >\n> > > > > > > > > > > > > Probably throughout the patch:\n> > > > > > > > > > > > >      s/origin corner/origin/\n> > > > > > > > > > > > >\n> > > > > > > > > > > > > Otherwise, LGTM\n> > > > > > > > > > > > >\n> > > > > > > > > > > > > Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>\n> > > > > > > > > > > > > >    */\n> > > > > > > > > > > > > >\n> > > > > > > > > > > > > >   /**\n> > > > > > > > > > > > > > @@ -740,15 +787,15 @@ Rectangle &Rectangle::translateBy(const\n> > > > > > > > > Point\n> > > > > > > > > > > &point)\n> > > > > > > > > > > > > >    */\n> > > > > > > > > > > > > >   Rectangle Rectangle::boundedTo(const Rectangle &bound) const\n> > > > > > > > > > > > > >   {\n> > > > > > > > > > > > > > -     int topLeftX = std::max(x, bound.x);\n> > > > > > > > > > > > > > -     int topLeftY = std::max(y, bound.y);\n> > > > > > > > > > > > > > +     int originX = std::max(x, bound.x);\n> > > > > > > > > > > > > > +     int originY = std::max(y, bound.y);\n> > > > > > > > > > > > > >       int bottomRightX = std::min<int>(x + width, bound.x +\n> > > > > > > > > > > bound.width);\n> > > > > > > > > > > > > >       int bottomRightY = std::min<int>(y + height, bound.y +\n> > > > > > > > > > > bound.height);\n> > > > > > > > > > > > > >\n> > > > > > > > > > > > > > -     unsigned int newWidth = std::max(bottomRightX - topLeftX,\n> > > > > > > > > 0);\n> > > > > > > > > > > > > > -     unsigned int newHeight = std::max(bottomRightY - topLeftY,\n> > > > > > > > > 0);\n> > > > > > > > > > > > > > +     unsigned int newWidth = std::max(bottomRightX - originX,\n> > > > > > > > > 0);\n> > > > > > > > > > > > > > +     unsigned int newHeight = std::max(bottomRightY - originY,\n> > > > > > > > > 0);\n> > > > > > > > > > > > > >\n> > > > > > > > > > > > > > -     return { topLeftX, topLeftY, newWidth, newHeight };\n> > > > > > > > > > > > > > +     return { originX, originY, newWidth, newHeight };\n> > > > > > > > > > > > > >   }\n> > > > > > > > > > > > > >\n> > > > > > > > > > > > > >   /**\n> > > > > > > > > > > > > > diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n> > > > > > > > > > > b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n> > > > > > > > > > > > > > index 3041fd1ed9fd..8d2440026689 100644\n> > > > > > > > > > > > > > --- a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n> > > > > > > > > > > > > > +++ b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n> > > > > > > > > > > > > > @@ -1289,7 +1289,7 @@ Rectangle CameraData::scaleIspCrop(const\n> > > > > > > > > > > Rectangle &ispCrop) const\n> > > > > > > > > > > > > >        */\n> > > > > > > > > > > > > >       Rectangle nativeCrop =\n> > > > > > > > > > > ispCrop.scaledBy(sensorInfo_.analogCrop.size(),\n> > > > > > > > > > > > > >\n> > > > > > > > > > >  sensorInfo_.outputSize);\n> > > > > > > > > > > > > > -     nativeCrop.translateBy(sensorInfo_.analogCrop.topLeft());\n> > > > > > > > > > > > > > +     nativeCrop.translateBy(sensorInfo_.analogCrop.origin());\n> > > > > > > > > > > > > >       return nativeCrop;\n> > > > > > > > > > > > > >   }\n> > > > > > > > > > > > > >\n> > > > > > > > > > > > > > @@ -1303,7 +1303,7 @@ void CameraData::applyScalerCrop(const\n> > > > > > > > > > > ControlList &controls)\n> > > > > > > > > > > > > >                       nativeCrop = { 0, 0, 1, 1 };\n> > > > > > > > > > > > > >\n> > > > > > > > > > > > > >               /* Create a version of the crop scaled to ISP\n> > > > > > > > > (camera\n> > > > > > > > > > > mode) pixels. */\n> > > > > > > > > > > > > > -             Rectangle ispCrop =\n> > > > > > > > > > > nativeCrop.translatedBy(-sensorInfo_.analogCrop.topLeft());\n> > > > > > > > > > > > > > +             Rectangle ispCrop =\n> > > > > > > > > > > nativeCrop.translatedBy(-sensorInfo_.analogCrop.origin());\n> > > > > > > > > > > > > >               ispCrop.scaleBy(sensorInfo_.outputSize,\n> > > > > > > > > > > sensorInfo_.analogCrop.size());\n> > > > > > > > > > > > > >\n> > > > > > > > > > > > > >               /*\n> > > > > > > > > > > > > > diff --git a/src/py/libcamera/py_geometry.cpp\n> > > > > > > > > > > b/src/py/libcamera/py_geometry.cpp\n> > > > > > > > > > > > > > index c7e303609427..8dee365b25dd 100644\n> > > > > > > > > > > > > > --- a/src/py/libcamera/py_geometry.cpp\n> > > > > > > > > > > > > > +++ b/src/py/libcamera/py_geometry.cpp\n> > > > > > > > > > > > > > @@ -105,7 +105,7 @@ void init_py_geometry(py::module &m)\n> > > > > > > > > > > > > >               .def_property_readonly(\"is_null\",\n> > > > > > > > > &Rectangle::isNull)\n> > > > > > > > > > > > > >               .def_property_readonly(\"center\",\n> > > > > > > > > &Rectangle::center)\n> > > > > > > > > > > > > >               .def_property_readonly(\"size\", &Rectangle::size)\n> > > > > > > > > > > > > > -             .def_property_readonly(\"topLeft\",\n> > > > > > > > > &Rectangle::topLeft)\n> > > > > > > > > > > > > > +             .def_property_readonly(\"origin\",\n> > > > > > > > > &Rectangle::origin)\n> > > > > > > > > > > > > >               .def(\"scale_by\", &Rectangle::scaleBy)\n> > > > > > > > > > > > > >               .def(\"translate_by\", &Rectangle::translateBy)\n> > > > > > > > > > > > > >               .def(\"bounded_to\", &Rectangle::boundedTo)\n> > > > > > > > > > > > > > diff --git a/test/geometry.cpp b/test/geometry.cpp\n> > > > > > > > > > > > > > index 64169206ad16..a4ee6f6e167a 100644\n> > > > > > > > > > > > > > --- a/test/geometry.cpp\n> > > > > > > > > > > > > > +++ b/test/geometry.cpp\n> > > > > > > > > > > > > > @@ -363,16 +363,16 @@ protected:\n> > > > > > > > > > > > > >                       return TestFail;\n> > > > > > > > > > > > > >               }\n> > > > > > > > > > > > > >\n> > > > > > > > > > > > > > -             /* Rectangle::size(), Rectangle::topLeft() and\n> > > > > > > > > > > Rectangle::center() tests */\n> > > > > > > > > > > > > > +             /* Rectangle::size(), Rectangle::origin() and\n> > > > > > > > > > > Rectangle::center() tests */\n> > > > > > > > > > > > > >               if (Rectangle(-1, -2, 3, 4).size() != Size(3, 4) ||\n> > > > > > > > > > > > > >                   Rectangle(0, 0, 100000, 200000).size() !=\n> > > > > > > > > > > Size(100000, 200000)) {\n> > > > > > > > > > > > > >                       cout << \"Rectangle::size() test failed\" <<\n> > > > > > > > > > > endl;\n> > > > > > > > > > > > > >                       return TestFail;\n> > > > > > > > > > > > > >               }\n> > > > > > > > > > > > > >\n> > > > > > > > > > > > > > -             if (Rectangle(1, 2, 3, 4).topLeft() != Point(1, 2)\n> > > > > > > > > ||\n> > > > > > > > > > > > > > -                 Rectangle(-1, -2, 3, 4).topLeft() != Point(-1,\n> > > > > > > > > > > -2)) {\n> > > > > > > > > > > > > > -                     cout << \"Rectangle::topLeft() test failed\"\n> > > > > > > > > <<\n> > > > > > > > > > > endl;\n> > > > > > > > > > > > > > +             if (Rectangle(1, 2, 3, 4).origin() != Point(1, 2)\n> > > > > > > > > ||\n> > > > > > > > > > > > > > +                 Rectangle(-1, -2, 3, 4).origin() != Point(-1,\n> > > > > > > > > -2))\n> > > > > > > > > > > {\n> > > > > > > > > > > > > > +                     cout << \"Rectangle::origin() test failed\"\n> > > > > > > > > <<\n> > > > > > > > > > > endl;\n> > > > > > > > > > > > > >                       return TestFail;\n> > > > > > > > > > > > > >               }\n> > > > > > > > > > > > > >\n> > > > > > > > > > > > > > --\n> > > > > > > > > > > > > > 2.46.1\n> > > > > > > > > > > > > >\n> > > > > > > > > > > > >\n> > > > > > > > > > > >\n> > > > > > > > > > > >\n> > > > > > > > > > > > --\n> > > > > > > > > > > > BR,\n> > > > > > > > > > > > Harvey Yang\n> > > > > > > > > > >\n> > > > > > > > >\n> > > > > >\n> > > > > >\n> > > > > >\n> > > > > > --\n> > > > > > BR,\n> > > > > > Harvey Yang\n> > > >\n> > > >\n> > > >\n> > > > --\n> > > > BR,\n> > > > Harvey Yang\n> >\n> >\n> >\n> > --\n> > BR,\n> > Harvey Yang","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 93629C0F1B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 27 Sep 2024 14:50:58 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 9E3916350F;\n\tFri, 27 Sep 2024 16:50:57 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 4A887634F2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 27 Sep 2024 16:50:55 +0200 (CEST)","from ideasonboard.com (mob-5-90-58-180.net.vodafone.it\n\t[5.90.58.180])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 13D9E83D;\n\tFri, 27 Sep 2024 16:49:24 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"s8M+Mz0Q\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1727448566;\n\tbh=6BrZIqfsw2ojEJcopQggkjEm3Qjcn7qEHKgZAo16uSA=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=s8M+Mz0QOgv+08fBx63VKumfoQh3ha88CfAEat+wSjoAmplZDjlWfDY1xsvAqgMYV\n\tvUVTzjh4ddOgjpd/iaP0L2Lynzx5r/qixyxPV//JqxG15vAVPKKXQcqUsgFcO+O5Cl\n\tgxTSudl5YAGUxWxjiGX9JidDlMoc63y2lLM5ZxYE=","Date":"Fri, 27 Sep 2024 16:50:47 +0200","From":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>","To":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>","Cc":"Cheng-Hao Yang <chenghaoyang@google.com>, \n\tUmang Jain <umang.jain@ideasonboard.com>,\n\tlibcamera devel <libcamera-devel@lists.libcamera.org>","Subject":"Re: [PATCH] libcamera: geometry: Rename Rectangle's top-left corner","Message-ID":"<jhm5lkl4kkjs3e2dydelkdeju3hqwwobxq3l6pg36knebrppdv@lrjdkupwnogu>","References":"<CAC=wSGWEZU7_=nEFTp+g_g74L7kcs65wK3oOeS8xwBqzMHa5wQ@mail.gmail.com>\n\t<zsszrdewqlrlovncquphk43ajxyksfoijoiorglvwem4kb2u6q@my2gscqpdzd3>\n\t<CAC=wSGXj==p2GZMidtwb9pUhmnuRrdqbGhQUF14HSNfTzgz_Cw@mail.gmail.com>\n\t<62yvkiqioilupdcm7ryjtrz273iamzojfi2pgxndmjwoyyaitb@iq46e47ke2vg>\n\t<CAC=wSGXgYv2YyZqwgRANhmVzPtLTkTHP4=R-_Sz+NE7wNzPJXw@mail.gmail.com>\n\t<6cnkhto53ixz7hafosgqebixvfdpwftc24ach46wsvv6qpjmkv@h7e25hene6yc>\n\t<CAC=wSGU3ubNji42mp-4eXH7L34ZZE0vP_NA5Uu1fKgUsQTvG7Q@mail.gmail.com>\n\t<juj2axmwzwss5axiy3y6l4hetonuv72oyzgb6ekf5hbt66it73@j23uammf6fl7>\n\t<CAC=wSGVEjJ-fHo4W31OGU2Qk8=OhhzYNCW4qFxqLLdtTu0kGrw@mail.gmail.com>\n\t<cdtdrnjxni6trvlsmejd24ihlbujtqo4sxq4x7gwktitzua4rz@msm5if6yuae5>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<cdtdrnjxni6trvlsmejd24ihlbujtqo4sxq4x7gwktitzua4rz@msm5if6yuae5>","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>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":31451,"web_url":"https://patchwork.libcamera.org/comment/31451/","msgid":"<CAC=wSGUUe83HiWGE_H=XvA23H=JTCiOvoJNpi0Y2OPaEhO89Hw@mail.gmail.com>","date":"2024-09-27T16:15:44","subject":"Re: [PATCH] libcamera: geometry: Rename Rectangle's top-left corner","submitter":{"id":148,"url":"https://patchwork.libcamera.org/api/people/148/","name":"Cheng-Hao Yang","email":"chenghaoyang@google.com"},"content":"Hi Jacopo,\n\nOn Fri, Sep 27, 2024 at 10:51 PM Jacopo Mondi\n<jacopo.mondi@ideasonboard.com> wrote:\n>\n> Hi again\n>\n> On Fri, Sep 27, 2024 at 10:54:20AM GMT, Jacopo Mondi wrote:\n> > Hi Harvey\n> >\n> > On Fri, Sep 27, 2024 at 04:46:06PM GMT, Cheng-Hao Yang wrote:\n> > > Hi Jacopo,\n> > >\n> > > On Fri, Sep 27, 2024 at 4:05 PM Jacopo Mondi\n> > > <jacopo.mondi@ideasonboard.com> wrote:\n> > > >\n> > > > Hi Harvey\n> > > >\n> > > > On Thu, Sep 26, 2024 at 11:22:58PM GMT, Cheng-Hao Yang wrote:\n> > > > > Hi Jacopo,\n> > > > >\n> > > > > On Thu, Sep 26, 2024 at 10:35 PM Jacopo Mondi\n> > > > > <jacopo.mondi@ideasonboard.com> wrote:\n> > > > > >\n> > > > > > Hi Harvey\n> > > > > >\n> > > > > > On Thu, Sep 26, 2024 at 10:03:55PM GMT, Cheng-Hao Yang wrote:\n> > > > > > > Hi Jacopo,\n> > > > > > >\n> > > > > > > On Thu, Sep 26, 2024 at 5:36 PM Jacopo Mondi\n> > > > > > > <jacopo.mondi@ideasonboard.com> wrote:\n> > > > > > > >\n> > > > > > > > Hi Harvey\n> > > > > > > >\n> > > > > > > > On Thu, Sep 26, 2024 at 05:28:13PM GMT, Cheng-Hao Yang wrote:\n> > > > > > > > > Hi Jacopo,\n> > > > > > > > >\n> > > > > > > > >\n> > > > > > > > >\n> > > > > > > > > On Thu, Sep 26, 2024, 4:38 PM Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n> > > > > > > > > wrote:\n> > > > > > > > >\n> > > > > > > > > > Hi Harvey\n> > > > > > > > > >\n> > > > > > > > > > On Thu, Sep 26, 2024 at 04:29:50PM GMT, Cheng-Hao Yang wrote:\n> > > > > > > > > > > Hi Jacopo,\n> > > > > > > > > > >\n> > > > > > > > > > > On Thu, Sep 26, 2024, 4:03 PM Jacopo Mondi <\n> > > > > > > > > > jacopo.mondi@ideasonboard.com>\n> > > > > > > > > > > wrote:\n> > > > > > > > > > >\n> > > > > > > > > > > > Hi Harvey\n> > > > > > > > > > > >\n> > > > > > > > > > > > On Wed, Sep 25, 2024 at 03:09:38PM GMT, Cheng-Hao Yang wrote:\n> > > > > > > > > > > > > Hi Jacopo,\n> > > > > > > > > > > > >\n> > > > > > > > > > > > > Thank you for the patch.\n> > > > > > > > > > > > >\n> > > > > > > > > > > > > On Wed, Sep 25, 2024 at 2:36 PM Umang Jain <\n> > > > > > > > > > umang.jain@ideasonboard.com>\n> > > > > > > > > > > > wrote:\n> > > > > > > > > > > > > >\n> > > > > > > > > > > > > > Hi Jacopo\n> > > > > > > > > > > > > >\n> > > > > > > > > > > > > > Thank you for the patch\n> > > > > > > > > > > > > >\n> > > > > > > > > > > > > > On 24/09/24 6:15 pm, Jacopo Mondi wrote:\n> > > > > > > > > > > > > > > The libcamera::Rectangle class should allow defining rectangles\n> > > > > > > > > > > > > > > regardless of the reference system where an instance is used in.\n> > > > > > > > > > > > > > >\n> > > > > > > > > > > > > > > However the class documentation assumes the reference system\n> > > > > > > > > > origin\n> > > > > > > > > > > > > > > point to be in the visual top-left side and that rectangles are\n> > > > > > > > > > > > > > > constructed by specifying the top-left corner position and sizes.\n> > > > > > > > > > > > > > >\n> > > > > > > > > > > > > > > However this is ambiguous when using a different reference\n> > > > > > > > > > system as,\n> > > > > > > > > > > > > > > in example, constructing a rectangle (x, y, w, h) in the\n> > > > > > > > > > following\n> > > > > > > > > > > > > > > scenario, with the origin corner in the top-left position, would\n> > > > > > > > > > > > require\n> > > > > > > > > > > > > > > a negative decrement along the y-axis.\n> > > > > > > > > > > > > > >\n> > > > > > > > > > > > > > >           ^\n> > > > > > > > > > > > > > >           |\n> > > > > > > > > > > > > > >          y|      o------------------\n> > > > > > > > > > > > > > >           |      |                 | h\n> > > > > > > > > > > > > > >           |      |                 |\n> > > > > > > > > > > > > > >           |      -------------------\n> > > > > > > > > > > > > > >           |               w\n> > > > > > > > > > > > > > >            ------------------------------->\n> > > > > > > > > > > > > > >           (0,0)  x\n> > > > > > > > > > > > > > >\n> > > > > > > > > > > > > > > To remove ambiguities, drop references to the visual top-left\n> > > > > > > > > > corner\n> > > > > > > > > > > > and\n> > > > > > > > > > > > > > > define the rectangle's origin corner as the corner closer to the\n> > > > > > > > > > > > > > > reference system origin point, and specify the horizontal and\n> > > > > > > > > > > > vertical\n> > > > > > > > > > > > > > > dimensions always increment along their respective axis, as in\n> > > > > > > > > > the\n> > > > > > > > > > > > > > > following example.\n> > > > > > > > > > > > > > >\n> > > > > > > > > > > > > > >           ^\n> > > > > > > > > > > > > > >           |\n> > > > > > > > > > > > > > >           |      -------------------\n> > > > > > > > > > > > > > >           |      ^                 | h\n> > > > > > > > > > > > > > >           |      |                 |\n> > > > > > > > > > > > > > >          y|      o---->-------------\n> > > > > > > > > > > > > > >           |               w\n> > > > > > > > > > > > > > >            ------------------------------->\n> > > > > > > > > > > > > > >           (0,0)  x\n> > > > > > > > > > > > > > >\n> > > > > > > > > > > > > > >           (0,0)  x\n> > > > > > > > > > > > > > >             ------------------------------>\n> > > > > > > > > > > > > > >            |              w\n> > > > > > > > > > > > > > >           y|     o---->-------------\n> > > > > > > > > > > > > > >            |     |                 | h\n> > > > > > > > > > > > > > >            |     v                 |\n> > > > > > > > > > > > > > >            |     -------------------\n> > > > > > > > > > > > > > >            |\n> > > > > > > > > > > > > > >            V\n> > > > > > > > > > > > > > >\n> > > > > > > > > > > > > > > Also rename for consistency the Rectangle::topLeft() function to\n> > > > > > > > > > > > > > > Rectangle::origin() and update its in-tree users.\n> > > > > > > > > > > > > > >\n> > > > > > > > > > > > > > > Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n> > > > > > > > > > > > > > > ---\n> > > > > > > > > > > > > > >   include/libcamera/geometry.h                  |  2 +-\n> > > > > > > > > > > > > > >   src/ipa/ipu3/algorithms/af.cpp                |  2 +-\n> > > > > > > > > > > > > > >   src/libcamera/geometry.cpp                    | 85\n> > > > > > > > > > > > ++++++++++++++-----\n> > > > > > > > > > > > > > >   .../pipeline/rpi/common/pipeline_base.cpp     |  4 +-\n> > > > > > > > > > > > > > >   src/py/libcamera/py_geometry.cpp              |  2 +-\n> > > > > > > > > > > > > > >   test/geometry.cpp                             |  8 +-\n> > > > > > > > > > > > > > >   6 files changed, 75 insertions(+), 28 deletions(-)\n> > > > > > > > > > > > > > >\n> > > > > > > > > > > > > > > diff --git a/include/libcamera/geometry.h\n> > > > > > > > > > > > b/include/libcamera/geometry.h\n> > > > > > > > > > > > > > > index 3e6f0f5d7fab..07cb0a7866fe 100644\n> > > > > > > > > > > > > > > --- a/include/libcamera/geometry.h\n> > > > > > > > > > > > > > > +++ b/include/libcamera/geometry.h\n> > > > > > > > > > > > > > > @@ -277,7 +277,7 @@ public:\n> > > > > > > > > > > > > > >               return { width, height };\n> > > > > > > > > > > > > > >       }\n> > > > > > > > > > > > > > >\n> > > > > > > > > > > > > > > -     Point topLeft() const\n> > > > > > > > > > > > > > > +     Point origin() const\n> > > > > > > > > > > > > > >       {\n> > > > > > > > > > > > > > >               return { x, y };\n> > > > > > > > > > > > > > >       }\n> > > > > > > > > > > > > > > diff --git a/src/ipa/ipu3/algorithms/af.cpp\n> > > > > > > > > > > > b/src/ipa/ipu3/algorithms/af.cpp\n> > > > > > > > > > > > > > > index cf68fb59c49b..1b707e9dd9ab 100644\n> > > > > > > > > > > > > > > --- a/src/ipa/ipu3/algorithms/af.cpp\n> > > > > > > > > > > > > > > +++ b/src/ipa/ipu3/algorithms/af.cpp\n> > > > > > > > > > > > > > > @@ -155,7 +155,7 @@ int Af::configure(IPAContext &context, const\n> > > > > > > > > > > > IPAConfigInfo &configInfo)\n> > > > > > > > > > > > > > >        * - Return the AF ROI as metadata in the Request\n> > > > > > > > > > > > > > >        */\n> > > > > > > > > > > > > > >       Rectangle roi = gridSize.centeredTo(bds.center());\n> > > > > > > > > > > > > > > -     Point start = roi.topLeft();\n> > > > > > > > > > > > > > > +     Point start = roi.origin();\n> > > > > > > > > > > > > > >\n> > > > > > > > > > > > > > >       /* x_start and y_start should be even */\n> > > > > > > > > > > > > > >       grid.x_start = utils::alignDown(start.x, 2);\n> > > > > > > > > > > > > > > diff --git a/src/libcamera/geometry.cpp\n> > > > > > > > > > b/src/libcamera/geometry.cpp\n> > > > > > > > > > > > > > > index 000151364c7f..45ba81a99920 100644\n> > > > > > > > > > > > > > > --- a/src/libcamera/geometry.cpp\n> > > > > > > > > > > > > > > +++ b/src/libcamera/geometry.cpp\n> > > > > > > > > > > > > > > @@ -593,11 +593,39 @@ std::ostream &operator<<(std::ostream &out,\n> > > > > > > > > > > > const SizeRange &sr)\n> > > > > > > > > > > > > > >    * \\brief Describe a rectangle's position and dimensions\n> > > > > > > > > > > > > > >    *\n> > > > > > > > > > > > > > >    * Rectangles are used to identify an area of an image. They\n> > > > > > > > > > are\n> > > > > > > > > > > > specified by\n> > > > > > > > > > > > > > > - * the coordinates of top-left corner and their horizontal and\n> > > > > > > > > > > > vertical size.\n> > > > > > > > > > > > > > > + * the coordinates of the corner closer to the reference\n> > > > > > > > > > system's\n> > > > > > > > > > > > origin point\n> > > > > > > > > > > > > > > + * and by horizontal and vertical increments from there.\n> > > > > > > > > > > > > > >    *\n> > > > > > > > > > > > > > > - * The measure unit of the rectangle coordinates and size, as\n> > > > > > > > > > well\n> > > > > > > > > > > > as the\n> > > > > > > > > > > > > > > - * reference point from which the Rectangle::x and Rectangle::y\n> > > > > > > > > > > > displacements\n> > > > > > > > > > > > > > > - * refers to, are defined by the context were rectangle is used.\n> > > > > > > > > > > > > > > + * The corner closer to the reference system's origin point is\n> > > > > > > > > > the\n> > > > > > > > > > > > rectangle's\n> > > > > > > > > > > > > > > + * origin corner.\n> > > > > > > > > > > > > > > + *\n> > > > > > > > > > > > > > > + * \\verbatim\n> > > > > > > > > > > > > > > +\n> > > > > > > > > > > > > > > +  o = origin corner\n> > > > > > > > > > > > > > > +\n> > > > > > > > > > > > > > > +         ^\n> > > > > > > > > > > > > > > +         |\n> > > > > > > > > > > > > > > +         |      -------------------\n> > > > > > > > > > > > > > > +         |      ^                 |\n> > > > > > > > > > > > > > > +         |      |                 |\n> > > > > > > > > > > > > > > +         |      o---->-------------\n> > > > > > > > > > > > > > > +         |\n> > > > > > > > > > > > > > > +          ------------------------------->\n> > > > > > > > > > > > > > > +         (0,0)\n> > > > > > > > > > > > > > > +\n> > > > > > > > > > > > > > > +         (0,0)\n> > > > > > > > > > > > > > > +           ------------------------------->\n> > > > > > > > > > > > > > > +          |\n> > > > > > > > > > > > > > > +          |      o---->-------------\n> > > > > > > > > > > > > > > +          |      |                 |\n> > > > > > > > > > > > > > > +          |      v                 |\n> > > > > > > > > > > > > > > +          |      -------------------\n> > > > > > > > > > > > > > > +          |\n> > > > > > > > > > > > > > > +          V\n> > > > > > > > > > > > > > > +   \\endverbatim\n> > > > > > > > > > > > > > > + *\n> > > > > > > > > > > > > > > + * The measure unit of the rectangle coordinates and size are\n> > > > > > > > > > > > defined by the\n> > > > > > > > > > > > > > > + * context were the rectangle is used.\n> > > > > > > > > > > > > > >    */\n> > > > > > > > > > > > > > >\n> > > > > > > > > > > > > > >   /**\n> > > > > > > > > > > > > > > @@ -608,35 +636,50 @@ std::ostream &operator<<(std::ostream &out,\n> > > > > > > > > > > > const SizeRange &sr)\n> > > > > > > > > > > > > > >   /**\n> > > > > > > > > > > > > > >    * \\fn Rectangle::Rectangle(int x, int y, const Size &size)\n> > > > > > > > > > > > > > >    * \\brief Construct a Rectangle with the given position and\n> > > > > > > > > > size\n> > > > > > > > > > > > > > > - * \\param[in] x The horizontal coordinate of the top-left corner\n> > > > > > > > > > > > > > > - * \\param[in] y The vertical coordinate of the top-left corner\n> > > > > > > > > > > > > > > + * \\param[in] x The horizontal coordinate of the origin corner\n> > > > > > > > > > > > > > > + * \\param[in] y The vertical coordinate of the origin corner\n> > > > > > > > > > > > > > >    * \\param[in] size The size\n> > > > > > > > > > > > > > > + *\n> > > > > > > > > > > > > > > + * The rectangle's origin corner is the corner closer to the\n> > > > > > > > > > > > reference system\n> > > > > > > > > > > > > > > + * origin point (0, 0).\n> > > > > > > > > > > > >\n> > > > > > > > > > > > > I think we should stick to the previous description:\n> > > > > > > > > > > > > `\"origin\" point defined as the point with the lower x and\n> > > > > > > > > > > > > lower y of the rectangle`, as `x` and `y` are signed integers.\n> > > > > > > > > > > > >\n> > > > > > > > > > > > > If we only support coordinates that are positive or 0, which\n> > > > > > > > > > > > > I'm not sure if it's the case, how about making the type to be\n> > > > > > > > > > > > > `unsigned int`?\n> > > > > > > > > > > > >\n> > > > > > > > > > > >\n> > > > > > > > > > > > To be honest I would rather make width and heigh signed to allow\n> > > > > > > > > > > > constructing (x, y, -w, -h)\n> > > > > > > > > > > >\n> > > > > > > > > > > >\n> > > > > > > > > > > >\n> > > > > > > > > > > >\n> > > > > > > > > > > >                -------------------\n> > > > > > > > > > > >                |                 ^\n> > > > > > > > > > > >                |            ------------->\n> > > > > > > > > > > >                |           |     |\n> > > > > > > > > > > >                ------<-----|-----o\n> > > > > > > > > > > >                            |\n> > > > > > > > > > > >                            |\n> > > > > > > > > > > >                            V\n> > > > > > > > > > > >\n> > > > > > > > > > > > Not sure if it's useful or not though\n> > > > > > > > > > > >\n> > > > > > > > > > >\n> > > > > > > > > > > Hmm... I find it pretty weird. What if all four corners have all negative\n> > > > > > > > > > > coordinates?\n> > > > > > > > > > >\n> > > > > > > > > > >\n> > > > > > > > > >\n> > > > > > > > > > Don't know, maybe if the reference system where the rectangle is used\n> > > > > > > > > > into has 4 planes and so an all-negative rectangle makes sense.\n> > > > > > > > > >\n> > > > > > > > > > My point is that we should allow users of this class to express\n> > > > > > > > > > Rectangle in any context they plan to use them. Not sure if I'm going\n> > > > > > > > > > overboard here or it makes sense.\n> > > > > > > > > >\n> > > > > > > > >\n> > > > > > > > > Yeah I agree, while doesn't that mean the description doesn't fit all\n> > > > > > > > > cases, like the corner closer to the reference system origin point of a\n> > > > > > > > > rectangle that has all negative coordinates is actually the \"bottom-right\"\n> > > > > > > >\n> > > > > > > > This patch aims to remove all references to \"top-left\" or in general\n> > > > > > > > to any visual reference exactly for that purpose. Or have I forgot any\n> > > > > > > > ?\n> > > > > > >\n> > > > > > > In this c'tor `\\fn Rectangle::Rectangle(int x, int y, const Size &size)`,\n> > > > > > > the description of `x` and `y` are updated to \"coordinates of the origin\n> > > > > > > corner\", where the origin corner is \"the corner closer to the reference\n> > > > > > > system origin point (0, 0).\"\n> > > > > > >\n> > > > > > > As currently libcamera::Size takes only non-negative width and height,\n> > > > > > > take rectangle [(-3, -3), (-3, -1), (-1, -3), (-1, -1)] as the example, you\n> > > > > > > can find that the only valid way to construct this rectangle as\n> > > > > > > libcamera::Rectangle is `{x = -3, y = -3, size = {2, 2}}`. However, this\n> > > > > > > doesn't fit with your updated description, as the corner closer to the\n> > > > > > > reference system origin point (0, 0) is actually (-1, -1), instead of\n> > > > > > > (-3, -3).\n> > > > > > >\n> > > > > >\n> > > > > > You're right. Let's take a step back though. If we have a 4 planes reference\n> > > > > > system, we always have a visual top-left indeed. As the 4 planes have\n> > > > > > negative and positive coordinates, we can describe with absolute\n> > > > > > positions the rectangle and all points in the system.\n> > > > >\n> > > > > Sorry, I still don't get your point...\n> > > > >\n> > > >\n> > > > If you have a 4 planes system\n> > > >\n> > > >                       ^\n> > > >                       |\n> > > >                       |\n> > > >                       |\n> > > >                       |\n> > > >         <--------------------------->\n> > > >                       |\n> > > >                       |\n> > > >                       |\n> > > >                       |\n> > > >                       V\n> > > >\n> > > > Then you always have a top, a left, and bottom and a right, you can\n> > > > describe width and height as negative or positive increments and your\n> > > > rectangle is always well defined as the reference system cannot be\n> > > > ambiguous. The very concept of \"reference system orientation\" doesn't\n> > > > make sense, as a 4-planes system describes the full 2-d space.\n> > > >\n> > > > The ambiguity I'm trying to solve is about using a 1 plane reference\n> > > > system, as depending on how the system is oriented the definition of\n> > > > the \"top-left\" point might change, as well as the definition of the\n> > > > horizontal and vertical increments change as well.\n> > > >\n> > > > In example:\n> > > >\n> > > >                       ^\n> > > >                       |\n> > > >                       |\n> > > >                       |  o-------\n> > > >                       |  |      |\n> > > >                       |  --------\n> > > >                       |\n> > > >                       ------------------------>\n> > > >\n> > > >         top-left: Smaller x and higher y\n> > > >         width: positive increment\n> > > >         height: negative increment\n> > > >\n> > > >\n> > > >\n> > > >\n> > > >                       ------------------------>\n> > > >                       |  o-------\n> > > >                       |  |      |\n> > > >                       |  --------\n> > > >                       |\n> > > >                       |\n> > > >                       V\n> > > >\n> > > >         top-left: Smaller x and smaller y\n> > > >         width: positive increment\n> > > >         height: positive increment\n> > > >\n> > > >\n> > > > I thought our Rectangle definition didn't make assumptions on the\n> > > > reference's system orientation and in fact that's what part of the\n> > > > documentation says, but indeed the usage of \"top-left\" is, as shown,\n> > > > ambiguous.\n> > > >\n> > > > So I went and changed that to be the \"corner closer to the origin\n> > > > point\" and specified in documentation that vertical and horizontal\n> > > > increments are always positive and I thought I was done with this, but\n> > > > then I made the mistake of talking about negative increments and\n> > > > 4-plane systems and here we are.\n> > > >\n> > > >\n> > > > > Do you mean that the new description, like\n> > > > > `The horizontal coordinate of the rectangle's origin corner`,\n> > > > > only fits with the 1-plane reference system? I thought it should fit all\n> > > > > 2D reference systems.\n> > > >\n> > > > I don't think that has never been the case, but indeed we have a\n> > > > constructor that takes \"signed\" x and y.\n> > >\n> > > IIUC, you mean `you don't think that has ever been the case`, right?\n> > >\n> >\n> >\n> > No, I meant \"I don't think the Rectangle class has been designed\n> > to fit all 2D reference systems\".\n> >\n> > > >\n> > > > To be honest I would not be concerned about 4-planes systems, we're\n> > > > talking about imaging and what is relevant here is that we should be\n> > > > allowed to express rectangles on reference systems that can be\n> > > > oriented differently, think of a sensor's pixel array that might be\n> > > > represented with the (0, 0) position in the top-left corner compared\n> > > > to a plane 2-d image that usually has its origin in the bottom-left\n> > > > corner.\n> > > >\n> > > > I have an hard time finding a use case for expressing negative\n> > > > coordinates in this usage context. Furthermore that if we introduce 4\n> > > > planes we lose the ability to describe systems with different\n> > > > orientation, as this:\n> > > >\n> > > >                       ------------------------>\n> > > >                       |  o-------\n> > > >                       |  |      |\n> > > >                       |  --------\n> > > >                       |\n> > > >                       |\n> > > >                       V\n> > > >\n> > > > when expressed in a 4-planes system becomes\n> > > >\n> > > >                       ^\n> > > >                       |\n> > > >                       |\n> > > >                       |\n> > > >                       |\n> > > >         <--------------------------->\n> > > >                       |/////////////\n> > > >                       |/////////////\n> > > >                       |// this /////\n> > > >                       |/////////////\n> > > >                       |/////////////\n> > > >                       V\n> > > >\n> > > > And would require you to express y and height in negative coordinates.\n> > > > Sincerely, I would not go there.\n> > > >\n> > > > I can specify that the Rectangle class reference system is always a\n> > > > 2-d plane with positively increasing x and y axes instead.\n> > >\n> > > Yeah I think specifying that is a great idea, and maybe a TODO to\n> > > set `x` and `y` to be unsigned int.\n> >\n> > I can try to do this right away and see if any compiler complains\n> > about that.\n> >\n> > > I hope no pipeline handlers is using signed coordinates when we\n> > > make the change in the API.\n> >\n> > However, geometry.h is public API, some applications might be affected\n> > by this change.\n> >\n> > >\n> > > Sorry for the chaos.\n> > >\n> >\n> > np, if it helps to make the final result better chaos is welcome.\n>\n> Seems like I made even more chaos\n>\n> I tried to standardize the gemotry library to work with a single\n> quadrant (what I called 'plane' in the previous email is actually a\n> 'quadrant') but it's a mess, we translate and move rectangles and\n> defining the behaviour when it happens to get into negative\n> coordinates is tricky and I don't like the result.\n>\n> I also have gone through the issue with Laurent and it's probably\n> better to take a step back\n>\n> 1) let's define top-left as the point with smallest x and smallest y\n> (even if it's not actually top-left), I'll send a patch to update the doc\n\nYes, this is more ideal in my opinion, and it's what I expected :)\n\n> 2) You 2 points constructors could be re-implemented on this by taking\n> the min(p1.x, p2.x) and min(p1.y, p2.y), this shouldn't be ambiguous\n> anymore if we always take the \"smallest\" point\n> 4) with your ack I'll rebase your series on my patch and will send out\n> a new version\n\nSure, thanks for the effort!\n\n>\n> once reviewed I'll merge them\n>\n> Thanks and sorry for this long thread\n\nNo worries. It's nice to discuss and find the best way to go with\ntogether!\n\n>\n> >\n> > > >\n> > > > >\n> > > > > >\n> > > > > > The problem at hands now is relevant for 1-planes reference systems,\n> > > > > > that can be oriented differently, in example with the origin point\n> > > > > > being in top-left or bottom-left positions, as per the examples above.\n> > > > > > In this case I think we agree that \"top-left\" is ambiguous. The x and\n> > > > > > y coordinates are always positive in the case with a single plane.\n> > > > > >\n> > > > > > I think we should also be concerned with 1 plane reference systems and\n> > > > > > move forward with this patch that removes references to the visual\n> > > > > > \"top-left\" and assumes increments in width and height are always\n> > > > > > positive.\n> > > > > >\n> > > > > > > >\n> > > > > > > > > corner, and currently libcamera::Size only allows non-negative width and\n> > > > > > > > > height [1].\n> > > > > > > >\n> > > > > > > > True, Size uses unsigned int. I don't think it's a big deal and I'm\n> > > > > > > > not proposing to introduce a new constructor with signed width and\n> > > > > > > > height now, but my point is that if the need arises we can now do\n> > > > > > > > that.\n> > > > > > > >\n> > > > > > > > >\n> > > > > > > > > [1]:\n> > > > > > > > > https://git.libcamera.org/libcamera/libcamera.git/tree/include/libcamera/geometry.h#n65\n> > > > > > > > >\n> > > > > > > > >\n> > > > > > > > > > >\n> > > > > > > > > > >\n> > > > > > > > > > > >\n> > > > > > > > > > > > > BR,\n> > > > > > > > > > > > > Harvey\n> > > > > > > > > > > > >\n> > > > > > > > > > > > >\n> > > > > > > > > > > > > > >    */\n> > > > > > > > > > > > > > >\n> > > > > > > > > > > > > > >   /**\n> > > > > > > > > > > > > > >    * \\fn Rectangle::Rectangle(int x, int y, unsigned int width,\n> > > > > > > > > > > > unsigned int height)\n> > > > > > > > > > > > > > >    * \\brief Construct a Rectangle with the given position and\n> > > > > > > > > > size\n> > > > > > > > > > > > > > > - * \\param[in] x The horizontal coordinate of the top-left corner\n> > > > > > > > > > > > > > > - * \\param[in] y The vertical coordinate of the top-left corner\n> > > > > > > > > > > > > > > + * \\param[in] x The horizontal coordinate of the origin corner\n> > > > > > > > > > > > > > > + * \\param[in] y The vertical coordinate of the origin corner\n> > > > > > > > > > > > > > >    * \\param[in] width The width\n> > > > > > > > > > > > > > >    * \\param[in] height The height\n> > > > > > > > > > > > > > > + *\n> > > > > > > > > > > > > > > + * The rectangle's origin corner is the corner closer to the\n> > > > > > > > > > > > reference system\n> > > > > > > > > > > > > > > + * origin point (0, 0).\n> > > > > > > > > > > > > > >    */\n> > > > > > > > > > > > > > >\n> > > > > > > > > > > > > > >   /**\n> > > > > > > > > > > > > > >    * \\fn Rectangle::Rectangle(const Size &size)\n> > > > > > > > > > > > > > > - * \\brief Construct a Rectangle of \\a size with its top left\n> > > > > > > > > > corner\n> > > > > > > > > > > > located\n> > > > > > > > > > > > > > > + * \\brief Construct a Rectangle of \\a size with its origin\n> > > > > > > > > > corner\n> > > > > > > > > > > > located\n> > > > > > > > > > > > > > >    * at (0,0)\n> > > > > > > > > > > > > > >    * \\param[in] size The desired Rectangle size\n> > > > > > > > > > > > > > > + *\n> > > > > > > > > > > > > > > + * The rectangle's origin corner is the corner closer to the\n> > > > > > > > > > > > reference system\n> > > > > > > > > > > > > > > + * origin point (0, 0).\n> > > > > > > > > > > > > > >    */\n> > > > > > > > > > > > > > >\n> > > > > > > > > > > > > > >   /**\n> > > > > > > > > > > > > > >    * \\var Rectangle::x\n> > > > > > > > > > > > > > > - * \\brief The horizontal coordinate of the rectangle's top-left\n> > > > > > > > > > > > corner\n> > > > > > > > > > > > > > > + * \\brief The horizontal coordinate of the rectangle's origin\n> > > > > > > > > > corner\n> > > > > > > > > > > > > > > + *\n> > > > > > > > > > > > > > > + * The rectangle's origin corner is the corner closer to the\n> > > > > > > > > > > > reference system\n> > > > > > > > > > > > > > > + * origin point (0, 0).\n> > > > > > > > > > > > > > >    */\n> > > > > > > > > > > > > > >\n> > > > > > > > > > > > > > >   /**\n> > > > > > > > > > > > > > >    * \\var Rectangle::y\n> > > > > > > > > > > > > > > - * \\brief The vertical coordinate of the rectangle's top-left\n> > > > > > > > > > corner\n> > > > > > > > > > > > > > > + * \\brief The vertical coordinate of the rectangle's origin\n> > > > > > > > > > corner\n> > > > > > > > > > > > > > > + *\n> > > > > > > > > > > > > > > + * The rectangle's origin corner is the corner closer to the\n> > > > > > > > > > > > reference system\n> > > > > > > > > > > > > > > + * origin point (0, 0).\n> > > > > > > > > > > > > > >    */\n> > > > > > > > > > > > > > >\n> > > > > > > > > > > > > > >   /**\n> > > > > > > > > > > > > > > @@ -683,9 +726,13 @@ Point Rectangle::center() const\n> > > > > > > > > > > > > > >    */\n> > > > > > > > > > > > > > >\n> > > > > > > > > > > > > > >   /**\n> > > > > > > > > > > > > > > - * \\fn Point Rectangle::topLeft() const\n> > > > > > > > > > > > > > > - * \\brief Retrieve the coordinates of the top left corner of\n> > > > > > > > > > this\n> > > > > > > > > > > > Rectangle\n> > > > > > > > > > > > > > > - * \\return The Rectangle's top left corner\n> > > > > > > > > > > > > > > + * \\fn Point Rectangle::origin() const\n> > > > > > > > > > > > > > > + * \\brief Retrieve the coordinates of the origin corner of this\n> > > > > > > > > > > > Rectangle\n> > > > > > > > > > > > > > > + *\n> > > > > > > > > > > > > > > + * The rectangle's origin corner is the corner closer to the\n> > > > > > > > > > > > reference system\n> > > > > > > > > > > > > > > + * origin point (0, 0).\n> > > > > > > > > > > > > > > + *\n> > > > > > > > > > > > > > > + * \\return The Rectangle's origin corner\n> > > > > > > > > > > > > >\n> > > > > > > > > > > > > > I think you can drop \"corner\" from \"origin corner\"\n> > > > > > > > > > > > > >\n> > > > > > > > > > > > > > Probably throughout the patch:\n> > > > > > > > > > > > > >      s/origin corner/origin/\n> > > > > > > > > > > > > >\n> > > > > > > > > > > > > > Otherwise, LGTM\n> > > > > > > > > > > > > >\n> > > > > > > > > > > > > > Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>\n> > > > > > > > > > > > > > >    */\n> > > > > > > > > > > > > > >\n> > > > > > > > > > > > > > >   /**\n> > > > > > > > > > > > > > > @@ -740,15 +787,15 @@ Rectangle &Rectangle::translateBy(const\n> > > > > > > > > > Point\n> > > > > > > > > > > > &point)\n> > > > > > > > > > > > > > >    */\n> > > > > > > > > > > > > > >   Rectangle Rectangle::boundedTo(const Rectangle &bound) const\n> > > > > > > > > > > > > > >   {\n> > > > > > > > > > > > > > > -     int topLeftX = std::max(x, bound.x);\n> > > > > > > > > > > > > > > -     int topLeftY = std::max(y, bound.y);\n> > > > > > > > > > > > > > > +     int originX = std::max(x, bound.x);\n> > > > > > > > > > > > > > > +     int originY = std::max(y, bound.y);\n> > > > > > > > > > > > > > >       int bottomRightX = std::min<int>(x + width, bound.x +\n> > > > > > > > > > > > bound.width);\n> > > > > > > > > > > > > > >       int bottomRightY = std::min<int>(y + height, bound.y +\n> > > > > > > > > > > > bound.height);\n> > > > > > > > > > > > > > >\n> > > > > > > > > > > > > > > -     unsigned int newWidth = std::max(bottomRightX - topLeftX,\n> > > > > > > > > > 0);\n> > > > > > > > > > > > > > > -     unsigned int newHeight = std::max(bottomRightY - topLeftY,\n> > > > > > > > > > 0);\n> > > > > > > > > > > > > > > +     unsigned int newWidth = std::max(bottomRightX - originX,\n> > > > > > > > > > 0);\n> > > > > > > > > > > > > > > +     unsigned int newHeight = std::max(bottomRightY - originY,\n> > > > > > > > > > 0);\n> > > > > > > > > > > > > > >\n> > > > > > > > > > > > > > > -     return { topLeftX, topLeftY, newWidth, newHeight };\n> > > > > > > > > > > > > > > +     return { originX, originY, newWidth, newHeight };\n> > > > > > > > > > > > > > >   }\n> > > > > > > > > > > > > > >\n> > > > > > > > > > > > > > >   /**\n> > > > > > > > > > > > > > > diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n> > > > > > > > > > > > b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n> > > > > > > > > > > > > > > index 3041fd1ed9fd..8d2440026689 100644\n> > > > > > > > > > > > > > > --- a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n> > > > > > > > > > > > > > > +++ b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n> > > > > > > > > > > > > > > @@ -1289,7 +1289,7 @@ Rectangle CameraData::scaleIspCrop(const\n> > > > > > > > > > > > Rectangle &ispCrop) const\n> > > > > > > > > > > > > > >        */\n> > > > > > > > > > > > > > >       Rectangle nativeCrop =\n> > > > > > > > > > > > ispCrop.scaledBy(sensorInfo_.analogCrop.size(),\n> > > > > > > > > > > > > > >\n> > > > > > > > > > > >  sensorInfo_.outputSize);\n> > > > > > > > > > > > > > > -     nativeCrop.translateBy(sensorInfo_.analogCrop.topLeft());\n> > > > > > > > > > > > > > > +     nativeCrop.translateBy(sensorInfo_.analogCrop.origin());\n> > > > > > > > > > > > > > >       return nativeCrop;\n> > > > > > > > > > > > > > >   }\n> > > > > > > > > > > > > > >\n> > > > > > > > > > > > > > > @@ -1303,7 +1303,7 @@ void CameraData::applyScalerCrop(const\n> > > > > > > > > > > > ControlList &controls)\n> > > > > > > > > > > > > > >                       nativeCrop = { 0, 0, 1, 1 };\n> > > > > > > > > > > > > > >\n> > > > > > > > > > > > > > >               /* Create a version of the crop scaled to ISP\n> > > > > > > > > > (camera\n> > > > > > > > > > > > mode) pixels. */\n> > > > > > > > > > > > > > > -             Rectangle ispCrop =\n> > > > > > > > > > > > nativeCrop.translatedBy(-sensorInfo_.analogCrop.topLeft());\n> > > > > > > > > > > > > > > +             Rectangle ispCrop =\n> > > > > > > > > > > > nativeCrop.translatedBy(-sensorInfo_.analogCrop.origin());\n> > > > > > > > > > > > > > >               ispCrop.scaleBy(sensorInfo_.outputSize,\n> > > > > > > > > > > > sensorInfo_.analogCrop.size());\n> > > > > > > > > > > > > > >\n> > > > > > > > > > > > > > >               /*\n> > > > > > > > > > > > > > > diff --git a/src/py/libcamera/py_geometry.cpp\n> > > > > > > > > > > > b/src/py/libcamera/py_geometry.cpp\n> > > > > > > > > > > > > > > index c7e303609427..8dee365b25dd 100644\n> > > > > > > > > > > > > > > --- a/src/py/libcamera/py_geometry.cpp\n> > > > > > > > > > > > > > > +++ b/src/py/libcamera/py_geometry.cpp\n> > > > > > > > > > > > > > > @@ -105,7 +105,7 @@ void init_py_geometry(py::module &m)\n> > > > > > > > > > > > > > >               .def_property_readonly(\"is_null\",\n> > > > > > > > > > &Rectangle::isNull)\n> > > > > > > > > > > > > > >               .def_property_readonly(\"center\",\n> > > > > > > > > > &Rectangle::center)\n> > > > > > > > > > > > > > >               .def_property_readonly(\"size\", &Rectangle::size)\n> > > > > > > > > > > > > > > -             .def_property_readonly(\"topLeft\",\n> > > > > > > > > > &Rectangle::topLeft)\n> > > > > > > > > > > > > > > +             .def_property_readonly(\"origin\",\n> > > > > > > > > > &Rectangle::origin)\n> > > > > > > > > > > > > > >               .def(\"scale_by\", &Rectangle::scaleBy)\n> > > > > > > > > > > > > > >               .def(\"translate_by\", &Rectangle::translateBy)\n> > > > > > > > > > > > > > >               .def(\"bounded_to\", &Rectangle::boundedTo)\n> > > > > > > > > > > > > > > diff --git a/test/geometry.cpp b/test/geometry.cpp\n> > > > > > > > > > > > > > > index 64169206ad16..a4ee6f6e167a 100644\n> > > > > > > > > > > > > > > --- a/test/geometry.cpp\n> > > > > > > > > > > > > > > +++ b/test/geometry.cpp\n> > > > > > > > > > > > > > > @@ -363,16 +363,16 @@ protected:\n> > > > > > > > > > > > > > >                       return TestFail;\n> > > > > > > > > > > > > > >               }\n> > > > > > > > > > > > > > >\n> > > > > > > > > > > > > > > -             /* Rectangle::size(), Rectangle::topLeft() and\n> > > > > > > > > > > > Rectangle::center() tests */\n> > > > > > > > > > > > > > > +             /* Rectangle::size(), Rectangle::origin() and\n> > > > > > > > > > > > Rectangle::center() tests */\n> > > > > > > > > > > > > > >               if (Rectangle(-1, -2, 3, 4).size() != Size(3, 4) ||\n> > > > > > > > > > > > > > >                   Rectangle(0, 0, 100000, 200000).size() !=\n> > > > > > > > > > > > Size(100000, 200000)) {\n> > > > > > > > > > > > > > >                       cout << \"Rectangle::size() test failed\" <<\n> > > > > > > > > > > > endl;\n> > > > > > > > > > > > > > >                       return TestFail;\n> > > > > > > > > > > > > > >               }\n> > > > > > > > > > > > > > >\n> > > > > > > > > > > > > > > -             if (Rectangle(1, 2, 3, 4).topLeft() != Point(1, 2)\n> > > > > > > > > > ||\n> > > > > > > > > > > > > > > -                 Rectangle(-1, -2, 3, 4).topLeft() != Point(-1,\n> > > > > > > > > > > > -2)) {\n> > > > > > > > > > > > > > > -                     cout << \"Rectangle::topLeft() test failed\"\n> > > > > > > > > > <<\n> > > > > > > > > > > > endl;\n> > > > > > > > > > > > > > > +             if (Rectangle(1, 2, 3, 4).origin() != Point(1, 2)\n> > > > > > > > > > ||\n> > > > > > > > > > > > > > > +                 Rectangle(-1, -2, 3, 4).origin() != Point(-1,\n> > > > > > > > > > -2))\n> > > > > > > > > > > > {\n> > > > > > > > > > > > > > > +                     cout << \"Rectangle::origin() test failed\"\n> > > > > > > > > > <<\n> > > > > > > > > > > > endl;\n> > > > > > > > > > > > > > >                       return TestFail;\n> > > > > > > > > > > > > > >               }\n> > > > > > > > > > > > > > >\n> > > > > > > > > > > > > > > --\n> > > > > > > > > > > > > > > 2.46.1\n> > > > > > > > > > > > > > >\n> > > > > > > > > > > > > >\n> > > > > > > > > > > > >\n> > > > > > > > > > > > >\n> > > > > > > > > > > > > --\n> > > > > > > > > > > > > BR,\n> > > > > > > > > > > > > Harvey Yang\n> > > > > > > > > > > >\n> > > > > > > > > >\n> > > > > > >\n> > > > > > >\n> > > > > > >\n> > > > > > > --\n> > > > > > > BR,\n> > > > > > > Harvey Yang\n> > > > >\n> > > > >\n> > > > >\n> > > > > --\n> > > > > BR,\n> > > > > Harvey Yang\n> > >\n> > >\n> > >\n> > > --\n> > > BR,\n> > > Harvey Yang\n\n\n\n--\nBR,\nHarvey Yang","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 3B6CAC3257\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 27 Sep 2024 16:16:25 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 368546350F;\n\tFri, 27 Sep 2024 18:16:24 +0200 (CEST)","from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com\n\t[IPv6:2a00:1450:4864:20::32a])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 4E3A7634F2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 27 Sep 2024 18:16:22 +0200 (CEST)","by mail-wm1-x32a.google.com with SMTP id\n\t5b1f17b1804b1-42cae4ead5bso241475e9.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 27 Sep 2024 09:16:22 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key;\n\tunprotected) header.d=google.com header.i=@google.com\n\theader.b=\"rQuUV1Zz\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=google.com; s=20230601; t=1727453782; x=1728058582;\n\tdarn=lists.libcamera.org; \n\th=content-transfer-encoding:cc:to:subject:message-id:date:from\n\t:in-reply-to:references:mime-version:from:to:cc:subject:date\n\t:message-id:reply-to;\n\tbh=+8CNo83UHJEaLbsuwTRvLrapkp9Q5azX2kGWKNlO4gQ=;\n\tb=rQuUV1ZzyzoC5fDKuawkhyK/VtrjAd6hRpd/dpFrz7BJlivTIwnxpB+Ths38X59nAG\n\tTbz9oW0Kqxs4s26J9ARVqU7UB72p2u0+I9MIpDVDq88Hv7876/nvYMSkcj6Z7LBYfZ8D\n\tRq0y8wWbMjfXuzSMaFp99AqPkqRQUReXSUUR4UdBQWIP0/h6p2R16PtAWharBSBCTa0v\n\tOiURIDw/o9cupBqzHFj+7iV9wwYAU3Vz/E7EhX1Rb8i58/R/+ehjz6VnRQZ3qfqMaFA4\n\tztVWtF9ZncclpfwGbf8248h1IKr+OE1KZu+6xWrMJu2bY0G00Q9jhm3SaxHud8BS9yHg\n\tYmxg==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1727453782; x=1728058582;\n\th=content-transfer-encoding:cc:to:subject:message-id:date:from\n\t:in-reply-to:references:mime-version:x-gm-message-state:from:to:cc\n\t:subject:date:message-id:reply-to;\n\tbh=+8CNo83UHJEaLbsuwTRvLrapkp9Q5azX2kGWKNlO4gQ=;\n\tb=l7qxnWJCWPbZlt5K436d+QqMSWw9OWst5UtO9qeTIwVSZd7FIGaND9XvC3y2vdh7KC\n\tqVA+rwqnU7fdwGKnGyq1BAhozZED73c6Xz+JG5uowNMmKydhXU6psRVRNJFH0ghML8cg\n\tzloU83lOS2KV3xOG4is7kDU8phvvVb/xjwCXz2xNEe5GTxT0q+sIzLB+yM4ToaqmBbQq\n\tzegVPjTLEGgC4kgX4plKOzxKleSyy9HsCz2ZmDyzQV6HvCBi0FpOhNHhlKEXDaWhhZMm\n\t0APS00qTen326WinFFaQXeTbhiYLU8C7L484JQGE2NJsVD1bM2e0FAxP/ivms1iTlVgk\n\tHZCg==","X-Forwarded-Encrypted":"i=1;\n\tAJvYcCW3ZSWRtZ9Zm6CB+aIPSppNP5JKcghLm8i8Hb54bIkfxLyUNjHAiG+DxtNxRPJ5Wb5LAce85Dg5E4PN5hfcrlY=@lists.libcamera.org","X-Gm-Message-State":"AOJu0YyRX7nRUYJVAGNMne3IX5Vk/qr01rYK8/eNpqPLpwHjVbyPUMEC\n\tzickR7FCiXPwf43U8A0hLq2SNIJZg7E+O92tGB9Z552o1fMfYNJ6UJU/H5y33WnwTeotND2h2CJ\n\t3LaaEGJrBQ0oMLG3NEtQJdGC4pRBDYfS62UaviVTvIwYWEys86g==","X-Google-Smtp-Source":"AGHT+IHYGA+qMThNriMAblMwH6lv4feETbyblFZ43n0Ot71B/fso9kh/xeSh+0zM3xVeIuYioe6rk/WUcpLM137CaCU=","X-Received":"by 2002:a05:600c:3d0a:b0:42c:acba:2011 with SMTP id\n\t5b1f17b1804b1-42f5a657cfbmr4000725e9.1.1727453781162; Fri, 27 Sep 2024\n\t09:16:21 -0700 (PDT)","MIME-Version":"1.0","References":"<CAC=wSGWEZU7_=nEFTp+g_g74L7kcs65wK3oOeS8xwBqzMHa5wQ@mail.gmail.com>\n\t<zsszrdewqlrlovncquphk43ajxyksfoijoiorglvwem4kb2u6q@my2gscqpdzd3>\n\t<CAC=wSGXj==p2GZMidtwb9pUhmnuRrdqbGhQUF14HSNfTzgz_Cw@mail.gmail.com>\n\t<62yvkiqioilupdcm7ryjtrz273iamzojfi2pgxndmjwoyyaitb@iq46e47ke2vg>\n\t<CAC=wSGXgYv2YyZqwgRANhmVzPtLTkTHP4=R-_Sz+NE7wNzPJXw@mail.gmail.com>\n\t<6cnkhto53ixz7hafosgqebixvfdpwftc24ach46wsvv6qpjmkv@h7e25hene6yc>\n\t<CAC=wSGU3ubNji42mp-4eXH7L34ZZE0vP_NA5Uu1fKgUsQTvG7Q@mail.gmail.com>\n\t<juj2axmwzwss5axiy3y6l4hetonuv72oyzgb6ekf5hbt66it73@j23uammf6fl7>\n\t<CAC=wSGVEjJ-fHo4W31OGU2Qk8=OhhzYNCW4qFxqLLdtTu0kGrw@mail.gmail.com>\n\t<cdtdrnjxni6trvlsmejd24ihlbujtqo4sxq4x7gwktitzua4rz@msm5if6yuae5>\n\t<jhm5lkl4kkjs3e2dydelkdeju3hqwwobxq3l6pg36knebrppdv@lrjdkupwnogu>","In-Reply-To":"<jhm5lkl4kkjs3e2dydelkdeju3hqwwobxq3l6pg36knebrppdv@lrjdkupwnogu>","From":"Cheng-Hao Yang <chenghaoyang@google.com>","Date":"Sat, 28 Sep 2024 00:15:44 +0800","Message-ID":"<CAC=wSGUUe83HiWGE_H=XvA23H=JTCiOvoJNpi0Y2OPaEhO89Hw@mail.gmail.com>","Subject":"Re: [PATCH] libcamera: geometry: Rename Rectangle's top-left corner","To":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>","Cc":"Umang Jain <umang.jain@ideasonboard.com>, \n\tlibcamera devel <libcamera-devel@lists.libcamera.org>","Content-Type":"text/plain; charset=\"UTF-8\"","Content-Transfer-Encoding":"quoted-printable","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>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]