Fix: 2D tri/quad vs point intersection tests edge cases #117786

Merged
Aras Pranckevicius merged 1 commits from aras_p/blender:math_isect_point_fix into main 2024-02-03 19:03:29 +01:00

isect_point_tri_v2 and isect_point_quad_v2 are handling tris/quads
in either clockwise or counter-clockwise vertex orderings. However,
for counter-clockwise order it was considering points that lie on the edges
or vertices as "inside", whereas for counter-clockwise it was treating
them as "outside", unless they were on the first edge.

Visibly affected place is VSE: it has an optimization that checks
whether a fully opaque strip image fully covers the rendered area.
When the strip was scaled up to exactly cover the rendered area,
the check was failing since isect_point_quad_v2 was saying that a
point is outside the rect.

As far as I can tell, the functions have been "slightly wrong" in
this way for at least 15 years; harder to see through earlier
history in git.

Added a bunch of unit tests to cover this. Without the fix, "edge"
and "corner" cases against "cw" tri/quad were failing.

Performance (checked on clang15 on M1 Max):

  • isect_point_tri_v2 is pretty much the same performance (assembly
    several instructions shorter),
  • isect_point_quad_v2 is about three times faster (assembly 2x
    shorter), seemingly the compiler is able to use some SIMD now.
`isect_point_tri_v2` and `isect_point_quad_v2` are handling tris/quads in either clockwise or counter-clockwise vertex orderings. However, for counter-clockwise order it was considering points that lie on the edges or vertices as "inside", whereas for counter-clockwise it was treating them as "outside", unless they were on the first edge. Visibly affected place is VSE: it has an optimization that checks whether a fully opaque strip image fully covers the rendered area. When the strip was scaled up to *exactly* cover the rendered area, the check was failing since `isect_point_quad_v2` was saying that a point is outside the rect. As far as I can tell, the functions have been "slightly wrong" in this way for at least 15 years; harder to see through earlier history in git. Added a bunch of unit tests to cover this. Without the fix, "edge" and "corner" cases against "cw" tri/quad were failing. Performance (checked on clang15 on M1 Max): - `isect_point_tri_v2` is pretty much the same performance (assembly several instructions shorter), - `isect_point_quad_v2` is about three times *faster* (assembly 2x shorter), seemingly the compiler is able to use some SIMD now.
Aras Pranckevicius added 1 commit 2024-02-03 17:49:53 +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-darwin-arm64 Build done. Details
buildbot/vexp-code-patch-coordinator Build done. Details
93886337e8
Fix: 2D tri/quad vs point intersection tests edge cases
isect_point_tri_v2 and isect_point_quad_v2 are handling tris/quads
in either clockwise or counter-clockwise vertex orderings. However,
for clockwise order it was considering points that lie on the edges
or vertices as "inside", whereas for counter-clockwise it was treating
them as "outside".

Visibly affected place is VSE: it has an optimization that checks
whether a fully opaque strip image fully covers the rendered area.
When the strip was scaled up to *exactly* cover the rendered area,
the check was failing since isect_point_quad_v2 was saying that a
point is outside the rect.

As far as I can tell, the functions have been "slightly wrong" in
this way for at least 15 years; harder to see through earlier
history in git.

Added a bunch of unit tests to cover this. Without the fix, "edge"
and "corner" cases against "cw" tri/quad were failing.

Performance (checked on clang15 on M1 Max):
- isect_point_tri_v2 is pretty much the same performance (assembly
  several instructions shorter),
- isect_point_quad_v2 is about three times *faster* (assembly 2x
  shorter), seemingly the compiler is able to use some SIMD now.
Author
Member

@blender-bot build

@blender-bot build
Aras Pranckevicius merged commit f6276ec163 into main 2024-02-03 19:03:29 +01:00
Aras Pranckevicius deleted branch math_isect_point_fix 2024-02-03 19:03:31 +01:00
Sign in to join this conversation.
No reviewers
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset System
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
Asset Browser Project
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
1 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#117786
No description provided.