78 lines
18 KiB
HTML
78 lines
18 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="An object that can be inserted into an r-tree."><title>RTreeObject in rstar - 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="rstar" 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="../rstar/index.html">rstar</a><span class="version">0.12.0</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">RTree<wbr>Object</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#type-parameters" title="Type parameters">Type parameters</a></li><li><a href="#example-implementation" title="Example implementation">Example implementation</a></li></ul><h3><a href="#required-associated-types">Required Associated Types</a></h3><ul class="block"><li><a href="#associatedtype.Envelope" title="Envelope">Envelope</a></li></ul><h3><a href="#required-methods">Required Methods</a></h3><ul class="block"><li><a href="#tymethod.envelope" title="envelope">envelope</a></li></ul><h3><a href="#implementors">Implementors</a></h3></section><div id="rustdoc-modnav"><h2 class="in-crate"><a href="index.html">In crate rstar</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">rstar</a></span><h1>Trait <span class="trait">RTreeObject</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/rstar/object.rs.html#76-85">Source</a> </span></div><pre class="rust item-decl"><code>pub trait RTreeObject {
|
||
type <a href="#associatedtype.Envelope" class="associatedtype">Envelope</a>: <a class="trait" href="trait.Envelope.html" title="trait rstar::Envelope">Envelope</a>;
|
||
|
||
// Required method
|
||
fn <a href="#tymethod.envelope" class="fn">envelope</a>(&self) -> Self::<a class="associatedtype" href="trait.RTreeObject.html#associatedtype.Envelope" title="type rstar::RTreeObject::Envelope">Envelope</a>;
|
||
}</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>An object that can be inserted into an r-tree.</p>
|
||
<p>This trait must be implemented for any object to be inserted into an r-tree.
|
||
Some simple objects that already implement this trait can be found in the
|
||
<a href="primitives/index.html" title="mod rstar::primitives">crate::primitives</a> module.</p>
|
||
<p>The only property required of such an object is its <a href="trait.Envelope.html" title="trait rstar::Envelope">crate::Envelope</a>.
|
||
Most simply, this method should return the <a href="struct.AABB.html" title="struct rstar::AABB">axis aligned bounding box</a>
|
||
of the object. Other envelope types may be supported in the future.</p>
|
||
<p><em>Note</em>: It is a logic error if an object’s envelope changes after insertion into
|
||
an r-tree.</p>
|
||
<h2 id="type-parameters"><a class="doc-anchor" href="#type-parameters">§</a>Type parameters</h2>
|
||
<p><code>Envelope</code>: The object’s envelope type. At the moment, only <a href="struct.AABB.html" title="struct rstar::AABB">AABB</a> is
|
||
available.</p>
|
||
<h2 id="example-implementation"><a class="doc-anchor" href="#example-implementation">§</a>Example implementation</h2>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>rstar::{RTreeObject, AABB};
|
||
|
||
<span class="kw">struct </span>Player
|
||
{
|
||
name: String,
|
||
x_coordinate: f64,
|
||
y_coordinate: f64
|
||
}
|
||
|
||
<span class="kw">impl </span>RTreeObject <span class="kw">for </span>Player
|
||
{
|
||
<span class="kw">type </span>Envelope = AABB<[f64; <span class="number">2</span>]>;
|
||
|
||
<span class="kw">fn </span>envelope(<span class="kw-2">&</span><span class="self">self</span>) -> <span class="self">Self</span>::Envelope
|
||
{
|
||
AABB::from_point([<span class="self">self</span>.x_coordinate, <span class="self">self</span>.y_coordinate])
|
||
}
|
||
}
|
||
|
||
<span class="kw">use </span>rstar::RTree;
|
||
|
||
<span class="kw">let </span><span class="kw-2">mut </span>tree = RTree::new();
|
||
|
||
<span class="comment">// Insert a few players...
|
||
</span>tree.insert(Player {
|
||
name: <span class="string">"Forlorn Freeman"</span>.into(),
|
||
x_coordinate: <span class="number">1.</span>,
|
||
y_coordinate: <span class="number">0.
|
||
</span>});
|
||
tree.insert(Player {
|
||
name: <span class="string">"Sarah Croft"</span>.into(),
|
||
x_coordinate: <span class="number">0.5</span>,
|
||
y_coordinate: <span class="number">0.5</span>,
|
||
});
|
||
tree.insert(Player {
|
||
name: <span class="string">"Geralt of Trivia"</span>.into(),
|
||
x_coordinate: <span class="number">0.</span>,
|
||
y_coordinate: <span class="number">2.</span>,
|
||
});
|
||
|
||
<span class="comment">// Now we are ready to ask some questions!
|
||
</span><span class="kw">let </span>envelope = AABB::from_point([<span class="number">0.5</span>, <span class="number">0.5</span>]);
|
||
<span class="kw">let </span>likely_sarah_croft = tree.locate_in_envelope(<span class="kw-2">&</span>envelope).next();
|
||
<span class="macro">println!</span>(<span class="string">"Found {:?} lurking around at (0.5, 0.5)!"</span>, likely_sarah_croft.unwrap().name);
|
||
|
||
<span class="kw">let </span>unit_square = AABB::from_corners([-<span class="number">1.0</span>, -<span class="number">1.0</span>], [<span class="number">1.</span>, <span class="number">1.</span>]);
|
||
<span class="kw">for </span>player <span class="kw">in </span>tree.locate_in_envelope(<span class="kw-2">&</span>unit_square) {
|
||
<span class="macro">println!</span>(<span class="string">"And here is {:?} spelunking in the unit square."</span>, player.name);
|
||
}</code></pre></div>
|
||
</div></details><h2 id="required-associated-types" class="section-header">Required Associated Types<a href="#required-associated-types" class="anchor">§</a></h2><div class="methods"><details class="toggle" open><summary><section id="associatedtype.Envelope" class="method"><a class="src rightside" href="../src/rstar/object.rs.html#79">Source</a><h4 class="code-header">type <a href="#associatedtype.Envelope" class="associatedtype">Envelope</a>: <a class="trait" href="trait.Envelope.html" title="trait rstar::Envelope">Envelope</a></h4></section></summary><div class="docblock"><p>The object’s envelope type. Usually, <a href="struct.AABB.html" title="struct rstar::AABB">AABB</a> will be the right choice.
|
||
This type also defines the object’s dimensionality.</p>
|
||
</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.envelope" class="method"><a class="src rightside" href="../src/rstar/object.rs.html#84">Source</a><h4 class="code-header">fn <a href="#tymethod.envelope" class="fn">envelope</a>(&self) -> Self::<a class="associatedtype" href="trait.RTreeObject.html#associatedtype.Envelope" title="type rstar::RTreeObject::Envelope">Envelope</a></h4></section></summary><div class="docblock"><p>Returns the object’s envelope.</p>
|
||
<p>Usually, this will return the object’s <a href="struct.AABB.html" title="struct rstar::AABB">axis aligned bounding box</a>.</p>
|
||
</div></details></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-RTreeObject-for-Line%3CP%3E" class="impl"><a class="src rightside" href="../src/rstar/primitives/line.rs.html#47-56">Source</a><a href="#impl-RTreeObject-for-Line%3CP%3E" class="anchor">§</a><h3 class="code-header">impl<P> <a class="trait" href="trait.RTreeObject.html" title="trait rstar::RTreeObject">RTreeObject</a> for <a class="struct" href="primitives/struct.Line.html" title="struct rstar::primitives::Line">Line</a><P><div class="where">where
|
||
P: <a class="trait" href="trait.Point.html" title="trait rstar::Point">Point</a>,</div></h3></section></summary><div class="impl-items"><section id="associatedtype.Envelope-1" class="associatedtype trait-impl"><a class="src rightside" href="../src/rstar/primitives/line.rs.html#51">Source</a><a href="#associatedtype.Envelope-1" class="anchor">§</a><h4 class="code-header">type <a href="#associatedtype.Envelope" class="associatedtype">Envelope</a> = <a class="struct" href="struct.AABB.html" title="struct rstar::AABB">AABB</a><P></h4></section></div></details><details class="toggle implementors-toggle"><summary><section id="impl-RTreeObject-for-Rectangle%3CP%3E" class="impl"><a class="src rightside" href="../src/rstar/primitives/rectangle.rs.html#64-73">Source</a><a href="#impl-RTreeObject-for-Rectangle%3CP%3E" class="anchor">§</a><h3 class="code-header">impl<P> <a class="trait" href="trait.RTreeObject.html" title="trait rstar::RTreeObject">RTreeObject</a> for <a class="struct" href="primitives/struct.Rectangle.html" title="struct rstar::primitives::Rectangle">Rectangle</a><P><div class="where">where
|
||
P: <a class="trait" href="trait.Point.html" title="trait rstar::Point">Point</a>,</div></h3></section></summary><div class="impl-items"><section id="associatedtype.Envelope-2" class="associatedtype trait-impl"><a class="src rightside" href="../src/rstar/primitives/rectangle.rs.html#68">Source</a><a href="#associatedtype.Envelope-2" class="anchor">§</a><h4 class="code-header">type <a href="#associatedtype.Envelope" class="associatedtype">Envelope</a> = <a class="struct" href="struct.AABB.html" title="struct rstar::AABB">AABB</a><P></h4></section></div></details><details class="toggle implementors-toggle"><summary><section id="impl-RTreeObject-for-P" class="impl"><a class="src rightside" href="../src/rstar/object.rs.html#198-207">Source</a><a href="#impl-RTreeObject-for-P" class="anchor">§</a><h3 class="code-header">impl<P> <a class="trait" href="trait.RTreeObject.html" title="trait rstar::RTreeObject">RTreeObject</a> for P<div class="where">where
|
||
P: <a class="trait" href="trait.Point.html" title="trait rstar::Point">Point</a>,</div></h3></section></summary><div class="impl-items"><section id="associatedtype.Envelope-3" class="associatedtype trait-impl"><a class="src rightside" href="../src/rstar/object.rs.html#202">Source</a><a href="#associatedtype.Envelope-3" class="anchor">§</a><h4 class="code-header">type <a href="#associatedtype.Envelope" class="associatedtype">Envelope</a> = <a class="struct" href="struct.AABB.html" title="struct rstar::AABB">AABB</a><P></h4></section></div></details><details class="toggle implementors-toggle"><summary><section id="impl-RTreeObject-for-GeomWithData%3CR,+T%3E" class="impl"><a class="src rightside" href="../src/rstar/primitives/geom_with_data.rs.html#40-46">Source</a><a href="#impl-RTreeObject-for-GeomWithData%3CR,+T%3E" class="anchor">§</a><h3 class="code-header">impl<R: <a class="trait" href="trait.RTreeObject.html" title="trait rstar::RTreeObject">RTreeObject</a>, T> <a class="trait" href="trait.RTreeObject.html" title="trait rstar::RTreeObject">RTreeObject</a> for <a class="struct" href="primitives/struct.GeomWithData.html" title="struct rstar::primitives::GeomWithData">GeomWithData</a><R, T></h3></section></summary><div class="impl-items"><section id="associatedtype.Envelope-4" class="associatedtype trait-impl"><a class="src rightside" href="../src/rstar/primitives/geom_with_data.rs.html#41">Source</a><a href="#associatedtype.Envelope-4" class="anchor">§</a><h4 class="code-header">type <a href="#associatedtype.Envelope" class="associatedtype">Envelope</a> = <R as <a class="trait" href="trait.RTreeObject.html" title="trait rstar::RTreeObject">RTreeObject</a>>::<a class="associatedtype" href="trait.RTreeObject.html#associatedtype.Envelope" title="type rstar::RTreeObject::Envelope">Envelope</a></h4></section></div></details><details class="toggle implementors-toggle"><summary><section id="impl-RTreeObject-for-RTreeNode%3CT%3E" class="impl"><a class="src rightside" href="../src/rstar/node.rs.html#47-59">Source</a><a href="#impl-RTreeObject-for-RTreeNode%3CT%3E" class="anchor">§</a><h3 class="code-header">impl<T> <a class="trait" href="trait.RTreeObject.html" title="trait rstar::RTreeObject">RTreeObject</a> for <a class="enum" href="enum.RTreeNode.html" title="enum rstar::RTreeNode">RTreeNode</a><T><div class="where">where
|
||
T: <a class="trait" href="trait.RTreeObject.html" title="trait rstar::RTreeObject">RTreeObject</a>,</div></h3></section></summary><div class="impl-items"><section id="associatedtype.Envelope-5" class="associatedtype trait-impl"><a class="src rightside" href="../src/rstar/node.rs.html#51">Source</a><a href="#associatedtype.Envelope-5" class="anchor">§</a><h4 class="code-header">type <a href="#associatedtype.Envelope" class="associatedtype">Envelope</a> = <T as <a class="trait" href="trait.RTreeObject.html" title="trait rstar::RTreeObject">RTreeObject</a>>::<a class="associatedtype" href="trait.RTreeObject.html#associatedtype.Envelope" title="type rstar::RTreeObject::Envelope">Envelope</a></h4></section></div></details><details class="toggle implementors-toggle"><summary><section id="impl-RTreeObject-for-PointWithData%3CT,+P%3E" class="impl"><a class="src rightside" href="../src/rstar/primitives/point_with_data.rs.html#50-59">Source</a><a href="#impl-RTreeObject-for-PointWithData%3CT,+P%3E" class="anchor">§</a><h3 class="code-header">impl<T, P> <a class="trait" href="trait.RTreeObject.html" title="trait rstar::RTreeObject">RTreeObject</a> for <a class="struct" href="primitives/struct.PointWithData.html" title="struct rstar::primitives::PointWithData">PointWithData</a><T, P><div class="where">where
|
||
P: <a class="trait" href="trait.Point.html" title="trait rstar::Point">Point</a>,</div></h3></section></summary><div class="impl-items"><section id="associatedtype.Envelope-6" class="associatedtype trait-impl"><a class="src rightside" href="../src/rstar/primitives/point_with_data.rs.html#54">Source</a><a href="#associatedtype.Envelope-6" class="anchor">§</a><h4 class="code-header">type <a href="#associatedtype.Envelope" class="associatedtype">Envelope</a> = <a class="struct" href="struct.AABB.html" title="struct rstar::AABB">AABB</a><P></h4></section></div></details><details class="toggle implementors-toggle"><summary><section id="impl-RTreeObject-for-CachedEnvelope%3CT%3E" class="impl"><a class="src rightside" href="../src/rstar/primitives/cached_envelope.rs.html#21-30">Source</a><a href="#impl-RTreeObject-for-CachedEnvelope%3CT%3E" class="anchor">§</a><h3 class="code-header">impl<T: <a class="trait" href="trait.RTreeObject.html" title="trait rstar::RTreeObject">RTreeObject</a>> <a class="trait" href="trait.RTreeObject.html" title="trait rstar::RTreeObject">RTreeObject</a> for <a class="struct" href="primitives/struct.CachedEnvelope.html" title="struct rstar::primitives::CachedEnvelope">CachedEnvelope</a><T><div class="where">where
|
||
T::<a class="associatedtype" href="trait.RTreeObject.html#associatedtype.Envelope" title="type rstar::RTreeObject::Envelope">Envelope</a>: <a class="trait" href="https://doc.rust-lang.org/1.84.0/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>,</div></h3></section></summary><div class="impl-items"><section id="associatedtype.Envelope-7" class="associatedtype trait-impl"><a class="src rightside" href="../src/rstar/primitives/cached_envelope.rs.html#25">Source</a><a href="#associatedtype.Envelope-7" class="anchor">§</a><h4 class="code-header">type <a href="#associatedtype.Envelope" class="associatedtype">Envelope</a> = <T as <a class="trait" href="trait.RTreeObject.html" title="trait rstar::RTreeObject">RTreeObject</a>>::<a class="associatedtype" href="trait.RTreeObject.html#associatedtype.Envelope" title="type rstar::RTreeObject::Envelope">Envelope</a></h4></section></div></details></div><script src="../trait.impl/rstar/object/trait.RTreeObject.js" async></script></section></div></main></body></html> |