mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2025-08-04 21:37:59 +00:00
Bezier-rs: Implement miter-limit (#1096)
* Implement miter-limit approximation * Refactor to use Join enum and address other comments * Rustdocs improvements * Tweaks --------- Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
parent
3733804d18
commit
97be83c404
15 changed files with 106 additions and 69 deletions
|
@ -126,7 +126,7 @@ const subpathFeatures = {
|
|||
},
|
||||
offset: {
|
||||
name: "Offset",
|
||||
callback: (subpath: WasmSubpathInstance, options: Record<string, number>): string => subpath.offset(options.distance, options.join),
|
||||
callback: (subpath: WasmSubpathInstance, options: Record<string, number>): string => subpath.offset(options.distance, options.join, options.miter_limit),
|
||||
inputOptions: [
|
||||
{
|
||||
variable: "distance",
|
||||
|
@ -136,11 +136,18 @@ const subpathFeatures = {
|
|||
default: 10,
|
||||
},
|
||||
joinOptions,
|
||||
{
|
||||
variable: "join: Miter - limit",
|
||||
min: 1,
|
||||
max: 10,
|
||||
step: 0.25,
|
||||
default: 4,
|
||||
},
|
||||
],
|
||||
},
|
||||
outline: {
|
||||
name: "Outline",
|
||||
callback: (subpath: WasmSubpathInstance, options: Record<string, number>): string => subpath.outline(options.distance, options.join, options.cap),
|
||||
callback: (subpath: WasmSubpathInstance, options: Record<string, number>): string => subpath.outline(options.distance, options.join, options.cap, options.miter_limit),
|
||||
inputOptions: [
|
||||
{
|
||||
variable: "distance",
|
||||
|
@ -150,6 +157,13 @@ const subpathFeatures = {
|
|||
default: 10,
|
||||
},
|
||||
joinOptions,
|
||||
{
|
||||
variable: "join: Miter - limit",
|
||||
min: 1,
|
||||
max: 10,
|
||||
step: 0.25,
|
||||
default: 4,
|
||||
},
|
||||
{ ...capOptions, isDisabledForClosed: true },
|
||||
],
|
||||
},
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { BEZIER_T_VALUE_VARIANTS, SUBPATH_T_VALUE_VARIANTS } from "@/utils/types";
|
||||
import { BEZIER_T_VALUE_VARIANTS, CAP_VARIANTS, JOIN_VARIANTS, SUBPATH_T_VALUE_VARIANTS } from "@/utils/types";
|
||||
|
||||
export const tSliderOptions = {
|
||||
min: 0,
|
||||
|
@ -50,12 +50,12 @@ export const joinOptions = {
|
|||
variable: "join",
|
||||
default: 0,
|
||||
inputType: "dropdown",
|
||||
options: ["Bevel", "Miter", "Round"],
|
||||
options: JOIN_VARIANTS,
|
||||
};
|
||||
|
||||
export const capOptions = {
|
||||
variable: "cap",
|
||||
default: 0,
|
||||
inputType: "dropdown",
|
||||
options: ["Butt", "Round", "Square"],
|
||||
options: CAP_VARIANTS,
|
||||
};
|
||||
|
|
|
@ -95,3 +95,6 @@ export interface DemoPane extends HTMLElement {
|
|||
|
||||
export const BEZIER_T_VALUE_VARIANTS = ["Parametric", "Euclidean"] as const;
|
||||
export const SUBPATH_T_VALUE_VARIANTS = ["GlobalParametric", "GlobalEuclidean"] as const;
|
||||
|
||||
export const CAP_VARIANTS = ["Butt", "Round", "Square"] as const;
|
||||
export const JOIN_VARIANTS = ["Bevel", "Miter", "Round"] as const;
|
||||
|
|
|
@ -441,8 +441,8 @@ impl WasmSubpath {
|
|||
wrap_svg_tag(format!("{}{}", self.to_default_svg(), trimmed_subpath_svg))
|
||||
}
|
||||
|
||||
pub fn offset(&self, distance: f64, join: i32) -> String {
|
||||
let join = parse_join(join);
|
||||
pub fn offset(&self, distance: f64, join: i32, miter_limit: f64) -> String {
|
||||
let join = parse_join(join, miter_limit);
|
||||
let offset_subpath = self.0.offset(distance, join);
|
||||
|
||||
let mut offset_svg = String::new();
|
||||
|
@ -451,8 +451,8 @@ impl WasmSubpath {
|
|||
wrap_svg_tag(format!("{}{offset_svg}", self.to_default_svg()))
|
||||
}
|
||||
|
||||
pub fn outline(&self, distance: f64, join: i32, cap: i32) -> String {
|
||||
let join = parse_join(join);
|
||||
pub fn outline(&self, distance: f64, join: i32, cap: i32, miter_limit: f64) -> String {
|
||||
let join = parse_join(join, miter_limit);
|
||||
let cap = parse_cap(cap);
|
||||
let (outline_piece1, outline_piece2) = self.0.outline(distance, join, cap);
|
||||
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
use bezier_rs::{Cap, Join};
|
||||
|
||||
pub fn parse_join(join: i32) -> Join {
|
||||
pub fn parse_join(join: i32, miter_limit: f64) -> Join {
|
||||
match join {
|
||||
0 => Join::Bevel,
|
||||
1 => Join::Miter,
|
||||
1 => Join::Miter(Some(miter_limit)),
|
||||
2 => Join::Round,
|
||||
_ => panic!("Unexpected Join value: '{}'", join),
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue