62 lines
No EOL
16 KiB
HTML
62 lines
No EOL
16 KiB
HTML
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="Simple 2D geometric primitives on top of euclid."><title>cosmic::widget::canvas::path::lyon_path::geom - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Italic-81dc35de.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-MediumItalic-ccf7e434.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../../../../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../../../../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../../../../../static.files/rustdoc-aa0817cf.css"><meta name="rustdoc-vars" data-root-path="../../../../../../" data-static-root-path="../../../../../../static.files/" data-current-crate="cosmic" data-themes="" data-resource-suffix="" data-rustdoc-version="1.90.0-nightly (3048886e5 2025-07-30)" data-channel="nightly" data-search-js="search-fa3e91e5.js" data-settings-js="settings-5514c975.js" ><script src="../../../../../../static.files/storage-68b7e25d.js"></script><script defer src="../../../../../../crates.js"></script><script defer src="../../../../../../static.files/main-eebb9057.js"></script><noscript><link rel="stylesheet" href="../../../../../../static.files/noscript-32bb7600.css"></noscript><link rel="alternate icon" type="image/png" href="../../../../../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../../../../../static.files/favicon-044be391.svg"></head><body class="rustdoc mod crate"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../../../../../cosmic/index.html">cosmic</a><span class="version">1.0.0</span></h2></div><div class="sidebar-elems"><ul class="block"><li><a id="all-types" href="all.html">All Items</a></li></ul><section id="rustdoc-toc"><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#overview" title="Overview.">Overview.</a></li><li><a href="#flattening" title="Flattening">Flattening</a></li></ul><h3><a href="#modules">Crate Items</a></h3><ul class="block"><li><a href="#modules" title="Modules">Modules</a></li><li><a href="#structs" title="Structs">Structs</a></li><li><a href="#traits" title="Traits">Traits</a></li><li><a href="#functions" title="Functions">Functions</a></li><li><a href="#types" title="Type Aliases">Type Aliases</a></li></ul></section><div id="rustdoc-modnav"><h2><a href="../index.html">In cosmic::<wbr>widget::<wbr>canvas::<wbr>path::<wbr>lyon_<wbr>path</a></h2></div></div></nav><div class="sidebar-resizer" title="Drag to resize sidebar"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><div class="rustdoc-breadcrumbs"><a href="../../../../../index.html">cosmic</a>::<wbr><a href="../../../../index.html">widget</a>::<wbr><a href="../../../index.html">canvas</a>::<wbr><a href="../../index.html">path</a>::<wbr><a href="../index.html">lyon_path</a></div><h1>Crate <span>geom</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"></span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Simple 2D geometric primitives on top of euclid.</p>
|
||
<p>This crate is reexported in <a href="https://docs.rs/lyon/">lyon</a>.</p>
|
||
<h2 id="overview"><a class="doc-anchor" href="#overview">§</a>Overview.</h2>
|
||
<p>This crate implements some of the maths to work with:</p>
|
||
<ul>
|
||
<li>lines and line segments,</li>
|
||
<li>quadratic and cubic bézier curves,</li>
|
||
<li>elliptic arcs,</li>
|
||
<li>triangles.</li>
|
||
</ul>
|
||
<h2 id="flattening"><a class="doc-anchor" href="#flattening">§</a>Flattening</h2>
|
||
<p>Flattening is the action of approximating a curve with a succession of line segments.</p>
|
||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 120 30" height="30mm" width="120mm">
|
||
<path d="M26.7 24.94l.82-11.15M44.46 5.1L33.8 7.34" fill="none" stroke="#55d400" stroke-width=".5"/>
|
||
<path d="M26.7 24.94c.97-11.13 7.17-17.6 17.76-19.84M75.27 24.94l1.13-5.5 2.67-5.48 4-4.42L88 6.7l5.02-1.6" fill="none" stroke="#000"/>
|
||
<path d="M77.57 19.37a1.1 1.1 0 0 1-1.08 1.08 1.1 1.1 0 0 1-1.1-1.08 1.1 1.1 0 0 1 1.08-1.1 1.1 1.1 0 0 1 1.1 1.1" color="#000" fill="none" stroke="#030303" stroke-linecap="round" stroke-opacity=".5"/>
|
||
<path d="M77.57 19.37a1.1 1.1 0 0 1-1.08 1.08 1.1 1.1 0 0 1-1.1-1.08 1.1 1.1 0 0 1 1.08-1.1 1.1 1.1 0 0 1 1.1 1.1" color="#000" fill="#fff"/>
|
||
<path d="M80.22 13.93a1.1 1.1 0 0 1-1.1 1.1 1.1 1.1 0 0 1-1.08-1.1 1.1 1.1 0 0 1 1.1-1.08 1.1 1.1 0 0 1 1.08 1.08" color="#000" fill="none" stroke="#030303" stroke-linecap="round" stroke-opacity=".5"/>
|
||
<path d="M80.22 13.93a1.1 1.1 0 0 1-1.1 1.1 1.1 1.1 0 0 1-1.08-1.1 1.1 1.1 0 0 1 1.1-1.08 1.1 1.1 0 0 1 1.08 1.08" color="#000" fill="#fff"/>
|
||
<path d="M84.08 9.55a1.1 1.1 0 0 1-1.08 1.1 1.1 1.1 0 0 1-1.1-1.1 1.1 1.1 0 0 1 1.1-1.1 1.1 1.1 0 0 1 1.08 1.1" color="#000" fill="none" stroke="#030303" stroke-linecap="round" stroke-opacity=".5"/>
|
||
<path d="M84.08 9.55a1.1 1.1 0 0 1-1.08 1.1 1.1 1.1 0 0 1-1.1-1.1 1.1 1.1 0 0 1 1.1-1.1 1.1 1.1 0 0 1 1.08 1.1" color="#000" fill="#fff"/>
|
||
<path d="M89.1 6.66a1.1 1.1 0 0 1-1.08 1.1 1.1 1.1 0 0 1-1.08-1.1 1.1 1.1 0 0 1 1.08-1.08 1.1 1.1 0 0 1 1.1 1.08" color="#000" fill="none" stroke="#030303" stroke-linecap="round" stroke-opacity=".5"/>
|
||
<path d="M89.1 6.66a1.1 1.1 0 0 1-1.08 1.1 1.1 1.1 0 0 1-1.08-1.1 1.1 1.1 0 0 1 1.08-1.08 1.1 1.1 0 0 1 1.1 1.08" color="#000" fill="#fff"/>
|
||
<path d="M94.4 5a1.1 1.1 0 0 1-1.1 1.1A1.1 1.1 0 0 1 92.23 5a1.1 1.1 0 0 1 1.08-1.08A1.1 1.1 0 0 1 94.4 5" color="#000" fill="none" stroke="#030303" stroke-linecap="round" stroke-opacity=".5"/>
|
||
<path d="M94.4 5a1.1 1.1 0 0 1-1.1 1.1A1.1 1.1 0 0 1 92.23 5a1.1 1.1 0 0 1 1.08-1.08A1.1 1.1 0 0 1 94.4 5" color="#000" fill="#fff"/>
|
||
<path d="M76.44 25.13a1.1 1.1 0 0 1-1.1 1.1 1.1 1.1 0 0 1-1.08-1.1 1.1 1.1 0 0 1 1.1-1.1 1.1 1.1 0 0 1 1.08 1.1" color="#000" fill="none" stroke="#030303" stroke-linecap="round" stroke-opacity=".5"/>
|
||
<path d="M76.44 25.13a1.1 1.1 0 0 1-1.1 1.1 1.1 1.1 0 0 1-1.08-1.1 1.1 1.1 0 0 1 1.1-1.1 1.1 1.1 0 0 1 1.08 1.1" color="#000" fill="#fff"/>
|
||
<path d="M27.78 24.9a1.1 1.1 0 0 1-1.08 1.08 1.1 1.1 0 0 1-1.1-1.08 1.1 1.1 0 0 1 1.1-1.1 1.1 1.1 0 0 1 1.08 1.1" color="#000" fill="none" stroke="#030303" stroke-linecap="round" stroke-opacity=".5"/>
|
||
<path d="M27.78 24.9a1.1 1.1 0 0 1-1.08 1.08 1.1 1.1 0 0 1-1.1-1.08 1.1 1.1 0 0 1 1.1-1.1 1.1 1.1 0 0 1 1.08 1.1" color="#000" fill="#fff"/>
|
||
<path d="M45.4 5.14a1.1 1.1 0 0 1-1.08 1.1 1.1 1.1 0 0 1-1.1-1.1 1.1 1.1 0 0 1 1.1-1.08 1.1 1.1 0 0 1 1.1 1.08" color="#000" fill="none" stroke="#030303" stroke-linecap="round" stroke-opacity=".5"/>
|
||
<path d="M45.4 5.14a1.1 1.1 0 0 1-1.08 1.1 1.1 1.1 0 0 1-1.1-1.1 1.1 1.1 0 0 1 1.1-1.08 1.1 1.1 0 0 1 1.1 1.08" color="#000" fill="#fff"/>
|
||
<path d="M28.67 13.8a1.1 1.1 0 0 1-1.1 1.08 1.1 1.1 0 0 1-1.08-1.08 1.1 1.1 0 0 1 1.08-1.1 1.1 1.1 0 0 1 1.1 1.1" color="#000" fill="none" stroke="#030303" stroke-linecap="round" stroke-opacity=".5"/>
|
||
<path d="M28.67 13.8a1.1 1.1 0 0 1-1.1 1.08 1.1 1.1 0 0 1-1.08-1.08 1.1 1.1 0 0 1 1.08-1.1 1.1 1.1 0 0 1 1.1 1.1" color="#000" fill="#fff"/>
|
||
<path d="M35 7.32a1.1 1.1 0 0 1-1.1 1.1 1.1 1.1 0 0 1-1.08-1.1 1.1 1.1 0 0 1 1.1-1.1A1.1 1.1 0 0 1 35 7.33" color="#000" fill="none" stroke="#030303" stroke-linecap="round" stroke-opacity=".5"/>
|
||
<path d="M35 7.32a1.1 1.1 0 0 1-1.1 1.1 1.1 1.1 0 0 1-1.08-1.1 1.1 1.1 0 0 1 1.1-1.1A1.1 1.1 0 0 1 35 7.33" color="#000" fill="#fff"/>
|
||
<text style="line-height:6.61458302px" x="35.74" y="284.49" font-size="5.29" font-family="Sans" letter-spacing="0" word-spacing="0" fill="#b3b3b3" stroke-width=".26" transform="translate(19.595 -267)">
|
||
<tspan x="35.74" y="284.49" font-size="10.58">→</tspan>
|
||
</text>
|
||
</svg>
|
||
<p>The tolerance threshold taken as input by the flattening algorithms corresponds
|
||
to the maximum distance between the curve and its linear approximation.
|
||
The smaller the tolerance is, the more precise the approximation and the more segments
|
||
are generated. This value is typically chosen in function of the zoom level.</p>
|
||
<svg viewBox="0 0 47.5 13.2" height="100" width="350" xmlns="http://www.w3.org/2000/svg">
|
||
<path d="M-2.44 9.53c16.27-8.5 39.68-7.93 52.13 1.9" fill="none" stroke="#dde9af" stroke-width="4.6"/>
|
||
<path d="M-1.97 9.3C14.28 1.03 37.36 1.7 49.7 11.4" fill="none" stroke="#00d400" stroke-width=".57" stroke-linecap="round" stroke-dasharray="4.6, 2.291434"/>
|
||
<path d="M-1.94 10.46L6.2 6.08l28.32-1.4 15.17 6.74" fill="none" stroke="#000" stroke-width=".6"/>
|
||
<path d="M6.83 6.57a.9.9 0 0 1-1.25.15.9.9 0 0 1-.15-1.25.9.9 0 0 1 1.25-.15.9.9 0 0 1 .15 1.25" color="#000" stroke="#000" stroke-width=".57" stroke-linecap="round" stroke-opacity=".5"/>
|
||
<path d="M35.35 5.3a.9.9 0 0 1-1.25.15.9.9 0 0 1-.15-1.25.9.9 0 0 1 1.25-.15.9.9 0 0 1 .15 1.24" color="#000" stroke="#000" stroke-width=".6" stroke-opacity=".5"/>
|
||
<g fill="none" stroke="#ff7f2a" stroke-width=".26">
|
||
<path d="M20.4 3.8l.1 1.83M19.9 4.28l.48-.56.57.52M21.02 5.18l-.5.56-.6-.53" stroke-width=".2978872"/>
|
||
</g>
|
||
</svg>
|
||
<p>The figure above shows a close up on a curve (the dotted line) and its linear
|
||
approximation (the black segments). The tolerance threshold is represented by
|
||
the light green area and the orange arrow.</p>
|
||
</div></details><h2 id="modules" class="section-header">Modules<a href="#modules" class="anchor">§</a></h2><dl class="item-table"><dt><a class="mod" href="arc/index.html" title="mod cosmic::widget::canvas::path::lyon_path::geom::arc">arc</a></dt><dd>Elliptic arc related maths and tools.</dd><dt><a class="mod" href="arrayvec/index.html" title="mod cosmic::widget::canvas::path::lyon_path::geom::arrayvec">arrayvec</a></dt><dd><strong>arrayvec</strong> provides the types <a href="arrayvec/struct.ArrayVec.html" title="struct cosmic::widget::canvas::path::lyon_path::geom::arrayvec::ArrayVec"><code>ArrayVec</code></a> and <a href="arrayvec/struct.ArrayString.html" title="struct cosmic::widget::canvas::path::lyon_path::geom::arrayvec::ArrayString"><code>ArrayString</code></a>:
|
||
array-backed vector and string types, which store their contents inline.</dd><dt><a class="mod" href="cubic_bezier/index.html" title="mod cosmic::widget::canvas::path::lyon_path::geom::cubic_bezier">cubic_<wbr>bezier</a></dt><dt><a class="mod" href="euclid/index.html" title="mod cosmic::widget::canvas::path::lyon_path::geom::euclid">euclid</a></dt><dd>A collection of strongly typed math tools for computer graphics with an inclination
|
||
towards 2d graphics and layout.</dd><dt><a class="mod" href="quadratic_bezier/index.html" title="mod cosmic::widget::canvas::path::lyon_path::geom::quadratic_bezier">quadratic_<wbr>bezier</a></dt><dt><a class="mod" href="traits/index.html" title="mod cosmic::widget::canvas::path::lyon_path::geom::traits">traits</a></dt><dt><a class="mod" href="utils/index.html" title="mod cosmic::widget::canvas::path::lyon_path::geom::utils">utils</a></dt></dl><h2 id="structs" class="section-header">Structs<a href="#structs" class="anchor">§</a></h2><dl class="item-table"><dt><a class="struct" href="struct.Angle.html" title="struct cosmic::widget::canvas::path::lyon_path::geom::Angle">Angle</a></dt><dd>An angle in radians</dd><dt><a class="struct" href="struct.Arc.html" title="struct cosmic::widget::canvas::path::lyon_path::geom::Arc">Arc</a></dt><dd>An elliptic arc curve segment.</dd><dt><a class="struct" href="struct.ArcFlags.html" title="struct cosmic::widget::canvas::path::lyon_path::geom::ArcFlags">ArcFlags</a></dt><dd>Flag parameters for arcs as described by the SVG specification.</dd><dt><a class="struct" href="struct.CubicBezierSegment.html" title="struct cosmic::widget::canvas::path::lyon_path::geom::CubicBezierSegment">Cubic<wbr>Bezier<wbr>Segment</a></dt><dd>A 2d curve segment defined by four points: the beginning of the segment, two control
|
||
points and the end of the segment.</dd><dt><a class="struct" href="struct.Line.html" title="struct cosmic::widget::canvas::path::lyon_path::geom::Line">Line</a></dt><dd>An infinite line defined by a point and a vector.</dd><dt><a class="struct" href="struct.LineEquation.html" title="struct cosmic::widget::canvas::path::lyon_path::geom::LineEquation">Line<wbr>Equation</a></dt><dd>A line defined by the equation
|
||
<code>a * x + b * y + c = 0; a * a + b * b = 1</code>.</dd><dt><a class="struct" href="struct.LineSegment.html" title="struct cosmic::widget::canvas::path::lyon_path::geom::LineSegment">Line<wbr>Segment</a></dt><dd>A linear segment.</dd><dt><a class="struct" href="struct.QuadraticBezierSegment.html" title="struct cosmic::widget::canvas::path::lyon_path::geom::QuadraticBezierSegment">Quadratic<wbr>Bezier<wbr>Segment</a></dt><dd>A 2d curve segment defined by three points: the beginning of the segment, a control
|
||
point and the end of the segment.</dd><dt><a class="struct" href="struct.SvgArc.html" title="struct cosmic::widget::canvas::path::lyon_path::geom::SvgArc">SvgArc</a></dt><dd>An elliptic arc curve segment using the SVG’s end-point notation.</dd><dt><a class="struct" href="struct.Triangle.html" title="struct cosmic::widget::canvas::path::lyon_path::geom::Triangle">Triangle</a></dt><dd>A 2D triangle defined by three points <code>a</code>, <code>b</code> and <code>c</code>.</dd></dl><h2 id="traits" class="section-header">Traits<a href="#traits" class="anchor">§</a></h2><dl class="item-table"><dt><a class="trait" href="trait.Scalar.html" title="trait cosmic::widget::canvas::path::lyon_path::geom::Scalar">Scalar</a></dt><dt><a class="trait" href="trait.Segment.html" title="trait cosmic::widget::canvas::path::lyon_path::geom::Segment">Segment</a></dt><dd>Common APIs to segment types.</dd></dl><h2 id="functions" class="section-header">Functions<a href="#functions" class="anchor">§</a></h2><dl class="item-table"><dt><a class="fn" href="fn.point.html" title="fn cosmic::widget::canvas::path::lyon_path::geom::point">point</a></dt><dd>Shorthand for <code>Point::new(x, y)</code>.</dd><dt><a class="fn" href="fn.size.html" title="fn cosmic::widget::canvas::path::lyon_path::geom::size">size</a></dt><dd>Shorthand for <code>Size::new(x, y)</code>.</dd><dt><a class="fn" href="fn.vector.html" title="fn cosmic::widget::canvas::path::lyon_path::geom::vector">vector</a></dt><dd>Shorthand for <code>Vector::new(x, y)</code>.</dd></dl><h2 id="types" class="section-header">Type Aliases<a href="#types" class="anchor">§</a></h2><dl class="item-table"><dt><a class="type" href="type.Box2D.html" title="type cosmic::widget::canvas::path::lyon_path::geom::Box2D">Box2D</a></dt><dt><a class="type" href="type.Point.html" title="type cosmic::widget::canvas::path::lyon_path::geom::Point">Point</a></dt><dt><a class="type" href="type.Rotation.html" title="type cosmic::widget::canvas::path::lyon_path::geom::Rotation">Rotation</a></dt><dd>Alias for <code>euclid::default::Rotation2D</code></dd><dt><a class="type" href="type.Scale.html" title="type cosmic::widget::canvas::path::lyon_path::geom::Scale">Scale</a></dt><dt><a class="type" href="type.Size.html" title="type cosmic::widget::canvas::path::lyon_path::geom::Size">Size</a></dt><dt><a class="type" href="type.Transform.html" title="type cosmic::widget::canvas::path::lyon_path::geom::Transform">Transform</a></dt><dd>Alias for <code>euclid::default::Transform2D</code></dd><dt><a class="type" href="type.Translation.html" title="type cosmic::widget::canvas::path::lyon_path::geom::Translation">Translation</a></dt><dd>Alias for <code>euclid::default::Translation2D</code></dd><dt><a class="type" href="type.Vector.html" title="type cosmic::widget::canvas::path::lyon_path::geom::Vector">Vector</a></dt></dl></section></div></main></body></html> |