Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4e0cacf

Browse files
sfreilichcopybara-github
authored andcommitted
Use C++20 features for comparison and equality operators
Field-by-field equality can be implemented with `bool operator==(...) const = default`. Similarly, our typed-float classes that wrap a value can be ordered on that value with the default `operator==` plus `auto operator<=>(...) const = default`.PiperOrigin-RevId: 797050343
1 parentd6ccfa5 commit4e0cacf

29 files changed

+83
-362
lines changed

‎ink/brush/brush_behavior.cc‎

Lines changed: 0 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -36,77 +36,6 @@ bool BrushBehavior::EnabledToolTypes::HasAllTypes() const {
3636
return unknown && mouse && touch && stylus;
3737
}
3838

39-
booloperator==(const BrushBehavior::EnabledToolTypes& lhs,
40-
const BrushBehavior::EnabledToolTypes& rhs) {
41-
return lhs.unknown == rhs.unknown && lhs.mouse == rhs.mouse &&
42-
lhs.touch == rhs.touch && lhs.stylus == rhs.stylus;
43-
}
44-
45-
booloperator==(const BrushBehavior::SourceNode& lhs,
46-
const BrushBehavior::SourceNode& rhs) {
47-
return lhs.source == rhs.source &&
48-
lhs.source_out_of_range_behavior == rhs.source_out_of_range_behavior &&
49-
lhs.source_value_range == rhs.source_value_range;
50-
}
51-
52-
booloperator==(const BrushBehavior::ConstantNode& lhs,
53-
const BrushBehavior::ConstantNode& rhs) {
54-
return lhs.value == rhs.value;
55-
}
56-
57-
booloperator==(const BrushBehavior::NoiseNode& lhs,
58-
const BrushBehavior::NoiseNode& rhs) {
59-
return lhs.seed == rhs.seed && lhs.vary_over == rhs.vary_over &&
60-
lhs.base_period == rhs.base_period;
61-
}
62-
63-
booloperator==(const BrushBehavior::FallbackFilterNode& lhs,
64-
const BrushBehavior::FallbackFilterNode& rhs) {
65-
return lhs.is_fallback_for == rhs.is_fallback_for;
66-
}
67-
68-
booloperator==(const BrushBehavior::ToolTypeFilterNode& lhs,
69-
const BrushBehavior::ToolTypeFilterNode& rhs) {
70-
return lhs.enabled_tool_types == rhs.enabled_tool_types;
71-
}
72-
73-
booloperator==(const BrushBehavior::DampingNode& lhs,
74-
const BrushBehavior::DampingNode& rhs) {
75-
return lhs.damping_source == rhs.damping_source &&
76-
lhs.damping_gap == rhs.damping_gap;
77-
}
78-
79-
booloperator==(const BrushBehavior::ResponseNode& lhs,
80-
const BrushBehavior::ResponseNode& rhs) {
81-
return lhs.response_curve == rhs.response_curve;
82-
}
83-
84-
booloperator==(const BrushBehavior::BinaryOpNode& lhs,
85-
const BrushBehavior::BinaryOpNode& rhs) {
86-
return lhs.operation == rhs.operation;
87-
}
88-
89-
booloperator==(const BrushBehavior::InterpolationNode& lhs,
90-
const BrushBehavior::InterpolationNode& rhs) {
91-
return lhs.interpolation == rhs.interpolation;
92-
}
93-
94-
booloperator==(const BrushBehavior::TargetNode& lhs,
95-
const BrushBehavior::TargetNode& rhs) {
96-
return lhs.target == rhs.target &&
97-
lhs.target_modifier_range == rhs.target_modifier_range;
98-
}
99-
100-
booloperator==(const BrushBehavior::PolarTargetNode& lhs,
101-
const BrushBehavior::PolarTargetNode& rhs) {
102-
return lhs.target == rhs.target && lhs.angle_range == rhs.angle_range &&
103-
lhs.magnitude_range == rhs.magnitude_range;
104-
}
105-
106-
booloperator==(const BrushBehavior& lhs,const BrushBehavior& rhs) {
107-
return lhs.nodes == rhs.nodes;
108-
}
109-
11039
namespacebrush_internal {
11140
namespace {
11241

‎ink/brush/brush_behavior.h‎

Lines changed: 26 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,8 @@ struct BrushBehavior {
374374

375375
boolHasAnyTypes()const;
376376
boolHasAllTypes()const;
377+
378+
booloperator==(const EnabledToolTypes& rhs)const =default;
377379
};
378380

379381
staticconstexpr EnabledToolTypeskAllToolTypes = {
@@ -459,6 +461,8 @@ struct BrushBehavior {
459461
Source source;
460462
OutOfRange source_out_of_range_behavior = OutOfRange::kClamp;
461463
std::array<float,2> source_value_range;
464+
465+
booloperator==(const SourceNode& rhs)const =default;
462466
};
463467

464468
// Value node for producing a constant value.
@@ -467,6 +471,8 @@ struct BrushBehavior {
467471
// To be valid: `value` must be finite.
468472
structConstantNode {
469473
float value;
474+
475+
booloperator==(const ConstantNode& rhs)const =default;
470476
};
471477

472478
// Value node for producing a continuous random noise function with values
@@ -480,6 +486,8 @@ struct BrushBehavior {
480486
uint32_t seed;
481487
DampingSource vary_over;
482488
float base_period;
489+
490+
booloperator==(const NoiseNode& rhs)const =default;
483491
};
484492

485493
//////////////////////////
@@ -495,6 +503,8 @@ struct BrushBehavior {
495503
// - `is_fallback_for` must be a valid `OptionalInputProperty` enumerator.
496504
structFallbackFilterNode {
497505
OptionalInputProperty is_fallback_for;
506+
507+
booloperator==(const FallbackFilterNode& rhs)const =default;
498508
};
499509

500510
// Value node for filtering out a branch of a behavior graph unless this
@@ -505,6 +515,8 @@ struct BrushBehavior {
505515
// To be valid: At least one tool type must be enabled.
506516
structToolTypeFilterNode {
507517
EnabledToolTypes enabled_tool_types;
518+
519+
booloperator==(const ToolTypeFilterNode& rhs)const =default;
508520
};
509521

510522
////////////////////////////
@@ -524,6 +536,8 @@ struct BrushBehavior {
524536
structDampingNode {
525537
DampingSource damping_source;
526538
float damping_gap;
539+
540+
booloperator==(const DampingNode& rhs)const =default;
527541
};
528542

529543
// Value node for mapping a value through a response curve.
@@ -534,6 +548,8 @@ struct BrushBehavior {
534548
// To be valid: `function` must be a valid `EasingFunction`.
535549
structResponseNode {
536550
EasingFunction response_curve;
551+
552+
booloperator==(const ResponseNode& rhs)const =default;
537553
};
538554

539555
// Value node for combining two other values with a binary operation.
@@ -544,6 +560,8 @@ struct BrushBehavior {
544560
// To be valid: `operation` must be a valid `BinaryOp` enumerator.
545561
structBinaryOpNode {
546562
BinaryOp operation;
563+
564+
booloperator==(const BinaryOpNode& rhs)const =default;
547565
};
548566

549567
// Value node for interpolating to/from a range of two values.
@@ -554,6 +572,8 @@ struct BrushBehavior {
554572
// To be valid: `interpolation` must be a valid `Interpolation` enumerator.
555573
structInterpolationNode {
556574
Interpolation interpolation;
575+
576+
booloperator==(const InterpolationNode& rhs)const =default;
557577
};
558578

559579
//////////////////////
@@ -573,6 +593,8 @@ struct BrushBehavior {
573593
structTargetNode {
574594
Target target;
575595
std::array<float,2> target_modifier_range;
596+
597+
booloperator==(const TargetNode& rhs)const =default;
576598
};
577599

578600
// Terminal node that consumes two input values (angle and magnitude), forming
@@ -591,6 +613,8 @@ struct BrushBehavior {
591613
PolarTarget target;
592614
std::array<float,2> angle_range;
593615
std::array<float,2> magnitude_range;
616+
617+
booloperator==(const PolarTargetNode& rhs)const =default;
594618
};
595619

596620
// A single node in a behavior's graph. Each node type is either a "value
@@ -604,45 +628,9 @@ struct BrushBehavior {
604628
InterpolationNode, TargetNode, PolarTargetNode>;
605629

606630
std::vector<Node> nodes;
607-
};
608631

609-
booloperator==(const BrushBehavior::EnabledToolTypes& lhs,
610-
const BrushBehavior::EnabledToolTypes& rhs);
611-
612-
booloperator==(const BrushBehavior::SourceNode& lhs,
613-
const BrushBehavior::SourceNode& rhs);
614-
615-
booloperator==(const BrushBehavior::ConstantNode& lhs,
616-
const BrushBehavior::ConstantNode& rhs);
617-
618-
booloperator==(const BrushBehavior::NoiseNode& lhs,
619-
const BrushBehavior::NoiseNode& rhs);
620-
621-
booloperator==(const BrushBehavior::FallbackFilterNode& lhs,
622-
const BrushBehavior::FallbackFilterNode& rhs);
623-
624-
booloperator==(const BrushBehavior::ToolTypeFilterNode& lhs,
625-
const BrushBehavior::ToolTypeFilterNode& rhs);
626-
627-
booloperator==(const BrushBehavior::DampingNode& lhs,
628-
const BrushBehavior::DampingNode& rhs);
629-
630-
booloperator==(const BrushBehavior::ResponseNode& lhs,
631-
const BrushBehavior::ResponseNode& rhs);
632-
633-
booloperator==(const BrushBehavior::BinaryOpNode& lhs,
634-
const BrushBehavior::BinaryOpNode& rhs);
635-
636-
booloperator==(const BrushBehavior::InterpolationNode& lhs,
637-
const BrushBehavior::InterpolationNode& rhs);
638-
639-
booloperator==(const BrushBehavior::TargetNode& lhs,
640-
const BrushBehavior::TargetNode& rhs);
641-
642-
booloperator==(const BrushBehavior::PolarTargetNode& lhs,
643-
const BrushBehavior::PolarTargetNode& rhs);
644-
645-
booloperator==(const BrushBehavior& lhs,const BrushBehavior& rhs);
632+
booloperator==(const BrushBehavior& rhs)const =default;
633+
};
646634

647635
namespacebrush_internal {
648636

‎ink/brush/brush_paint.cc‎

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@
2323
#include"absl/strings/str_join.h"
2424
#include"absl/time/time.h"
2525

26-
namespaceink {
27-
namespacebrush_internal {
26+
namespaceink::brush_internal {
2827
namespace {
2928

3029
boolIsValidBrushPaintTextureMapping(BrushPaint::TextureMapping mapping) {
@@ -443,27 +442,4 @@ std::string ToFormattedString(const BrushPaint& paint) {
443442
return formatted;
444443
}
445444

446-
}// namespace brush_internal
447-
448-
booloperator==(const BrushPaint::TextureKeyframe& lhs,
449-
const BrushPaint::TextureKeyframe& rhs) {
450-
return lhs.progress == rhs.progress && lhs.size == rhs.size &&
451-
lhs.offset == rhs.offset && lhs.rotation == rhs.rotation &&
452-
lhs.opacity == rhs.opacity;
453-
}
454-
455-
booloperator==(const BrushPaint::TextureLayer& lhs,
456-
const BrushPaint::TextureLayer& rhs) {
457-
return lhs.client_texture_id == rhs.client_texture_id &&
458-
lhs.mapping == rhs.mapping && lhs.origin == rhs.origin &&
459-
lhs.size_unit == rhs.size_unit && lhs.wrap_x == rhs.wrap_x &&
460-
lhs.wrap_y == rhs.wrap_y && lhs.size == rhs.size &&
461-
lhs.offset == rhs.offset && lhs.rotation == rhs.rotation &&
462-
lhs.size_jitter == rhs.size_jitter &&
463-
lhs.offset_jitter == rhs.offset_jitter &&
464-
lhs.rotation_jitter == rhs.rotation_jitter &&
465-
lhs.opacity == rhs.opacity && lhs.keyframes == rhs.keyframes &&
466-
lhs.blend_mode == rhs.blend_mode;
467-
}
468-
469-
}// namespace ink
445+
}// namespace ink::brush_internal

‎ink/brush/brush_paint.h‎

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,8 @@ struct BrushPaint {
226226
// Value of texture layer opacity to apply for this keyframe. This value
227227
// will override `TextureLayer::opacity`.
228228
std::optional<float> opacity;
229+
230+
booloperator==(const TextureKeyframe& rhs)const =default;
229231
};
230232

231233
structTextureLayer {
@@ -296,18 +298,14 @@ struct BrushPaint {
296298
// "dst", which is the layer at index + 1. If index refers to the last
297299
// texture layer, then the layer at "index + 1" is the brush color layer.
298300
BlendMode blend_mode = BlendMode::kModulate;
301+
302+
booloperator==(const TextureLayer& rhs)const =default;
299303
};
300304

301305
std::vector<TextureLayer> texture_layers;
302-
};
303-
304-
booloperator==(const BrushPaint::TextureKeyframe& lhs,
305-
const BrushPaint::TextureKeyframe& rhs);
306306

307-
booloperator==(const BrushPaint::TextureLayer& lhs,
308-
const BrushPaint::TextureLayer& rhs);
309-
310-
booloperator==(const BrushPaint& lhs,const BrushPaint& rhs);
307+
booloperator==(const BrushPaint& rhs)const =default;
308+
};
311309

312310
namespacebrush_internal {
313311

@@ -393,10 +391,6 @@ H AbslHashValue(H h, const BrushPaint& paint) {
393391
returnH::combine(std::move(h), paint.texture_layers);
394392
}
395393

396-
inlinebooloperator==(const BrushPaint& lhs,const BrushPaint& rhs) {
397-
return lhs.texture_layers == rhs.texture_layers;
398-
}
399-
400394
}// namespace ink
401395

402396
#endif// INK_STROKES_BRUSH_BRUSH_PAINT_H_

‎ink/brush/brush_tip.cc‎

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,7 @@
2727
#include"ink/geometry/vec.h"
2828
#include"ink/types/duration.h"
2929

30-
namespaceink {
31-
32-
bool BrushTip::operator==(const BrushTip& other)const {
33-
return scale == other.scale && corner_rounding == other.corner_rounding &&
34-
slant == other.slant && pinch == other.pinch &&
35-
rotation == other.rotation &&
36-
opacity_multiplier == other.opacity_multiplier &&
37-
particle_gap_distance_scale == other.particle_gap_distance_scale &&
38-
particle_gap_duration == other.particle_gap_duration &&
39-
behaviors == other.behaviors;
40-
}
41-
42-
namespacebrush_internal {
30+
namespaceink::brush_internal {
4331

4432
absl::StatusValidateBrushTipTopLevel(const BrushTip& tip) {
4533
if (!std::isfinite(tip.scale.x) || !std::isfinite(tip.scale.y) ||
@@ -139,5 +127,4 @@ std::string ToFormattedString(const BrushTip& tip) {
139127
return formatted;
140128
}
141129

142-
}// namespace brush_internal
143-
}// namespace ink
130+
}// namespace ink::brush_internal

‎ink/brush/brush_tip.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ struct BrushTip {
109109

110110
std::vector<BrushBehavior> behaviors;
111111

112-
booloperator==(const BrushTip& other)const;
112+
booloperator==(const BrushTip& other)const =default;
113113
};
114114

115115
namespacebrush_internal {

‎ink/brush/easing_function.cc‎

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,7 @@
2525
#include"absl/strings/str_join.h"
2626
#include"ink/geometry/point.h"
2727

28-
namespaceink {
29-
30-
bool EasingFunction::operator==(const EasingFunction& other)const {
31-
return parameters == other.parameters;
32-
}
33-
34-
bool EasingFunction::CubicBezier::operator==(const CubicBezier& other)const {
35-
return x1 == other.x1 && y1 == other.y1 && x2 == other.x2 && y2 == other.y2;
36-
}
37-
38-
bool EasingFunction::Linear::operator==(const Linear& other)const {
39-
return points == other.points;
40-
}
41-
42-
bool EasingFunction::Steps::operator==(const Steps& other)const {
43-
return step_count == other.step_count && step_position == other.step_position;
44-
}
45-
46-
namespacebrush_internal {
28+
namespaceink::brush_internal {
4729
namespace {
4830

4931
boolIsValidPredefinedEasingFunction(EasingFunction::Predefined predefined) {
@@ -218,5 +200,4 @@ std::string ToFormattedString(const EasingFunction::Parameters& parameters) {
218200
parameters);
219201
}
220202

221-
}// namespace brush_internal
222-
}// namespace ink
203+
}// namespace ink::brush_internal

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp