Files
phy/hexasphere/trait.BaseShape.html
Orion Kindel 0ce894e6b0 doc
2025-03-18 10:30:23 -05:00

115 lines
22 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!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="Defines the geometry of the shape to be subdivided, and the functions used in interpolation."><title>BaseShape in hexasphere - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.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-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../" data-static-root-path="../static.files/" data-current-crate="hexasphere" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.0 (9fc6b4312 2025-01-07)" data-channel="1.84.0" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../static.files/storage-59e33391.js"></script><script defer src="sidebar-items.js"></script><script defer src="../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../static.files/noscript-893ab5e7.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 trait"><!--[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="../hexasphere/index.html">hexasphere</a><span class="version">15.1.0</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">Base<wbr>Shape</a></h2><h3><a href="#required-associated-consts">Required Associated Constants</a></h3><ul class="block"><li><a href="#associatedconstant.EDGES" title="EDGES">EDGES</a></li></ul><h3><a href="#required-methods">Required Methods</a></h3><ul class="block"><li><a href="#tymethod.initial_points" title="initial_points">initial_points</a></li><li><a href="#tymethod.interpolate" title="interpolate">interpolate</a></li><li><a href="#tymethod.triangles" title="triangles">triangles</a></li></ul><h3><a href="#provided-methods">Provided Methods</a></h3><ul class="block"><li><a href="#method.interpolate_half" title="interpolate_half">interpolate_half</a></li><li><a href="#method.interpolate_multiple" title="interpolate_multiple">interpolate_multiple</a></li></ul><h3><a href="#dyn-compatibility">Dyn Compatibility</a></h3><h3><a href="#implementors">Implementors</a></h3></section><div id="rustdoc-modnav"><h2 class="in-crate"><a href="index.html">In crate hexasphere</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="index.html">hexasphere</a></span><h1>Trait <span class="trait">BaseShape</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../src/hexasphere/lib.rs.html#124-212">Source</a> </span></div><pre class="rust item-decl"><code>pub trait BaseShape {
const <a href="#associatedconstant.EDGES" class="constant">EDGES</a>: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.usize.html">usize</a>;
// Required methods
fn <a href="#tymethod.initial_points" class="fn">initial_points</a>(&amp;self) -&gt; <a class="struct" href="https://doc.rust-lang.org/1.84.0/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a>&lt;<a class="struct" href="../glam/f32/sse2/vec3a/struct.Vec3A.html" title="struct glam::f32::sse2::vec3a::Vec3A">Vec3A</a>&gt;;
<span class="item-spacer"></span> fn <a href="#tymethod.triangles" class="fn">triangles</a>(&amp;self) -&gt; <a class="struct" href="https://doc.rust-lang.org/1.84.0/alloc/boxed/struct.Box.html" title="struct alloc::boxed::Box">Box</a>&lt;[<a class="struct" href="struct.Triangle.html" title="struct hexasphere::Triangle">Triangle</a>]&gt;;
<span class="item-spacer"></span> fn <a href="#tymethod.interpolate" class="fn">interpolate</a>(&amp;self, a: <a class="struct" href="../glam/f32/sse2/vec3a/struct.Vec3A.html" title="struct glam::f32::sse2::vec3a::Vec3A">Vec3A</a>, b: <a class="struct" href="../glam/f32/sse2/vec3a/struct.Vec3A.html" title="struct glam::f32::sse2::vec3a::Vec3A">Vec3A</a>, p: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.f32.html">f32</a>) -&gt; <a class="struct" href="../glam/f32/sse2/vec3a/struct.Vec3A.html" title="struct glam::f32::sse2::vec3a::Vec3A">Vec3A</a>;
// Provided methods
fn <a href="#method.interpolate_half" class="fn">interpolate_half</a>(&amp;self, a: <a class="struct" href="../glam/f32/sse2/vec3a/struct.Vec3A.html" title="struct glam::f32::sse2::vec3a::Vec3A">Vec3A</a>, b: <a class="struct" href="../glam/f32/sse2/vec3a/struct.Vec3A.html" title="struct glam::f32::sse2::vec3a::Vec3A">Vec3A</a>) -&gt; <a class="struct" href="../glam/f32/sse2/vec3a/struct.Vec3A.html" title="struct glam::f32::sse2::vec3a::Vec3A">Vec3A</a> { ... }
<span class="item-spacer"></span> fn <a href="#method.interpolate_multiple" class="fn">interpolate_multiple</a>(
&amp;self,
a: <a class="struct" href="../glam/f32/sse2/vec3a/struct.Vec3A.html" title="struct glam::f32::sse2::vec3a::Vec3A">Vec3A</a>,
b: <a class="struct" href="../glam/f32/sse2/vec3a/struct.Vec3A.html" title="struct glam::f32::sse2::vec3a::Vec3A">Vec3A</a>,
indices: &amp;[<a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.u32.html">u32</a>],
points: &amp;mut [<a class="struct" href="../glam/f32/sse2/vec3a/struct.Vec3A.html" title="struct glam::f32::sse2::vec3a::Vec3A">Vec3A</a>],
) { ... }
}</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Defines the geometry of the shape to be subdivided, and the functions
used in interpolation.</p>
<p>If you want to use a different interpolation function,
implement this trait for a new type, and carry over only
the properties youd like to keep:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>hexasphere::{Triangle, shapes::IcoSphereBase};
<span class="kw">use </span>glam::Vec3A;
<span class="comment">// Uses linear interpolation instead of spherical.
</span><span class="kw">struct </span>FlatIcosahedron;
<span class="kw">impl </span>BaseShape <span class="kw">for </span>FlatIcosahedron {
<span class="comment">// Keep the initial parameters.
</span><span class="kw">fn </span>initial_points(<span class="kw-2">&amp;</span><span class="self">self</span>) -&gt; Vec&lt;Vec3A&gt; {
IcoSphereBase.initial_points()
}
<span class="kw">fn </span>triangles(<span class="kw-2">&amp;</span><span class="self">self</span>) -&gt; Box&lt;[Triangle]&gt; {
IcoSphereBase.triangles()
}
<span class="kw">const </span>EDGES: usize = IcoSphereBase::EDGES;
<span class="comment">// Swap out what you'd like to change.
</span><span class="kw">fn </span>interpolate(<span class="kw-2">&amp;</span><span class="self">self</span>, a: Vec3A, b: Vec3A, p: f32) -&gt; Vec3A {
hexasphere::interpolation::lerp(a, b, p)
}
<span class="kw">fn </span>interpolate_half(<span class="kw-2">&amp;</span><span class="self">self</span>, a: Vec3A, b: Vec3A) -&gt; Vec3A {
hexasphere::interpolation::lerp_half(a, b)
}
<span class="kw">fn </span>interpolate_multiple(<span class="kw-2">&amp;</span><span class="self">self</span>, a: Vec3A, b: Vec3A, indices: <span class="kw-2">&amp;</span>[u32], points: <span class="kw-2">&amp;mut </span>[Vec3A]) {
hexasphere::interpolation::lerp_multiple(a, b, indices, points);
}
}</code></pre></div>
<p>Or, create your own shape, by changing the values for
<a href="#tymethod.initial_points"><code>initial_points</code></a>, <a href="#tymethod.triangles"><code>triangles</code></a>, and <a href="#associatedconstant.EDGES"><code>EDGES</code></a>. Check
the documentation for these members individually on how
they should be implemented.</p>
</div></details><h2 id="required-associated-consts" class="section-header">Required Associated Constants<a href="#required-associated-consts" class="anchor">§</a></h2><div class="methods"><details class="toggle" open><summary><section id="associatedconstant.EDGES" class="method"><a class="src rightside" href="../src/hexasphere/lib.rs.html#160">Source</a><h4 class="code-header">const <a href="#associatedconstant.EDGES" class="constant">EDGES</a>: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.usize.html">usize</a></h4></section></summary><div class="docblock"><p>Number of unique edges defined in the contents of
<code>triangles()</code>. This number is 5 for a square for
example:</p>
<div class="example-wrap"><pre class="language-text"><code>a - 0 - b
| / |
3 4 1
| / |
d - 2 - c</code></pre></div></div></details></div><h2 id="required-methods" class="section-header">Required Methods<a href="#required-methods" class="anchor">§</a></h2><div class="methods"><details class="toggle method-toggle" open><summary><section id="tymethod.initial_points" class="method"><a class="src rightside" href="../src/hexasphere/lib.rs.html#138">Source</a><h4 class="code-header">fn <a href="#tymethod.initial_points" class="fn">initial_points</a>(&amp;self) -&gt; <a class="struct" href="https://doc.rust-lang.org/1.84.0/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a>&lt;<a class="struct" href="../glam/f32/sse2/vec3a/struct.Vec3A.html" title="struct glam::f32::sse2::vec3a::Vec3A">Vec3A</a>&gt;</h4></section></summary><div class="docblock"><p>The vertices for all main triangles of the shape.
Check the source file for this
crate and look for the constants module at the bottom
for an example.</p>
<p>Constraints on the points depend on the interpolation
function used:</p>
<ul>
<li><code>slerp</code> requires normalized (magnitude 1) data.</li>
<li><code>lerp</code> doesnt care.</li>
<li><code>normalized_lerp</code> requires normalized (magnitude 1)
data.</li>
</ul>
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.triangles" class="method"><a class="src rightside" href="../src/hexasphere/lib.rs.html#146">Source</a><h4 class="code-header">fn <a href="#tymethod.triangles" class="fn">triangles</a>(&amp;self) -&gt; <a class="struct" href="https://doc.rust-lang.org/1.84.0/alloc/boxed/struct.Box.html" title="struct alloc::boxed::Box">Box</a>&lt;[<a class="struct" href="struct.Triangle.html" title="struct hexasphere::Triangle">Triangle</a>]&gt;</h4></section></summary><div class="docblock"><p>Main triangles for the shape;
that is, the triangles which exist before subdivision.</p>
<p>See <a href="struct.Triangle.html#method.new" title="associated function hexasphere::Triangle::new"><code>Triangle::new()</code></a> for details.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.interpolate" class="method"><a class="src rightside" href="../src/hexasphere/lib.rs.html#179">Source</a><h4 class="code-header">fn <a href="#tymethod.interpolate" class="fn">interpolate</a>(&amp;self, a: <a class="struct" href="../glam/f32/sse2/vec3a/struct.Vec3A.html" title="struct glam::f32::sse2::vec3a::Vec3A">Vec3A</a>, b: <a class="struct" href="../glam/f32/sse2/vec3a/struct.Vec3A.html" title="struct glam::f32::sse2::vec3a::Vec3A">Vec3A</a>, p: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.f32.html">f32</a>) -&gt; <a class="struct" href="../glam/f32/sse2/vec3a/struct.Vec3A.html" title="struct glam::f32::sse2::vec3a::Vec3A">Vec3A</a></h4></section></summary><div class="docblock"><p>Basic function used for interpolation. When <code>p</code> is
<code>0.0</code>, <code>a</code> is expected. When <code>p</code> is <code>1.0</code>, <code>b</code> is
expected. There are three options already implemented
in this crate:</p>
<ul>
<li><a href="../fn.lerp.html"><code>lerp</code></a> implements linear interpolation.</li>
<li><a href="../fn.geometric_slerp.html"><code>geometric_slerp</code></a> implements spherical
interpolation. (Interpolates along an arc on a sphere)</li>
<li><a href="../fn.normalized_lerp.html"><code>normalized_lerp</code></a> implements cheaper
yet less accurate spherical interpolation. The accuracy
decreases as the angle between the two points on the unit
sphere increases.</li>
</ul>
</div></details></div><h2 id="provided-methods" class="section-header">Provided Methods<a href="#provided-methods" class="anchor">§</a></h2><div class="methods"><details class="toggle method-toggle" open><summary><section id="method.interpolate_half" class="method"><a class="src rightside" href="../src/hexasphere/lib.rs.html#186-188">Source</a><h4 class="code-header">fn <a href="#method.interpolate_half" class="fn">interpolate_half</a>(&amp;self, a: <a class="struct" href="../glam/f32/sse2/vec3a/struct.Vec3A.html" title="struct glam::f32::sse2::vec3a::Vec3A">Vec3A</a>, b: <a class="struct" href="../glam/f32/sse2/vec3a/struct.Vec3A.html" title="struct glam::f32::sse2::vec3a::Vec3A">Vec3A</a>) -&gt; <a class="struct" href="../glam/f32/sse2/vec3a/struct.Vec3A.html" title="struct glam::f32::sse2::vec3a::Vec3A">Vec3A</a></h4></section></summary><div class="docblock"><p>If an optimization is available for the case where <code>p</code>
is <code>0.5</code>, this function should implement it. This defaults
to calling <code>interpolate(a, b, 0.5)</code> however.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="method.interpolate_multiple" class="method"><a class="src rightside" href="../src/hexasphere/lib.rs.html#205-211">Source</a><h4 class="code-header">fn <a href="#method.interpolate_multiple" class="fn">interpolate_multiple</a>(
&amp;self,
a: <a class="struct" href="../glam/f32/sse2/vec3a/struct.Vec3A.html" title="struct glam::f32::sse2::vec3a::Vec3A">Vec3A</a>,
b: <a class="struct" href="../glam/f32/sse2/vec3a/struct.Vec3A.html" title="struct glam::f32::sse2::vec3a::Vec3A">Vec3A</a>,
indices: &amp;[<a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.u32.html">u32</a>],
points: &amp;mut [<a class="struct" href="../glam/f32/sse2/vec3a/struct.Vec3A.html" title="struct glam::f32::sse2::vec3a::Vec3A">Vec3A</a>],
)</h4></section></summary><div class="docblock"><p>If an optimization is available for the case where <code>p</code>
varies but <code>a</code> and <code>b</code> dont, this function should implement
it.</p>
<h6 id="parameters"><a class="doc-anchor" href="#parameters">§</a>Parameters</h6>
<ul>
<li><code>a</code>: start.</li>
<li><code>b</code>: end.</li>
<li><code>indices</code>: list of indices to index into <code>points</code>. <code>points</code>
at the index should contain the result. The index (n) of an
index should correspond with the nth point in a distribution
of <code>indices.len()</code> points between (exclusive) <code>a</code> and <code>b</code>.</li>
<li><code>points</code>: list of points where the results of the calculation
should end up. To be indexed by values in <code>indices</code>.</li>
</ul>
</div></details></div><h2 id="dyn-compatibility" class="section-header">Dyn Compatibility<a href="#dyn-compatibility" class="anchor">§</a></h2><div class="dyn-compatibility-info"><p>This trait is <b>not</b> <a href="https://doc.rust-lang.org/1.84.0/reference/items/traits.html#object-safety">dyn compatible</a>.</p><p><i>In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.</i></p></div><h2 id="implementors" class="section-header">Implementors<a href="#implementors" class="anchor">§</a></h2><div id="implementors-list"><details class="toggle implementors-toggle"><summary><section id="impl-BaseShape-for-CubeBase" class="impl"><a class="src rightside" href="../src/hexasphere/shapes.rs.html#329-355">Source</a><a href="#impl-BaseShape-for-CubeBase" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="trait.BaseShape.html" title="trait hexasphere::BaseShape">BaseShape</a> for <a class="struct" href="shapes/struct.CubeBase.html" title="struct hexasphere::shapes::CubeBase">CubeBase</a></h3></section></summary><div class="impl-items"><section id="associatedconstant.EDGES-1" class="associatedconstant trait-impl"><a class="src rightside" href="../src/hexasphere/shapes.rs.html#339">Source</a><a href="#associatedconstant.EDGES-1" class="anchor">§</a><h4 class="code-header">const <a href="#associatedconstant.EDGES" class="constant">EDGES</a>: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.usize.html">usize</a> = 18usize</h4></section></div></details><details class="toggle implementors-toggle"><summary><section id="impl-BaseShape-for-IcoSphereBase" class="impl"><a class="src rightside" href="../src/hexasphere/shapes.rs.html#24-50">Source</a><a href="#impl-BaseShape-for-IcoSphereBase" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="trait.BaseShape.html" title="trait hexasphere::BaseShape">BaseShape</a> for <a class="struct" href="shapes/struct.IcoSphereBase.html" title="struct hexasphere::shapes::IcoSphereBase">IcoSphereBase</a></h3></section></summary><div class="impl-items"><section id="associatedconstant.EDGES-2" class="associatedconstant trait-impl"><a class="src rightside" href="../src/hexasphere/shapes.rs.html#34">Source</a><a href="#associatedconstant.EDGES-2" class="anchor">§</a><h4 class="code-header">const <a href="#associatedconstant.EDGES" class="constant">EDGES</a>: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.usize.html">usize</a> = 30usize</h4></section></div></details><details class="toggle implementors-toggle"><summary><section id="impl-BaseShape-for-NormIcoSphereBase" class="impl"><a class="src rightside" href="../src/hexasphere/shapes.rs.html#95-121">Source</a><a href="#impl-BaseShape-for-NormIcoSphereBase" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="trait.BaseShape.html" title="trait hexasphere::BaseShape">BaseShape</a> for <a class="struct" href="shapes/struct.NormIcoSphereBase.html" title="struct hexasphere::shapes::NormIcoSphereBase">NormIcoSphereBase</a></h3></section></summary><div class="impl-items"><section id="associatedconstant.EDGES-3" class="associatedconstant trait-impl"><a class="src rightside" href="../src/hexasphere/shapes.rs.html#105">Source</a><a href="#associatedconstant.EDGES-3" class="anchor">§</a><h4 class="code-header">const <a href="#associatedconstant.EDGES" class="constant">EDGES</a>: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.usize.html">usize</a> = 30usize</h4></section></div></details><details class="toggle implementors-toggle"><summary><section id="impl-BaseShape-for-SquareBase" class="impl"><a class="src rightside" href="../src/hexasphere/shapes.rs.html#281-307">Source</a><a href="#impl-BaseShape-for-SquareBase" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="trait.BaseShape.html" title="trait hexasphere::BaseShape">BaseShape</a> for <a class="struct" href="shapes/struct.SquareBase.html" title="struct hexasphere::shapes::SquareBase">SquareBase</a></h3></section></summary><div class="impl-items"><section id="associatedconstant.EDGES-4" class="associatedconstant trait-impl"><a class="src rightside" href="../src/hexasphere/shapes.rs.html#291">Source</a><a href="#associatedconstant.EDGES-4" class="anchor">§</a><h4 class="code-header">const <a href="#associatedconstant.EDGES" class="constant">EDGES</a>: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.usize.html">usize</a> = 5usize</h4></section></div></details><details class="toggle implementors-toggle"><summary><section id="impl-BaseShape-for-TetraSphereBase" class="impl"><a class="src rightside" href="../src/hexasphere/shapes.rs.html#158-184">Source</a><a href="#impl-BaseShape-for-TetraSphereBase" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="trait.BaseShape.html" title="trait hexasphere::BaseShape">BaseShape</a> for <a class="struct" href="shapes/struct.TetraSphereBase.html" title="struct hexasphere::shapes::TetraSphereBase">TetraSphereBase</a></h3></section></summary><div class="impl-items"><section id="associatedconstant.EDGES-5" class="associatedconstant trait-impl"><a class="src rightside" href="../src/hexasphere/shapes.rs.html#168">Source</a><a href="#associatedconstant.EDGES-5" class="anchor">§</a><h4 class="code-header">const <a href="#associatedconstant.EDGES" class="constant">EDGES</a>: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.usize.html">usize</a> = 6usize</h4></section></div></details><details class="toggle implementors-toggle"><summary><section id="impl-BaseShape-for-TriangleBase" class="impl"><a class="src rightside" href="../src/hexasphere/shapes.rs.html#219-247">Source</a><a href="#impl-BaseShape-for-TriangleBase" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="trait.BaseShape.html" title="trait hexasphere::BaseShape">BaseShape</a> for <a class="struct" href="shapes/struct.TriangleBase.html" title="struct hexasphere::shapes::TriangleBase">TriangleBase</a></h3></section></summary><div class="impl-items"><section id="associatedconstant.EDGES-6" class="associatedconstant trait-impl"><a class="src rightside" href="../src/hexasphere/shapes.rs.html#231">Source</a><a href="#associatedconstant.EDGES-6" class="anchor">§</a><h4 class="code-header">const <a href="#associatedconstant.EDGES" class="constant">EDGES</a>: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.usize.html">usize</a> = 3usize</h4></section></div></details></div><script src="../trait.impl/hexasphere/trait.BaseShape.js" async></script></section></div></main></body></html>