Skip to content

Commit

Permalink
Merge pull request #6 from forkgull/ci
Browse files Browse the repository at this point in the history
Add Github Actions workflow
  • Loading branch information
dfrg authored Dec 20, 2023
2 parents a67e6d3 + 63604e1 commit 6b2efde
Show file tree
Hide file tree
Showing 11 changed files with 166 additions and 65 deletions.
72 changes: 72 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: CI

permissions:
contents: read

on:
pull_request:
push:
branches:
- main

env:
CARGO_INCREMENTAL: 0
CARGO_NET_GIT_FETCH_WITH_CLI: true
CARGO_NET_RETRY: 10
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
RUSTFLAGS: -D warnings
RUSTDOCFLAGS: -D warnings
RUSTUP_MAX_RETRIES: 10

defaults:
run:
shell: bash

jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
rust: [nightly, beta, stable]
steps:
- uses: actions/checkout@v4
- name: Install Rust
run: rustup update ${{ matrix.rust }} && rustup default ${{ matrix.rust }}
- run: rustup target add wasm32-unknown-unknown
- run: rustup target add thumbv7m-none-eabi
- name: Install WASM Test Tools and cargo-hack
uses: taiki-e/install-action@v2
with:
tool: cargo-hack,wasm-pack
- run: cargo test
- run: cargo test --no-default-features --features libm,eval
- run: cargo hack build --all --target thumbv7m-none-eabi \
--no-default-features --features libm,eval --no-dev-deps
- run: cargo check --all --all-features --all-targets --target wasm32-unknown-unknown

clippy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
run: rustup update stable
- run: cargo clippy --all-features --all-targets

fmt:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
run: rustup update stable
- run: cargo fmt --all --check

doc:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
run: rustup update stable
- run: cargo doc --all --all-features
2 changes: 2 additions & 0 deletions src/geometry.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! Geometric primitives.

#[allow(unused)]
use crate::F32Ext;

use core::borrow::Borrow;
Expand Down Expand Up @@ -551,6 +552,7 @@ impl Bounds {

pub(super) struct BoundsBuilder {
pub count: usize,
#[allow(dead_code)]
pub start: Point,
pub current: Point,
pub min: Point,
Expand Down
5 changes: 4 additions & 1 deletion src/mask.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use super::geometry::{Origin, Placement, Transform, Vector};
use super::path_data::{apply, PathData};
use super::scratch::Scratch;
use super::style::{Fill, Style};
#[allow(unused)]
use super::F32Ext;

use crate::lib::Vec;
use core::cell::RefCell;
Expand Down Expand Up @@ -247,6 +249,7 @@ where
}
}

#[allow(clippy::needless_lifetimes)]
pub fn render<'a, 'c, D>(
mask: &'a Mask<'a, 'c, D>,
offset: Vector,
Expand Down Expand Up @@ -293,7 +296,7 @@ pub fn render<'a, 'c, D>(
w,
h,
&mut |r| {
inner.apply(data.clone(), &style, transform, r);
inner.apply(data, &style, transform, r);
},
fill,
pitch,
Expand Down
20 changes: 12 additions & 8 deletions src/path_builder.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
//! Path builder.

#![allow(clippy::excessive_precision)]

use super::command::Command;
use super::geometry::{Angle, BoundsBuilder, Point, Transform};
#[allow(unused)]
use super::F32Ext;

use crate::lib::Vec;
use core::f32;

/// Describes the size of an arc.
#[derive(Copy, Clone, PartialEq)]
Expand Down Expand Up @@ -211,12 +215,11 @@ impl PathBuilder for Vec<Command> {
| Command::CurveTo(_, _, p) => *p,
Command::Close => {
for cmd in self.iter().rev().skip(1) {
match cmd {
Command::MoveTo(p) => return *p,
_ => {}
if let Command::MoveTo(p) = cmd {
return *p;
}
}
return Point::ZERO;
Point::ZERO
}
},
}
Expand Down Expand Up @@ -439,9 +442,9 @@ impl Arc {
}
let segments = ratio.ceil().max(1.);
ang2 /= segments;
let a = if ang2 == 1.5707963267948966 {
let a = if ang2 == f32::consts::FRAC_PI_2 {
0.551915024494
} else if ang2 == -1.5707963267948966 {
} else if ang2 == -f32::consts::FRAC_PI_2 {
-0.551915024494
} else {
4. / 3. * (ang2 / 4.).tan()
Expand Down Expand Up @@ -494,6 +497,7 @@ impl Iterator for Arc {
}
}

#[allow(clippy::too_many_arguments)]
pub fn arc(
sink: &mut impl PathBuilder,
from: Point,
Expand Down Expand Up @@ -568,9 +572,9 @@ pub fn arc(
}
let segments = ratio.ceil().max(1.);
ang2 /= segments;
let a = if ang2 == 1.5707963267948966 {
let a = if ang2 == f32::consts::FRAC_PI_2 {
0.551915024494
} else if ang2 == -1.5707963267948966 {
} else if ang2 == -f32::consts::FRAC_PI_2 {
-0.551915024494
} else {
4. / 3. * (ang2 / 4.).tan()
Expand Down
25 changes: 16 additions & 9 deletions src/raster.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! Path rasterizer.

#![allow(clippy::too_many_arguments)]

use super::geometry::{Point, Vector};
use super::path_builder::PathBuilder;
use super::style::Fill;
Expand Down Expand Up @@ -114,9 +116,9 @@ impl<'a, S: RasterStorage> Rasterizer<'a, S> {
if index != -1 {
let y = ((i as i32) - min.y) as usize;
let row_offset = if y_up {
(pitch * (height - 1 - y)) as usize
pitch * (height - 1 - y)
} else {
(pitch * y) as usize
pitch * y
};
let row = &mut buffer[row_offset..];
let mut x = min.x;
Expand Down Expand Up @@ -206,9 +208,9 @@ impl<'a, S: RasterStorage> Rasterizer<'a, S> {
if index != -1 {
let y = ((i as i32) - min.y) as usize;
let row_offset = if y_up {
(pitch * (height - 1 - y)) as usize
pitch * (height - 1 - y)
} else {
(pitch * y) as usize
pitch * y
};
let mut x = min.x;
let mut cover = 0;
Expand Down Expand Up @@ -377,6 +379,7 @@ impl<'a, S: RasterStorage> Rasterizer<'a, S> {
self.py = to_y;
}

#[allow(clippy::uninit_assumed_init, invalid_value)]
fn quad_to(&mut self, control: FixedPoint, to: FixedPoint) {
let mut arc: [FixedPoint; 16 * 2 + 1] =
unsafe { core::mem::MaybeUninit::uninit().assume_init() };
Expand Down Expand Up @@ -428,6 +431,7 @@ impl<'a, S: RasterStorage> Rasterizer<'a, S> {
}
}

#[allow(clippy::uninit_assumed_init, invalid_value)]
fn curve_to(&mut self, control1: FixedPoint, control2: FixedPoint, to: FixedPoint) {
let mut arc: [FixedPoint; 16 * 8 + 1] =
unsafe { core::mem::MaybeUninit::uninit().assume_init() };
Expand Down Expand Up @@ -589,6 +593,7 @@ impl RasterStorage for HeapStorage {
}

#[inline(always)]
#[allow(clippy::comparison_chain)]
fn set(&mut self, x: i32, y: i32, area: i32, cover: i32) {
let yindex = (y - self.min.y) as usize;
let mut cell_index = self.indices[yindex];
Expand All @@ -607,7 +612,7 @@ impl RasterStorage for HeapStorage {
}
let new_index = self.cells.len();
let cell = Cell {
x: x,
x,
area,
cover,
next: cell_index,
Expand Down Expand Up @@ -636,6 +641,7 @@ pub struct AdaptiveStorage {
}

impl AdaptiveStorage {
#[allow(clippy::uninit_assumed_init, invalid_value)]
pub fn new() -> Self {
Self {
min: FixedPoint::default(),
Expand All @@ -661,7 +667,7 @@ impl RasterStorage for AdaptiveStorage {
if self.height > MAX_BAND {
self.heap_indices.resize((max.y - min.y) as usize, -1);
} else {
for i in 0..self.height as usize {
for i in 0..self.height {
self.indices[i] = -1;
}
}
Expand All @@ -684,14 +690,15 @@ impl RasterStorage for AdaptiveStorage {
}

#[inline(always)]
#[allow(clippy::comparison_chain)]
fn set(&mut self, x: i32, y: i32, area: i32, cover: i32) {
let yindex = (y - self.min.y) as usize;
let indices = if self.height > MAX_BAND {
&mut self.heap_indices[..]
} else {
&mut self.indices[..]
};
let cells = if self.heap_cells.len() != 0 {
let cells = if !self.heap_cells.is_empty() {
&mut self.heap_cells[..]
} else {
&mut self.cells[..]
Expand All @@ -713,7 +720,7 @@ impl RasterStorage for AdaptiveStorage {
let new_index = self.cell_count;
self.cell_count += 1;
let cell = Cell {
x: x,
x,
area,
cover,
next: cell_index,
Expand All @@ -726,7 +733,7 @@ impl RasterStorage for AdaptiveStorage {
if new_index < MAX_CELLS {
cells[new_index] = cell;
} else {
if self.heap_cells.len() == 0 {
if self.heap_cells.is_empty() {
self.heap_cells.extend_from_slice(&self.cells);
}
self.heap_cells.push(cell);
Expand Down
6 changes: 3 additions & 3 deletions src/scratch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,21 +79,21 @@ impl Inner {
let mut transform_sink = TransformSink { sink, transform };
stroke_with_storage(
data.commands(),
&stroke,
stroke,
&mut transform_sink,
&mut self.segments,
);
} else {
stroke_with_storage(
data.commands()
.map(|cmd| cmd.borrow().transform(&transform)),
&stroke,
stroke,
sink,
&mut self.segments,
);
}
} else {
stroke_with_storage(data.commands(), &stroke, sink, &mut self.segments);
stroke_with_storage(data.commands(), stroke, sink, &mut self.segments);
}
Fill::NonZero
}
Expand Down
Loading

0 comments on commit 6b2efde

Please sign in to comment.