Skip to content

Commit

Permalink
rustfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
ctrlcctrlv committed Mar 12, 2023
1 parent cf4fc08 commit 3a60079
Show file tree
Hide file tree
Showing 28 changed files with 610 additions and 500 deletions.
5 changes: 4 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ fn main() {
compile_error!("Features `sdl2-static` and `sdl2-dynamic` are mutually exclusive!");
}
}
let version = git_version!( args = ["--tags", "--always", "--dirty=-desync"], fallback = "v1" );
let version = git_version!(
args = ["--tags", "--always", "--dirty=-desync"],
fallback = "v1"
);
rustc_env!("MFEK_VERSION", "{}", version);
rustc_env!("MFEK_COMPILED_AT", "{}", chrono::Local::now().timestamp());
#[cfg(all(target_os = "macos", feature = "sdl2-dynamic"))]
Expand Down
9 changes: 4 additions & 5 deletions src/contour_operations/dashalongpath.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
use MFEKmath::mfek::ResolveCubic;
use glifparser::glif::contour::MFEKContourCommon;
use glifparser::glif::{MFEKContour, MFEKOutline, contour_operations::dash::DashContour};
use glifparser::{MFEKPointData, Glif};
use glifparser::glif::{contour_operations::dash::DashContour, MFEKContour, MFEKOutline};
use glifparser::{Glif, MFEKPointData};
use MFEKmath::mfek::ResolveCubic;

use super::ContourOperationBuild;

impl ContourOperationBuild for DashContour {
fn build(&self, contour: &MFEKContour<MFEKPointData>) -> MFEKOutline<MFEKPointData> {

let mut glif = Glif::default();

// TODO: Get rid of this call to resolve to cubic and use some internal cache.
glif.outline = Some(vec![contour.to_cubic().cubic().unwrap().clone()]);
let dash_output = MFEKmath::dash_along_glif(&glif, self);
Expand Down
2 changes: 1 addition & 1 deletion src/contour_operations/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ pub mod dashalongpath;
pub mod patternalongpath;
pub mod variablewidthstroke;

use glifparser::glif::contour_operations::{unknown_op_outline, ContourOperations};
use glifparser::glif::{MFEKContour, MFEKOutline};
use glifparser::glif::contour_operations::{ContourOperations, unknown_op_outline};
use glifparser::MFEKPointData;

pub trait ContourOperationBuild {
Expand Down
7 changes: 5 additions & 2 deletions src/contour_operations/patternalongpath.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
use glifparser::{glif::{MFEKContour, MFEKOutline, contour::MFEKContourCommon}, MFEKPointData};
use glifparser::glif::contour_operations::pap::PAPContour;
use glifparser::{
glif::{contour::MFEKContourCommon, MFEKContour, MFEKOutline},
MFEKPointData,
};
use MFEKmath::{pattern_along_path_mfek, Piecewise};

use super::{ContourOperationBuild};
use super::ContourOperationBuild;

impl ContourOperationBuild for PAPContour<MFEKPointData> {
fn build(&self, contour: &MFEKContour<MFEKPointData>) -> MFEKOutline<MFEKPointData> {
Expand Down
6 changes: 3 additions & 3 deletions src/contour_operations/variablewidthstroke.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use MFEKmath::mfek::ResolveCubic;
use glifparser::MFEKPointData;
use glifparser::glif::contour_operations::vws::VWSContour;
use glifparser::glif::{MFEKContour, MFEKOutline};
use glifparser::glif::contour_operations::vws::{VWSContour};
use glifparser::MFEKPointData;
use MFEKmath::mfek::ResolveCubic;
use MFEKmath::{variable_width_stroke, Piecewise, VWSSettings};

use super::ContourOperationBuild;
Expand Down
2 changes: 1 addition & 1 deletion src/editor/contour_handlers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ impl Editor {
MFEKContourInnerType::Quad => Box::new(QuadHandler{}),
}
}
}*/
}*/
13 changes: 7 additions & 6 deletions src/editor/io/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::{events::*, Editor};

use MFEKmath::mfek::ResolveCubic;
use glifparser::glif::contour::MFEKContourCommon;
use MFEKmath::mfek::ResolveCubic;
//use fs2::FileExt as _; # TODO: Add file locking.
use glifparser::glif::mfek::{Layer, MFEKGlif};
use glifparser::{Glif, MFEKPointData};
Expand Down Expand Up @@ -134,14 +134,13 @@ impl Editor {
if let Some(i) = interface {
self.rebuild(i);
}

let mut export = self.prepare_export();
if export.layers.len() > 1 {
log::warn!("In a flatten operation, layers not in the topmost group will be discarded and not in your chosen file. You may want to export (Ctrl+E) and not flatten.");
}
let layer = &mut export.layers[0];


let glif_struct = self.glyph.as_ref().unwrap().to_exported(layer);

let filename = self.with_glyph(|glyph| {
Expand Down Expand Up @@ -370,9 +369,11 @@ pub trait ExportLayer {
/// the normal MFEKGlif type's layers, then you will need to apply contour operations yourself!
impl ExportLayer for MFEKGlif<MFEKPointData> {
fn to_exported(&self, layer: &mut Layer<MFEKPointData>) -> Glif<MFEKPointData> {
let contours: Vec<_> = layer.outline.iter_mut().map(|c|
c.to_cubic().cubic_mut().unwrap().clone()
).collect();
let contours: Vec<_> = layer
.outline
.iter_mut()
.map(|c| c.to_cubic().cubic_mut().unwrap().clone())
.collect();
let mut ret = Glif::new();
ret.outline = Some(contours);
ret.anchors = self.anchors.clone();
Expand Down
4 changes: 3 additions & 1 deletion src/editor/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,6 @@ macro_rules! get_point_mut {
// This re-import is here because I think it's messy to refer to these macros using the top-level
// crate::. This allows me to have in modules e.g. `use crate::editor::macros::get_point`, which is
// our preferred way of importing them.
pub use {get_contour, get_contour_len, get_contour_mut, is_contour_open, get_point, get_point_mut};
pub use {
get_contour, get_contour_len, get_contour_mut, get_point, get_point_mut, is_contour_open,
};
6 changes: 2 additions & 4 deletions src/editor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub struct Editor {
active_tool_enum: ToolEnum,
clipboard: EditorClipboard,

layer_idx: Option<usize>, // active layer
layer_idx: Option<usize>, // active layer
pub contour_idx: Option<usize>, // index into Outline
pub point_idx: Option<usize>,

Expand Down Expand Up @@ -115,7 +115,7 @@ impl Editor {

/// This function MUST be called before calling with_active_<layer/glif>_mut or it will panic.
/// Pushes a clone of the current layer onto the history stack and puts the editor in a modifying state.
/// When the fold argument is set to true the editor won't create new HistoryEntrys if the entry
/// When the fold argument is set to true the editor won't create new HistoryEntrys if the entry
/// below has the same description.
pub fn begin_modification(&mut self, description: &str, fold: bool) {
log::trace!("Modification begun: {}", description);
Expand All @@ -129,7 +129,6 @@ impl Editor {
if fold && description.to_owned() == last_entry.description {
return;
}

}

self.history.add_undo_entry(HistoryEntry {
Expand All @@ -141,7 +140,6 @@ impl Editor {
selected: Some(self.selected.clone()),
glyph: self.glyph.as_ref().unwrap().clone(),
});

}

/// When calling this family of functions the editor will become inaccessible because of the borrow on one of it's members.
Expand Down
11 changes: 8 additions & 3 deletions src/editor/operations.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use crate::contour_operations::ContourOperationBuild;
use crate::user_interface::Interface;
use MFEKmath::mfek::ResolveCubic;
use glifparser::glif::contour::MFEKContourCommon;
use glifparser::outline::skia::{FromSkiaPath, ToSkiaPaths};
use glifparser::{FlattenedGlif, MFEKPointData};
use glifparser::{
glif::{Layer, LayerOperation},
MFEKGlif, Outline,
};
use glifparser::{FlattenedGlif, MFEKPointData};
use skia_safe::PathOp;
use MFEKmath::mfek::ResolveCubic;

use super::Editor;

Expand Down Expand Up @@ -74,7 +74,12 @@ impl Editor {
.glyph
.as_ref()
.expect("Illegally tried to export a null glyph!");
if glyph.layers.len() == 1 && glyph.layers[0].outline.iter().all(|c| c.operation().clone() == None) {
if glyph.layers.len() == 1
&& glyph.layers[0]
.outline
.iter()
.all(|c| c.operation().clone() == None)
{
return glyph.clone();
}

Expand Down
30 changes: 17 additions & 13 deletions src/editor/selection.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
use flo_curves::{bezier::fit_curve_cubic, BezierCurve};
use glifparser::{
glif::{Layer, MFEKContour, contour::MFEKContourCommon, contour_operations::ContourOperation, inner::MFEKCommonInner},
glif::{
contour::MFEKContourCommon, contour_operations::ContourOperation, inner::MFEKCommonInner,
Layer, MFEKContour,
},
outline::skia::ToSkiaPaths as _,
Handle, MFEKPointData, WhichHandle,
};
use MFEKmath::{Bezier, Evaluate, Vector, Rect};
use MFEKmath::{Bezier, Evaluate, Rect, Vector};

use arboard::{self, Clipboard};
use serde_json;
Expand All @@ -13,7 +16,6 @@ use shrinkwraprs;
use super::Editor;
use crate::user_interface::gui;


use std::collections::HashSet;
use std::fmt;

Expand Down Expand Up @@ -259,8 +261,7 @@ impl Editor {

// if the contour is open and previous or next are out of bounds we're working with the start or end of the contour
// so we abort and just delete the selection
if (point_idx == 0 || point_idx == contour.len() - 1) && contour.is_open()
{
if (point_idx == 0 || point_idx == contour.len() - 1) && contour.is_open() {
self.delete_selection();
return;
}
Expand Down Expand Up @@ -375,7 +376,9 @@ impl Editor {
contour[next_idx].b = Handle::At(fitted_curve.w3.x as f32, fitted_curve.w3.y as f32);

contour.remove(point_idx);
layer.outline[contour_idx].operation_mut().remove_op(point_idx);
layer.outline[contour_idx]
.operation_mut()
.remove_op(point_idx);

self.contour_idx = None;
self.point_idx = None;
Expand Down Expand Up @@ -450,33 +453,35 @@ impl Editor {
pub fn build_selection_bounding_box(&self) -> Rect {
let mut points = vec![];
for (ci, pi) in &self.selected {
let point = self.get_active_layer_ref().outline[*ci].get_point(*pi).unwrap();
let point = self.get_active_layer_ref().outline[*ci]
.get_point(*pi)
.unwrap();
points.push(Vector {
x: point.x() as f64,
y: point.y() as f64,
});

if let Some(Handle::At(x, y)) = point.get_handle(WhichHandle::A) {
points.push(Vector {
x: x as f64,
y: y as f64,
});
}

if let Some(Handle::At(x, y)) = point.get_handle(WhichHandle::B) {
points.push(Vector {
x: x as f64,
y: y as f64,
});
}
}

Rect::AABB_from_points(points)
}

pub fn get_selection_bounding_box_center(&self) -> (f32, f32) {
let bounding_box = self.build_selection_bounding_box();

let half_width = ((bounding_box.left - bounding_box.right) / 2.) as f32;
let half_height = ((bounding_box.top - bounding_box.bottom) / 2.) as f32;
(
Expand All @@ -485,7 +490,6 @@ impl Editor {
)
}


pub fn merge_contours(&mut self, start_contour: usize, end_contour: usize) {
let (cidx, pidx) = {
let layer = self.get_active_layer_mut();
Expand Down
19 changes: 11 additions & 8 deletions src/editor/util.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// This file is mainly utilities that are common use cases for the editor, but don't necessarily need to be
// in Editor.

use crate::{get_contour_len, get_point_mut};
use crate::user_interface::Interface;
use crate::{get_contour_len, get_point_mut};
use flo_curves::{
bezier::{solve_curve_for_t_along_axis, Curve as FloCurve},
geo::Coord2,
};
use glifparser::{WhichHandle};
use glifparser::WhichHandle;
use glifrenderer::constants::{POINT_RADIUS, POINT_STROKE_THICKNESS};
use skia_safe::Contains;
use skia_safe::Point as SkPoint;
Expand Down Expand Up @@ -80,7 +80,10 @@ pub fn clicked_point_or_handle(

let size = ((POINT_RADIUS * 2.) + (POINT_STROKE_THICKNESS * 2.)) * (1. / factor);
// Topleft corner of point
let point_tl = SkPoint::new(point.x() as f32 - (size / 2.), point.y() as f32 - (size / 2.));
let point_tl = SkPoint::new(
point.x() as f32 - (size / 2.),
point.y() as f32 - (size / 2.),
);
let point_rect = SkRect::from_point_and_size(point_tl, (size, size));

// winit::PhysicalPosition as an SkPoint
Expand All @@ -93,9 +96,9 @@ pub fn clicked_point_or_handle(
if let Some(handle_pos) = point.get_handle_position(WhichHandle::A) {
let a_tl = SkPoint::new(handle_pos.0 - (size / 2.), handle_pos.1 - (size / 2.));
let a_rect = SkRect::from_point_and_size(a_tl, (size, size));

if a_rect.contains(sk_mpos) {
return Some((contour_idx, point_idx, WhichHandle::A))
return Some((contour_idx, point_idx, WhichHandle::A));
}
}

Expand All @@ -104,7 +107,7 @@ pub fn clicked_point_or_handle(
let b_rect = SkRect::from_point_and_size(b_tl, (size, size));

if b_rect.contains(sk_mpos) {
return Some((contour_idx, point_idx, WhichHandle::B))
return Some((contour_idx, point_idx, WhichHandle::B));
}
}
}
Expand Down Expand Up @@ -176,7 +179,7 @@ pub fn nearest_point_on_curve(
&mouse_vec,
3.5 / i.viewport.factor as f64,
);

if let Some(ct) = ct {
use flo_curves::BezierCurve as _;
use flo_curves::Coordinate as _;
Expand All @@ -187,7 +190,7 @@ pub fn nearest_point_on_curve(
t = Some(ct);
contour_idx = Some(cx);
seg_idx = Some(bx);

let subdivisions = MathPrimitive::subdivide(mbezier, ct);
if let Some(subdivisions) = subdivisions {
h1 = Some(subdivisions.0.to_control_points()[2]);
Expand Down
13 changes: 8 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ fn main() {

Event::MouseButtonDown {
mouse_btn, x, y, ..
} => {
} => {
let position = (x as f32, y as f32);
let mouse_info = MouseInfo::new(
&mut interface,
Expand All @@ -349,10 +349,13 @@ fn main() {
);

if mouse_btn == MouseButton::Middle {
editor.push_behavior(Box::new(PanBehavior::new(interface.viewport.clone(), mouse_info)));
editor.push_behavior(Box::new(PanBehavior::new(
interface.viewport.clone(),
mouse_info,
)));
continue;
}

editor.dispatch_editor_event(
&mut interface,
EditorEvent::MouseEvent {
Expand Down Expand Up @@ -401,7 +404,7 @@ fn main() {
interface.viewport.winsize = (x as f32, y as f32);
interface.viewport.set_broken_flag();
interface.adjust_viewport_by_os_dpi();
sk_surface = interface.create_surface( );
sk_surface = interface.create_surface();
}
_ => {}
},
Expand All @@ -414,7 +417,7 @@ fn main() {
&mut editor,
&mut window_manager,
&mut egui_manager,
&mut sk_surface
&mut sk_surface,
);
}
}
Loading

0 comments on commit 3a60079

Please sign in to comment.