Skip to content

Commit

Permalink
Delete the copy constructor from Mat2D
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
3 people committed Aug 29, 2023
1 parent ffb3fe7 commit 23be2fe
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 49 deletions.
2 changes: 1 addition & 1 deletion .rive_head
Original file line number Diff line number Diff line change
@@ -1 +1 @@
16cf8082fd9a66014305994c736d98cc12d96c73
d35df04272e659d8244c776e9c4f558452888501
3 changes: 2 additions & 1 deletion build/setup_compiler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ do
'-Wno-four-char-constants',
'-Wno-unreachable-code',
'-Wno-switch-enum',
'-Wno-missing-field-initializers'
'-Wno-missing-field-initializers',
'-Wno-unsafe-buffer-usage'
}
end

Expand Down
1 change: 0 additions & 1 deletion include/rive/math/aabb.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class AABB
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)
{
Expand Down
48 changes: 24 additions & 24 deletions include/rive/math/mat2d.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,24 @@
#define _RIVE_MAT2D_HPP_

#include "rive/math/vec2d.hpp"
#include <array>
#include <cstddef>

namespace rive
{
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}; }
Expand Down Expand Up @@ -65,21 +62,24 @@ class Mat2D

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]; }

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; }
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]}; }

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)
Expand Down
1 change: 0 additions & 1 deletion include/rive/math/vec2d.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ class Vec2D

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;
Expand Down
1 change: 0 additions & 1 deletion include/rive/span.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ template <typename T> class Span
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
Expand Down
36 changes: 18 additions & 18 deletions src/math/mat2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ Mat2D Mat2D::fromRotation(float rad)
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],
};
}

Expand All @@ -46,9 +46,9 @@ Mat2D Mat2D::multiply(const Mat2D& a, const Mat2D& b)
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.
Expand Down Expand Up @@ -89,8 +89,8 @@ void Mat2D::mapPoints(Vec2D dst[], const Vec2D pts[], size_t n) const

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)
Expand All @@ -112,7 +112,7 @@ bool Mat2D::invert(Mat2D* result) const

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;
Expand All @@ -121,8 +121,8 @@ TransformComponents Mat2D::decompose() const
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);
Expand All @@ -148,8 +148,8 @@ Mat2D Mat2D::compose(const TransformComponents& components)

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;
}
8 changes: 6 additions & 2 deletions vello/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ fn main() {

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,
Expand Down Expand Up @@ -121,7 +123,9 @@ fn main() {

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];
Expand Down

0 comments on commit 23be2fe

Please sign in to comment.