You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Trac3r-rust/doc/cgmath/trait.EuclideanSpace.html

86 lines
26 KiB

5 years ago
<!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="API documentation for the Rust `EuclideanSpace` trait in crate `cgmath`."><meta name="keywords" content="rust, rustlang, rust-lang, EuclideanSpace"><title>cgmath::EuclideanSpace - Rust</title><link rel="stylesheet" type="text/css" href="../normalize.css"><link rel="stylesheet" type="text/css" href="../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" type="text/css" href="../dark.css"><link rel="stylesheet" type="text/css" href="../light.css" id="themeStyle"><script src="../storage.js"></script><noscript><link rel="stylesheet" href="../noscript.css"></noscript><link rel="shortcut icon" href="../favicon.ico"><style type="text/css">#crate-search{background-image:url("../down-arrow.svg");}</style></head><body class="rustdoc trait"><!--[if lte IE 8]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"><div class="sidebar-menu">&#9776;</div><a href='../cgmath/index.html'><div class='logo-container'><img src='../rust-logo.png' alt='logo'></div></a><p class='location'>Trait EuclideanSpace</p><div class="sidebar-elems"><div class="block items"><a class="sidebar-title" href="#associated-types">Associated Types</a><div class="sidebar-links"><a href="#associatedtype.Scalar">Scalar</a><a href="#associatedtype.Diff">Diff</a></div><a class="sidebar-title" href="#required-methods">Required Methods</a><div class="sidebar-links"><a href="#tymethod.dot">dot</a><a href="#tymethod.from_vec">from_vec</a><a href="#tymethod.origin">origin</a><a href="#tymethod.to_vec">to_vec</a></div><a class="sidebar-title" href="#provided-methods">Provided Methods</a><div class="sidebar-links"><a href="#method.centroid">centroid</a><a href="#method.midpoint">midpoint</a></div><a class="sidebar-title" href="#implementors">Implementors</a></div><p class='location'><a href='index.html'>cgmath</a></p><script>window.sidebarCurrent = {name: 'EuclideanSpace', ty: 'trait', relpath: ''};</script><script defer src="sidebar-items.js"></script></div></nav><div class="theme-picker"><button id="theme-picker" aria-label="Pick another theme!"><img src="../brush.svg" width="18" alt="Pick another theme!"></button><div id="theme-choices"></div></div><script src="../theme.js"></script><nav class="sub"><form class="search-form js-only"><div class="search-container"><div><select id="crate-search"><option value="All crates">All crates</option></select><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press S to search, ? for more options…" type="search"></div><a id="settings-menu" href="../settings.html"><img src="../wheel.svg" width="18" alt="Change settings"></a></div></form></nav><section id="main" class="content"><h1 class='fqn'><span class='out-of-band'><span id='render-detail'><a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class='inner'>&#x2212;</span>]</a></span><a class='srclink' href='../src/cgmath/structure.rs.html#327-405' title='goto source code'>[src]</a></span><span class='in-band'>Trait <a href='index.html'>cgmath</a>::<wbr><a class="trait" href=''>EuclideanSpace</a></span></h1><div class="docblock type-decl hidden-by-usual-hider"><pre class='rust trait'>pub trait EuclideanSpace: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Copy.html" title="trait core::marker::Copy">Copy</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a> <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;Self: <a class="trait" href="../cgmath/prelude/trait.Array.html" title="trait cgmath::prelude::Array">Array</a>&lt;Element = Self::<a class="type" href="../cgmath/prelude/trait.EuclideanSpace.html#associatedtype.Scalar" title="type cgmath::prelude::EuclideanSpace::Scalar">Scalar</a>&gt;
type <a href='#associatedtype.Scalar' class="type">Scalar</a>: <a class="trait" href="../cgmath/trait.BaseNum.html" title="trait cgmath::BaseNum">BaseNum</a>;
type <a href='#associatedtype.Diff' class="type">Diff</a>: <a class="trait" href="../cgmath/prelude/trait.VectorSpace.html" title="trait cgmath::prelude::VectorSpace">VectorSpace</a>&lt;Scalar = Self::<a class="type" href="../cgmath/prelude/trait.EuclideanSpace.html#associatedtype.Scalar" title="type cgmath::prelude::EuclideanSpace::Scalar">Scalar</a>&gt;;
fn <a href='#tymethod.origin' class='fnname'>origin</a>() -&gt; Self;
<div class='item-spacer'></div> fn <a href='#tymethod.from_vec' class='fnname'>from_vec</a>(v: Self::<a class="type" href="../cgmath/prelude/trait.EuclideanSpace.html#associatedtype.Diff" title="type cgmath::prelude::EuclideanSpace::Diff">Diff</a>) -&gt; Self;
<div class='item-spacer'></div> fn <a href='#tymethod.to_vec' class='fnname'>to_vec</a>(self) -&gt; Self::<a class="type" href="../cgmath/prelude/trait.EuclideanSpace.html#associatedtype.Diff" title="type cgmath::prelude::EuclideanSpace::Diff">Diff</a>;
<div class='item-spacer'></div> fn <a href='#tymethod.dot' class='fnname'>dot</a>(self, v: Self::<a class="type" href="../cgmath/prelude/trait.EuclideanSpace.html#associatedtype.Diff" title="type cgmath::prelude::EuclideanSpace::Diff">Diff</a>) -&gt; Self::<a class="type" href="../cgmath/prelude/trait.EuclideanSpace.html#associatedtype.Scalar" title="type cgmath::prelude::EuclideanSpace::Scalar">Scalar</a>;
fn <a href='#method.midpoint' class='fnname'>midpoint</a>(self, other: Self) -&gt; Self { ... }
<div class='item-spacer'></div> fn <a href='#method.centroid' class='fnname'>centroid</a>(points: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&amp;[Self]</a>) -&gt; Self { ... }
}</pre></div><div class='docblock'><p>Points in a <a href="https://en.wikipedia.org/wiki/Euclidean_space">Euclidean space</a>
with an associated space of displacement vectors.</p>
<h1 id="point-vector-distinction" class="section-header"><a href="#point-vector-distinction">Point-Vector distinction</a></h1>
<p><code>cgmath</code> distinguishes between points and vectors in the following way:</p>
<ul>
<li>Points are <em>locations</em> relative to an origin</li>
<li>Vectors are <em>displacements</em> between those points</li>
</ul>
<p>For example, to find the midpoint between two points, you can write the
following:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">cgmath</span>::<span class="ident">Point3</span>;
<span class="kw">let</span> <span class="ident">p0</span> <span class="op">=</span> <span class="ident">Point3</span>::<span class="ident">new</span>(<span class="number">1.0</span>, <span class="number">2.0</span>, <span class="number">3.0</span>);
<span class="kw">let</span> <span class="ident">p1</span> <span class="op">=</span> <span class="ident">Point3</span>::<span class="ident">new</span>(<span class="op">-</span><span class="number">3.0</span>, <span class="number">1.0</span>, <span class="number">2.0</span>);
<span class="kw">let</span> <span class="ident">midpoint</span>: <span class="ident">Point3</span><span class="op">&lt;</span><span class="ident">f32</span><span class="op">&gt;</span> <span class="op">=</span> <span class="ident">p0</span> <span class="op">+</span> (<span class="ident">p1</span> <span class="op">-</span> <span class="ident">p0</span>) <span class="op">*</span> <span class="number">0.5</span>;</pre></div>
<p>Breaking the expression up, and adding explicit types makes it clearer
to see what is going on:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">let</span> <span class="ident">dv</span>: <span class="ident">Vector3</span><span class="op">&lt;</span><span class="ident">f32</span><span class="op">&gt;</span> <span class="op">=</span> <span class="ident">p1</span> <span class="op">-</span> <span class="ident">p0</span>;
<span class="kw">let</span> <span class="ident">half_dv</span>: <span class="ident">Vector3</span><span class="op">&lt;</span><span class="ident">f32</span><span class="op">&gt;</span> <span class="op">=</span> <span class="ident">dv</span> <span class="op">*</span> <span class="number">0.5</span>;
<span class="kw">let</span> <span class="ident">midpoint</span>: <span class="ident">Point3</span><span class="op">&lt;</span><span class="ident">f32</span><span class="op">&gt;</span> <span class="op">=</span> <span class="ident">p0</span> <span class="op">+</span> <span class="ident">half_dv</span>;</pre></div>
<h2 id="converting-between-points-and-vectors" class="section-header"><a href="#converting-between-points-and-vectors">Converting between points and vectors</a></h2>
<p>Points can be converted to and from displacement vectors using the
<code>EuclideanSpace::{from_vec, to_vec}</code> methods. Note that under the hood these
are implemented as inlined a type conversion, so should not have any
performance implications.</p>
<h2 id="references" class="section-header"><a href="#references">References</a></h2>
<ul>
<li><a href="http://doc.cgal.org/latest/Kernel_23/index.html#Kernel_23PointsandVectors">CGAL 4.7 - 2D and 3D Linear Geometry Kernel: 3.1 Points and Vectors</a></li>
<li><a href="http://math.stackexchange.com/q/645827">What is the difference between a point and a vector</a></li>
</ul>
</div>
<h2 id='associated-types' class='small-section-header'>Associated Types<a href='#associated-types' class='anchor'></a></h2><div class='methods'><h3 id='associatedtype.Scalar' class='method'><code id='Scalar.t'>type <a href='#associatedtype.Scalar' class="type">Scalar</a>: <a class="trait" href="../cgmath/trait.BaseNum.html" title="trait cgmath::BaseNum">BaseNum</a></code></h3><div class='docblock'><p>The associated scalar over which the space is defined.</p>
<p>Due to the equality constraints demanded by <code>Self::Diff</code>, this is effectively just an
alias to <code>Self::Diff::Scalar</code>.</p>
</div><h3 id='associatedtype.Diff' class='method'><code id='Diff.t'>type <a href='#associatedtype.Diff' class="type">Diff</a>: <a class="trait" href="../cgmath/prelude/trait.VectorSpace.html" title="trait cgmath::prelude::VectorSpace">VectorSpace</a>&lt;Scalar = Self::<a class="type" href="../cgmath/prelude/trait.EuclideanSpace.html#associatedtype.Scalar" title="type cgmath::prelude::EuclideanSpace::Scalar">Scalar</a>&gt;</code></h3><div class='docblock'><p>The associated space of displacement vectors.</p>
</div></div><span class='loading-content'>Loading content...</span>
<h2 id='required-methods' class='small-section-header'>Required methods<a href='#required-methods' class='anchor'></a></h2><div class='methods'><h3 id='tymethod.origin' class='method'><code id='origin.v'>fn <a href='#tymethod.origin' class='fnname'>origin</a>() -&gt; Self</code></h3><div class='docblock'><p>The point at the origin of the Euclidean space.</p>
</div><h3 id='tymethod.from_vec' class='method'><code id='from_vec.v'>fn <a href='#tymethod.from_vec' class='fnname'>from_vec</a>(v: Self::<a class="type" href="../cgmath/prelude/trait.EuclideanSpace.html#associatedtype.Diff" title="type cgmath::prelude::EuclideanSpace::Diff">Diff</a>) -&gt; Self</code></h3><div class='docblock'><p>Convert a displacement vector to a point.</p>
<p>This can be considered equivalent to the addition of the displacement
vector <code>v</code> to to <code>Self::origin()</code>.</p>
</div><h3 id='tymethod.to_vec' class='method'><code id='to_vec.v'>fn <a href='#tymethod.to_vec' class='fnname'>to_vec</a>(self) -&gt; Self::<a class="type" href="../cgmath/prelude/trait.EuclideanSpace.html#associatedtype.Diff" title="type cgmath::prelude::EuclideanSpace::Diff">Diff</a></code></h3><div class='docblock'><p>Convert a point to a displacement vector.</p>
<p>This can be seen as equivalent to the displacement vector from
<code>Self::origin()</code> to <code>self</code>.</p>
</div><h3 id='tymethod.dot' class='method'><code id='dot.v'>fn <a href='#tymethod.dot' class='fnname'>dot</a>(self, v: Self::<a class="type" href="../cgmath/prelude/trait.EuclideanSpace.html#associatedtype.Diff" title="type cgmath::prelude::EuclideanSpace::Diff">Diff</a>) -&gt; Self::<a class="type" href="../cgmath/prelude/trait.EuclideanSpace.html#associatedtype.Scalar" title="type cgmath::prelude::EuclideanSpace::Scalar">Scalar</a></code></h3><div class='docblock'><p>This is a weird one, but its useful for plane calculations.</p>
</div></div><span class='loading-content'>Loading content...</span>
<h2 id='provided-methods' class='small-section-header'>Provided methods<a href='#provided-methods' class='anchor'></a></h2><div class='methods'><h3 id='method.midpoint' class='method'><code id='midpoint.v'>fn <a href='#method.midpoint' class='fnname'>midpoint</a>(self, other: Self) -&gt; Self</code></h3><div class='docblock'><p>Returns the middle point between two other points.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">cgmath</span>::<span class="ident">prelude</span>::<span class="kw-2">*</span>;
<span class="kw">use</span> <span class="ident">cgmath</span>::<span class="ident">Point3</span>;
<span class="kw">let</span> <span class="ident">p</span> <span class="op">=</span> <span class="ident">Point3</span>::<span class="ident">midpoint</span>(
<span class="ident">Point3</span>::<span class="ident">new</span>(<span class="number">1.0</span>, <span class="number">2.0</span>, <span class="number">3.0</span>),
<span class="ident">Point3</span>::<span class="ident">new</span>(<span class="number">3.0</span>, <span class="number">1.0</span>, <span class="number">2.0</span>),
);</pre></div>
</div><h3 id='method.centroid' class='method'><code id='centroid.v'>fn <a href='#method.centroid' class='fnname'>centroid</a>(points: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&amp;[Self]</a>) -&gt; Self</code></h3><div class='docblock'><p>Returns the average position of all points in the slice.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">cgmath</span>::<span class="ident">prelude</span>::<span class="kw-2">*</span>;
<span class="kw">use</span> <span class="ident">cgmath</span>::<span class="ident">Point2</span>;
<span class="kw">let</span> <span class="ident">triangle</span> <span class="op">=</span> [
<span class="ident">Point2</span>::<span class="ident">new</span>(<span class="number">1.0</span>, <span class="number">1.0</span>),
<span class="ident">Point2</span>::<span class="ident">new</span>(<span class="number">2.0</span>, <span class="number">3.0</span>),
<span class="ident">Point2</span>::<span class="ident">new</span>(<span class="number">3.0</span>, <span class="number">1.0</span>),
];
<span class="kw">let</span> <span class="ident">centroid</span> <span class="op">=</span> <span class="ident">Point2</span>::<span class="ident">centroid</span>(<span class="kw-2">&amp;</span><span class="ident">triangle</span>);</pre></div>
</div></div><span class='loading-content'>Loading content...</span>
<h2 id='implementors' class='small-section-header'>Implementors<a href='#implementors' class='anchor'></a></h2><div class='item-list' id='implementors-list'><h3 id='impl-EuclideanSpace' class='impl'><code class='in-band'>impl&lt;S:&nbsp;<a class="trait" href="../cgmath/trait.BaseNum.html" title="trait cgmath::BaseNum">BaseNum</a>&gt; EuclideanSpace for <a class="struct" href="../cgmath/struct.Point1.html" title="struct cgmath::Point1">Point1</a>&lt;S&gt;</code><a href='#impl-EuclideanSpace' class='anchor'></a><a class='srclink' href='../src/cgmath/point.rs.html#150-173' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='associatedtype.Scalar-1' class="type"><code id='Scalar.t-1'>type <a href='#associatedtype.Scalar-1' class="type">Scalar</a> = S</code></h4><h4 id='associatedtype.Diff-1' class="type"><code id='Diff.t-1'>type <a href='#associatedtype.Diff-1' class="type">Diff</a> = <a class="struct" href="../cgmath/struct.Vector1.html" title="struct cgmath::Vector1">Vector1</a>&lt;S&gt;</code></h4><h4 id='method.origin' class="method hidden"><code id='origin.v-1'>fn <a href='#method.origin' class='fnname'>origin</a>() -&gt; <a class="struct" href="../cgmath/struct.Point1.html" title="struct cgmath::Point1">Point1</a>&lt;S&gt;</code><a class='srclink' href='../src/cgmath/point.rs.html#155-157' title='goto source code'>[src]</a></h4><h4 id='method.from_vec' class="method hidden"><code id='from_vec.v-1'>fn <a href='#method.from_vec' class='fnname'>from_vec</a>(v: <a class="struct" href="../cgmath/struct.Vector1.html" title="struct cgmath::Vector1">Vector1</a>&lt;S&gt;) -&gt; <a class="struct" href="../cgmath/struct.Point1.html" title="struct cgmath::Point1">Point1</a>&lt;S&gt;</code><a class='srclink' href='../src/cgmath/point.rs.html#160-162' title='goto source code'>[src]</a></h4><h4 id='method.to_vec' class="method hidden"><code id='to_vec.v-1'>fn <a href='#method.to_vec' class='fnname'>to_vec</a>(self) -&gt; <a class="struct" href="../cgmath/struct.Vector1.html" title="struct cgmath::Vector1">Vector1</a>&lt;S&gt;</code><a class='srclink' href='../src/cgmath/point.rs.html#165-167' title='goto source code'>[src]</a></h4><h4 id='method.dot' class="method hidden"><code id='dot.v-1'>fn <a href='#method.dot' class='fnname'>dot</a>(self, v: <a class="struct" href="../cgmath/struct.Vector1.html" title="struct cgmath::Vector1">Vector1</a>&lt;S&gt;) -&gt; S</code><a class='srclink' href='../src/cgmath/point.rs.html#170-172' title='goto source code'>[src]</a></h4></div><h3 id='impl-EuclideanSpace-1' class='impl'><code class='in-band'>impl&lt;S:&nbsp;<a class="trait" href="../cgmath/trait.BaseNum.html" title="trait cgmath::BaseNum">BaseNum</a>&gt; EuclideanSpace for <a class="struct" href="../cgmath/struct.Point2.html" title="struct cgmath::Point2">Point2</a>&lt;S&gt;</code><a href='#impl-EuclideanSpace-1' class='anchor'></a><a class='srclink' href='../src/cgmath/point.rs.html#150-173' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='associatedtype.Scalar-2' class="type"><code id='Scalar.t-2'>type <a href='#associatedtype.Scalar-2' class="type">Scalar</a> = S</code></h4><h4 id='associatedtype.Diff-2' class="type"><code id='Diff.t-2'>type <a href='#associatedtype.Diff-2' class="type">Diff</a> = <a class="struct" href="../cgmath/struct.Vector2.html" title="struct cgmath::Vector2">Vector2</a>&lt;S&gt;</code></h4><h4 id='method.origin-1' class="method hidden"><code id='origin.v-2'>fn <a href='#method.origin-1' class='fnname'>origin</a>() -&gt; <a class="struct" href="../cgmath/struct.Point2.html" title="struct cgmath::Point2">Point2</a>&lt;S&gt;</code><a class='srclink' href='../src/cgmath/point.rs.html#155-157' title='goto source code'>[src]</a></h4><h4 id='method.from_vec-1' class="method hidden"><code id='from_vec.v-2'>fn <a href='#method.from_vec-1' class='fnname'>from_vec</a>(v: <a class="struct" href="../cgmath/struct.Vector2.html" title="struct cgmath::Vector2">Vector2</a>&lt;S&gt;) -&gt; <a class="struct" href="../cgmath/struct.Point2.html" title="struct cgmath::Point2">Point
src="../implementors/cgmath/trait.EuclideanSpace.js">
</script></section><section id="search" class="content hidden"></section><section class="footer"></section><aside id="help" class="hidden"><div><h1 class="hidden">Help</h1><div class="shortcuts"><h2>Keyboard Shortcuts</h2><dl><dt><kbd>?</kbd></dt><dd>Show this help dialog</dd><dt><kbd>S</kbd></dt><dd>Focus the search field</dd><dt><kbd></kbd></dt><dd>Move up in search results</dd><dt><kbd></kbd></dt><dd>Move down in search results</dd><dt><kbd></kbd></dt><dd>Switch tab</dd><dt><kbd>&#9166;</kbd></dt><dd>Go to active search result</dd><dt><kbd>+</kbd></dt><dd>Expand all sections</dd><dt><kbd>-</kbd></dt><dd>Collapse all sections</dd></dl></div><div class="infos"><h2>Search Tricks</h2><p>Prefix searches with a type followed by a colon (e.g., <code>fn:</code>) to restrict the search to a given type.</p><p>Accepted types are: <code>fn</code>, <code>mod</code>, <code>struct</code>, <code>enum</code>, <code>trait</code>, <code>type</code>, <code>macro</code>, and <code>const</code>.</p><p>Search functions by type signature (e.g., <code>vec -> usize</code> or <code>* -> vec</code>)</p><p>Search multiple things at once by splitting your query with comma (e.g., <code>str,u8</code> or <code>String,struct:Vec,test</code>)</p></div></div></aside><script>window.rootPath = "../";window.currentCrate = "cgmath";</script><script src="../aliases.js"></script><script src="../main.js"></script><script defer src="../search-index.js"></script></body></html>