GPv3: Fix floating-point error in the hard eraser tool. #110801
No reviewers
Labels
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
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#110801
Loading…
Reference in New Issue
No description provided.
Delete Branch "amelief/blender:gpv3-eraser-fix-floating-point-issue"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
The hard eraser tool was not working properly when trying to erase closely to existing points, leading either to the insertion of various close points in the stroke, or to deleting a whole stroke segment.
This was due to the differenciation between the computation of the intersections between the eraser and the stroke, and the computation of whether a point lie inside the eraser, which lead to inconsistencies in the interpretation of the result.
This patch solves this issue by :
b8b3982cdd
to0267abd05f
First pass. In general, we use the more explicit types of
int
, e.g.int64_t
. Here it even makes sense to useint8_t
in some cases.@ -71,0 +94,4 @@
int &r_mu1)
{
const int64_t d_s0_center = math::distance_squared(s0, center);
No need for the space between each line here.
@ -71,0 +118,4 @@
}
/* Two intersections. */
const float i_sqrt = sqrtf(i);
sqrtf(float(i))
@ -74,3 +150,2 @@
*/
int intersections_with_segment(const float2 &point,
const float2 &point_after,
int intersections_with_segment(const int2 &point,
Return value should be
int8_t
.@ -98,1 +160,3 @@
std::swap(r_mu0, r_mu1);
/* Compute the integer values of the intersection. */
const int segment_length = math::distance(point, point_after);
I think we should use
int64_t
here. Same formu0
andmu1
.@ -103,0 +186,4 @@
* 0 : in-between the endpoints,
* 1 : after the last endpoint.
*/
const int side_mu0 = (mu0 <= 0) ? (-1) : ((mu0 >= segment_length) ? 1 : 0);
Should be
int8_t
.@ -103,0 +227,4 @@
/* Only one intersection lies within the segment. Only one point should be erased, depending on
* the side of the other intersection. */
const int side_outside_intersection = is_mu0_inside ? side_mu1 : side_mu0;
Should be
int8_t
.@ -117,4 +263,2 @@
* Note that for the two output arrays the last element may contain intersections if the
* corresponding curve is cyclic.
*/
int intersections_with_curves(const bke::CurvesGeometry &src,
Return value should be
int64_t
.@ -143,0 +288,4 @@
/* One-point stroke : just check if the point is inside the eraser. */
const int src_point = src_curve_points.first();
const float2 pos = screen_space_positions[src_point];
r_is_point_inside[src_point] = contains_point(pos);
Since the
contains_point
function is only used here, I would just copy the condition here and remove the inline function.@ -236,0 +369,4 @@
*/
int total_points_cut = 0;
for (const int src_point : src.points_range()) {
total_points_cut += int(is_point_cut[src_point]);
I would prefer
total_points_cut += is_point_cut[src_point] ? 1 : 0;
@ -515,1 +654,4 @@
this->mouse_position_pixels = int2(round_fl_to_int(mouse_position[0]),
round_fl_to_int(mouse_position[1]));
const int eraser_radius_pixels = round_fl_to_int(eraser_radius);
Should be
int64_t
.Found a couple more
int
s that should be explicitly typed :)@ -123,1 +250,3 @@
MutableSpan<float2> r_intersections_factors) const
int64_t intersections_with_curves(const bke::CurvesGeometry &src,
const Span<float2> screen_space_positions,
MutableSpan<int> r_nb_intersections,
MutableSpan<int64_t>
@ -128,1 +260,3 @@
threading::parallel_for(src.curves_range(), 256, [&](const IndexRange src_curves) {
Array<int2> screen_space_positions_pixel(src.points_num());
threading::parallel_for(src.points_range(), 1024, [&](const IndexRange src_points) {
for (const int src_point : src_points) {
const int64_t src_point
@ -142,1 +273,3 @@
mu1);
if (src_curve_points.size() == 1) {
/* One-point stroke : just check if the point is inside the eraser. */
const int src_point = src_curve_points.first();
const int64_t src_point
@ -144,3 +282,1 @@
r_intersections_factors[src_point] = float2(mu0, mu1);
}
});
for (const int src_point : src_curve_points.drop_back(1)) {
const int64_t src_point
@ -148,3 +294,4 @@
if (src_cyclic[src_curve]) {
/* If the curve is cyclic, we need to check for the closing segment. */
const int src_last_point = src_curve_points.last();
const int src_first_point = src_curve_points.first();
const int64_t src_first_point
@ -165,3 +313,3 @@
/* Compute total number of intersections. */
int total_intersections = 0;
int64_t total_intersections = 0;
for (const int src_point : src.points_range()) {
const int64_t src_point
@ -226,2 +336,4 @@
/* Compute intersections between the eraser and the curves in the source domain. */
Array<bool> is_point_inside(src_points_num, false);
Array<bool> is_point_cut(src_points_num, false);
Array<int> nb_intersections(src_points_num, 0);
Array<int64_t> nb_intersections
@ -236,0 +355,4 @@
* These points will be kept in the destination geometry, but change the topology of the curve.
*/
int64_t total_points_cut = 0;
for (const int src_point : src.points_range()) {
const int64_t src_point
@ -257,2 +380,4 @@
* numbers for which the integer is the index of the corresponding segment in the source
* curves, and the float part is the (0,1) factor representing its position in the segment.
*/
Array<std::pair<int, float>> dst_points_parameters(dst_points_num);
Array<std::pair<int64_t, float>> dst_points_parameters
@ -464,2 +589,3 @@
* stroke. */
/* If any segment of the stroke is closer to the eraser than its radius, then remove
* the stroke. */
for (const int src_point : src_curve_points.drop_back(1)) {
const int64_t src_point
Looks good!