BLI: Bounds: Add basic functions #118964

Merged
Falk David merged 11 commits from filedescriptor/blender:basic-bounds-functions into main 2024-03-05 14:32:59 +01:00
Member

The overall goal is to be able to eventually replace the BLI_rect.h C-style API.
This only adds come basic functions and tests.

The overall goal is to be able to eventually replace the `BLI_rect.h` C-style API. This only adds come basic functions and tests.
Falk David added 1 commit 2024-03-01 14:25:20 +01:00
buildbot/vexp-code-patch-lint Build done. Details
buildbot/vexp-code-patch-linux-x86_64 Build done. Details
buildbot/vexp-code-patch-darwin-arm64 Build done. Details
buildbot/vexp-code-patch-darwin-x86_64 Build done. Details
buildbot/vexp-code-patch-windows-amd64 Build done. Details
buildbot/vexp-code-patch-coordinator Build done. Details
2b9145dc40
BLI: Bounds: Add basic functions
The overall goal is to be able to eventually replace the `BLI_rect.h` C-style API.
This only adds come basic functions and tests.
Iliya Katushenock added this to the Core Libraries project 2024-03-01 14:27:01 +01:00
Author
Member

@blender-bot build

@blender-bot build
Falk David added 1 commit 2024-03-01 14:28:43 +01:00
buildbot/vexp-code-patch-lint Build done. Details
buildbot/vexp-code-patch-linux-x86_64 Build done. Details
buildbot/vexp-code-patch-darwin-x86_64 Build done. Details
buildbot/vexp-code-patch-windows-amd64 Build done. Details
buildbot/vexp-code-patch-coordinator Build done. Details
c310c24ba4
Formatting
Author
Member

@blender-bot build

@blender-bot build
Iliya Katushenock reviewed 2024-03-01 14:32:08 +01:00
@ -19,0 +24,4 @@
void translate(const T &offset);
void scale_from_center(const T &scale);
void resize(const T &new_size);

Might it can be named constructor? Something like:

const Bounds<float3> object_bound = ...
const Bounds<float3> part_of = object_bound.padding(-4);
Might it can be named constructor? Something like: ```Cpp const Bounds<float3> object_bound = ... const Bounds<float3> part_of = object_bound.padding(-4); ```
Author
Member

Right now I'm trying to just follow what BLI_rect.h is doing, so we can replace it. Adding new functions later would be no problem.

Right now I'm trying to just follow what `BLI_rect.h` is doing, so we can replace it. Adding new functions later would be no problem.
filedescriptor marked this conversation as resolved
Hans Goudey reviewed 2024-03-01 14:36:39 +01:00
Hans Goudey left a comment
Member

Seems like a fine place to start! I don't have strong a strong opinion about free functions vs. class methods here, so going this route seems fine. Might be nice to get the opinion of someone else who worked on our C++ math API too.

Seems like a fine place to start! I don't have strong a strong opinion about free functions vs. class methods here, so going this route seems fine. Might be nice to get the opinion of someone else who worked on our C++ math API too.
@ -119,0 +120,4 @@
} // namespace bounds
template<typename T, int Size>
[[nodiscard]] inline bool less_or_equal_than(const VecBase<T, Size> &a, const VecBase<T, Size> &b)
Member

This can go in a detail namespace. Or is it already implemented for VecBase in BLI_math_vector.hh? That seems like a better place for it

This can go in a detail namespace. Or is it already implemented for `VecBase` in `BLI_math_vector.hh`? That seems like a better place for it
Author
Member

It's not implemented there. I have a feeling that was a deliberate choice, so I put this here for now. We can only use == and != on vector types.

It's not implemented there. I have a feeling that was a deliberate choice, so I put this here for now. We can only use `==` and `!=` on vector types.
Member

I think it would be ok to use an operator overload for this. If not, then this function should probably at least have some more information about how it determines whether one vector is less than the other.

I think it would be ok to use an operator overload for this. If not, then this function should probably at least have some more information about how it determines whether one vector is less than the other.
filedescriptor marked this conversation as resolved
@ -119,0 +132,4 @@
template<typename T> inline bool Bounds<T>::is_empty() const
{
if (std::is_integral<T>::value || std::is_floating_point<T>::value) {
Member

if constexpr (that requires you to write "else" below)

`if constexpr` (that requires you to write "else" below)
filedescriptor marked this conversation as resolved
@ -119,0 +174,4 @@
this->translate(offset);
}
template<typename T> void Bounds<T>::pad(const T &padding)
Member

I'd add another template argument for the padding type, so we can pad a Bounds<float2> with a float for example

I'd add another template argument for the padding type, so we can pad a `Bounds<float2>` with a `float` for example
Author
Member

I suppose the same should be done for e.g. translate etc. ?

I suppose the same should be done for e.g. `translate` etc. ?

I think there can be just an overload for VecBase type with the same number of axis and for single value. Not sure how float2 should be used in float3 bounds.

I think there can be just an overload for `VecBase` type with the same number of axis and for single value. Not sure how `float2` should be used in `float3` bounds.
Member

Not sure about translate, better to be a bit conservative with that

Not sure about `translate`, better to be a bit conservative with that
filedescriptor marked this conversation as resolved
Falk David added 1 commit 2024-03-01 14:37:52 +01:00
Falk David added 1 commit 2024-03-01 14:41:46 +01:00
Falk David requested review from Hans Goudey 2024-03-01 14:49:46 +01:00
Falk David requested review from Jacques Lucke 2024-03-01 14:49:52 +01:00
Falk David added 2 commits 2024-03-01 15:06:18 +01:00
buildbot/vexp-code-patch-lint Build done. Details
buildbot/vexp-code-patch-linux-x86_64 Build done. Details
buildbot/vexp-code-patch-darwin-arm64 Build done. Details
buildbot/vexp-code-patch-darwin-x86_64 Build done. Details
buildbot/vexp-code-patch-windows-amd64 Build done. Details
buildbot/vexp-code-patch-coordinator Build done. Details
754b21316b
Make `pad` parameter templated
Author
Member

@blender-bot build

@blender-bot build
Jacques Lucke reviewed 2024-03-01 15:11:10 +01:00
@ -119,0 +134,4 @@
} // namespace detail
template<typename T> inline bool Bounds<T>::is_empty() const
Member

It feels a bit like this could be a little bit misleading. The min and max are usually inclusive. So if I have a Bounds<int> with min = max = 5, then it feels like there is something in the bounds and it's not empty.

It feels a bit like this could be a little bit misleading. The `min` and `max` are usually inclusive. So if I have a `Bounds<int>` with `min = max = 5`, then it feels like there is something in the bounds and it's not empty.
Author
Member

Right I had the same thought when looking at BLI_rcti_is_empty/BLI_rctf_is_empty.
I can add a comment saying that it's trying to replicate the same behavior as those functions if that helps.

Right I had the same thought when looking at `BLI_rcti_is_empty`/`BLI_rctf_is_empty`. I can add a comment saying that it's trying to replicate the same behavior as those functions if that helps.

Maybe that is is_empty_volume?

Maybe that is `is_empty_volume`?
Author
Member

Well for one, you can have a Bounds<int> so just two numbers. So it doesn't have to be a volume.
I think Bounds<T>::is_empty() is pretty clear.

Well for one, you can have a `Bounds<int>` so just two numbers. So it doesn't have to be a volume. I think `Bounds<T>::is_empty()` is pretty clear.
Jacques Lucke reviewed 2024-03-01 17:18:44 +01:00
Jacques Lucke left a comment
Member

I'm missing some comments explaining what some of the methods do. Especially the behavior of resize and recenter is not really obvious to me when looking at the name.

I'm missing some comments explaining what some of the methods do. Especially the behavior of `resize` and `recenter` is not really obvious to me when looking at the name.
Falk David added 3 commits 2024-03-01 17:54:31 +01:00
Author
Member

@JacquesLucke Added docstrings to the functions 👍

@JacquesLucke Added docstrings to the functions 👍
Falk David added 1 commit 2024-03-01 17:56:17 +01:00
Falk David added 1 commit 2024-03-04 10:26:51 +01:00
Jacques Lucke approved these changes 2024-03-05 09:29:55 +01:00
Author
Member

@HooglyBoogly Are you ok with me landing this?

@HooglyBoogly Are you ok with me landing this?
Hans Goudey approved these changes 2024-03-05 13:59:47 +01:00
Falk David merged commit a4e5469cc0 into main 2024-03-05 14:32:59 +01:00
Falk David deleted branch basic-bounds-functions 2024-03-05 14:33:01 +01:00
Sign in to join this conversation.
No reviewers
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
4 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#118964
No description provided.