Delete the copy constructor from Mat2D We can let it be defined implicitly. Also update some Rust formatting to match what the Rustfmt workflow wants. Diffs= d35df0427 Delete the copy constructor from Mat2D (#5916) Co-authored-by: Chris Dalton <99840794+csmartdalton@users.noreply.github.com> Co-authored-by: Luigi Rosso <luigi.rosso@gmail.com>
diff --git a/.rive_head b/.rive_head index 216f57b..21d0ac5 100644 --- a/.rive_head +++ b/.rive_head
@@ -1 +1 @@ -16cf8082fd9a66014305994c736d98cc12d96c73 +d35df04272e659d8244c776e9c4f558452888501
diff --git a/build/setup_compiler.lua b/build/setup_compiler.lua index 48dc985..a8844e6 100644 --- a/build/setup_compiler.lua +++ b/build/setup_compiler.lua
@@ -68,7 +68,8 @@ '-Wno-four-char-constants', '-Wno-unreachable-code', '-Wno-switch-enum', - '-Wno-missing-field-initializers' + '-Wno-missing-field-initializers', + '-Wno-unsafe-buffer-usage' } end
diff --git a/include/rive/math/aabb.hpp b/include/rive/math/aabb.hpp index 2ffca9a..1749209 100644 --- a/include/rive/math/aabb.hpp +++ b/include/rive/math/aabb.hpp
@@ -27,7 +27,6 @@ float minX, minY, maxX, maxY; AABB() : minX(0), minY(0), maxX(0), maxY(0) {} - AABB(const AABB& o) : minX(o.minX), minY(o.minY), maxX(o.maxX), maxY(o.maxY) {} AABB(const Vec2D& min, const Vec2D& max) : minX(min.x), minY(min.y), maxX(max.x), maxY(max.y) {} static AABB fromLTWH(float x, float y, float width, float height) {
diff --git a/include/rive/math/mat2d.hpp b/include/rive/math/mat2d.hpp index 1ccd06d..08360ed 100644 --- a/include/rive/math/mat2d.hpp +++ b/include/rive/math/mat2d.hpp
@@ -2,6 +2,7 @@ #define _RIVE_MAT2D_HPP_ #include "rive/math/vec2d.hpp" +#include <array> #include <cstddef> namespace rive @@ -9,20 +10,16 @@ class TransformComponents; class Mat2D { -private: - float m_Buffer[6]; - public: - Mat2D() : m_Buffer{1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f} {} - Mat2D(const Mat2D& copy) = default; + Mat2D() : m_buffer{{1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f}} {} Mat2D(float x1, float y1, float x2, float y2, float tx, float ty) : - m_Buffer{x1, y1, x2, y2, tx, ty} + m_buffer{{x1, y1, x2, y2, tx, ty}} {} - inline const float* values() const { return m_Buffer; } + inline const float* values() const { return &m_buffer[0]; } - float& operator[](std::size_t idx) { return m_Buffer[idx]; } - const float& operator[](std::size_t idx) const { return m_Buffer[idx]; } + float& operator[](std::size_t idx) { return m_buffer[idx]; } + const float& operator[](std::size_t idx) const { return m_buffer[idx]; } static Mat2D fromRotation(float rad); static Mat2D fromScale(float sx, float sy) { return {sx, 0, 0, sy, 0, 0}; } @@ -65,21 +62,24 @@ static Mat2D multiply(const Mat2D& a, const Mat2D& b); - float xx() const { return m_Buffer[0]; } - float xy() const { return m_Buffer[1]; } - float yx() const { return m_Buffer[2]; } - float yy() const { return m_Buffer[3]; } - float tx() const { return m_Buffer[4]; } - float ty() const { return m_Buffer[5]; } + float xx() const { return m_buffer[0]; } + float xy() const { return m_buffer[1]; } + float yx() const { return m_buffer[2]; } + float yy() const { return m_buffer[3]; } + float tx() const { return m_buffer[4]; } + float ty() const { return m_buffer[5]; } - Vec2D translation() const { return {m_Buffer[4], m_Buffer[5]}; } + Vec2D translation() const { return {m_buffer[4], m_buffer[5]}; } - void xx(float value) { m_Buffer[0] = value; } - void xy(float value) { m_Buffer[1] = value; } - void yx(float value) { m_Buffer[2] = value; } - void yy(float value) { m_Buffer[3] = value; } - void tx(float value) { m_Buffer[4] = value; } - void ty(float value) { m_Buffer[5] = value; } + void xx(float value) { m_buffer[0] = value; } + void xy(float value) { m_buffer[1] = value; } + void yx(float value) { m_buffer[2] = value; } + void yy(float value) { m_buffer[3] = value; } + void tx(float value) { m_buffer[4] = value; } + void ty(float value) { m_buffer[5] = value; } + +private: + std::array<float, 6> m_buffer; }; inline Vec2D operator*(const Mat2D& m, Vec2D v)
diff --git a/include/rive/math/vec2d.hpp b/include/rive/math/vec2d.hpp index 2d6b723..7e34fbd 100644 --- a/include/rive/math/vec2d.hpp +++ b/include/rive/math/vec2d.hpp
@@ -13,7 +13,6 @@ constexpr Vec2D() : x(0), y(0) {} constexpr Vec2D(float x, float y) : x(x), y(y) {} - constexpr Vec2D(const Vec2D&) = default; float lengthSquared() const { return x * x + y * y; } float length() const;
diff --git a/include/rive/span.hpp b/include/rive/span.hpp index 3dd8ea1..a90e581 100644 --- a/include/rive/span.hpp +++ b/include/rive/span.hpp
@@ -33,7 +33,6 @@ template <typename U, typename = typename std::enable_if<std::is_same<const U, T>::value>::type> constexpr Span(const Span<U>& that) : Span(that.data(), that.size()) {} - constexpr Span(const Span&) = default; template <typename Container> constexpr Span(Container& c) : Span(c.data(), c.size()) {} T& operator[](size_t index) const
diff --git a/src/math/mat2d.cpp b/src/math/mat2d.cpp index 5dab962..194dd02 100644 --- a/src/math/mat2d.cpp +++ b/src/math/mat2d.cpp
@@ -20,12 +20,12 @@ Mat2D Mat2D::scale(Vec2D vec) const { return { - m_Buffer[0] * vec.x, - m_Buffer[1] * vec.x, - m_Buffer[2] * vec.y, - m_Buffer[3] * vec.y, - m_Buffer[4], - m_Buffer[5], + m_buffer[0] * vec.x, + m_buffer[1] * vec.x, + m_buffer[2] * vec.y, + m_buffer[3] * vec.y, + m_buffer[4], + m_buffer[5], }; } @@ -46,9 +46,9 @@ void Mat2D::mapPoints(Vec2D dst[], const Vec2D pts[], size_t n) const { size_t i = 0; - float4 scale = float2{m_Buffer[0], m_Buffer[3]}.xyxy; - float4 skew = simd::load2f(m_Buffer + 1).yxyx; - float4 trans = simd::load2f(m_Buffer + 4).xyxy; + float4 scale = float2{m_buffer[0], m_buffer[3]}.xyxy; + float4 skew = simd::load2f(&m_buffer[1]).yxyx; + float4 trans = simd::load2f(&m_buffer[4]).xyxy; if (simd::all(skew.xy == 0.f)) { // Scale + translate matrix. @@ -89,8 +89,8 @@ bool Mat2D::invert(Mat2D* result) const { - float aa = m_Buffer[0], ab = m_Buffer[1], ac = m_Buffer[2], ad = m_Buffer[3], atx = m_Buffer[4], - aty = m_Buffer[5]; + float aa = m_buffer[0], ab = m_buffer[1], ac = m_buffer[2], ad = m_buffer[3], atx = m_buffer[4], + aty = m_buffer[5]; float det = aa * ad - ab * ac; if (det == 0.0f) @@ -112,7 +112,7 @@ TransformComponents Mat2D::decompose() const { - float m0 = m_Buffer[0], m1 = m_Buffer[1], m2 = m_Buffer[2], m3 = m_Buffer[3]; + float m0 = m_buffer[0], m1 = m_buffer[1], m2 = m_buffer[2], m3 = m_buffer[3]; float rotation = (float)std::atan2(m1, m0); float denom = m0 * m0 + m1 * m1; @@ -121,8 +121,8 @@ float skewX = (float)std::atan2(m0 * m2 + m1 * m3, denom); TransformComponents result; - result.x(m_Buffer[4]); - result.y(m_Buffer[5]); + result.x(m_buffer[4]); + result.y(m_buffer[5]); result.scaleX(scaleX); result.scaleY(scaleY); result.rotation(rotation); @@ -148,8 +148,8 @@ void Mat2D::scaleByValues(float sx, float sy) { - m_Buffer[0] *= sx; - m_Buffer[1] *= sx; - m_Buffer[2] *= sy; - m_Buffer[3] *= sy; + m_buffer[0] *= sx; + m_buffer[1] *= sx; + m_buffer[2] *= sy; + m_buffer[3] *= sy; }
diff --git a/vello/src/main.rs b/vello/src/main.rs index fadb30f..06a4dc0 100644 --- a/vello/src/main.rs +++ b/vello/src/main.rs
@@ -39,7 +39,9 @@ event_loop.run(move |event, _event_loop, control_flow| match event { Event::WindowEvent { ref event, .. } => { - let Some(render_state) = &mut render_state else { return }; + let Some(render_state) = &mut render_state else { + return; + }; match event { WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit, @@ -121,7 +123,9 @@ frame_start_time = Instant::now(); - let Some(render_state) = &mut render_state else { return }; + let Some(render_state) = &mut render_state else { + return; + }; let width = render_state.surface.config.width; let height = render_state.surface.config.height; let device_handle = &render_cx.devices[render_state.surface.dev_id];