Skip to main content

RangeId

Struct RangeId 

Source
pub struct RangeId { /* private fields */ }
Expand description

RangeIdは空間IDの範囲表現を表す型です。

各インデックスを範囲で指定することができます。各次元の範囲を表す配列の順序には意味を持ちません。内部的には下記のような構造体で構成されており、各フィールドをプライベートにすることで、ズームレベルに依存するインデックス範囲やその他のバリデーションを適切に適用することができます。

この型は PartialOrd / Ord を実装していますが、これは主にBTreeSetBTreeMap などの順序付きコレクションでの格納・探索用です。実際の空間的な「大小」を意味するものではありません。

pub struct RangeId {
    z: u8,
    f: [i32; 2],
    x: [u32; 2],
    y: [u32; 2],
}

Implementations§

Source§

impl RangeId

Source

pub fn new( z: u8, f: [i32; 2], x: [u32; 2], y: [u32; 2], ) -> Result<RangeId, Error>

指定された値から RangeId を構築します。 与えられた z, f1, f2, x1, x2, y1, y2 が 各ズームレベルにおける範囲内にあるかを検証し、範囲外の場合は Error を返します。

 各次元の与えられた2つの値は自動的に昇順に並び替えられ、 常に [min, max] の形で内部に保持されます。

§パラメータ
  • z — ズームレベル(0–63の範囲が有効)
  • f1 — 鉛直方向範囲の端のFインデックス
  • f2 — 鉛直方向範囲の端のFインデックス
  • x1 — 東西方向範囲の端のXインデックス
  • x2 — 東西方向範囲の端のXインデックス
  • y1 — 南北方向範囲の端のYインデックス
  • y2 — 南北方向範囲の端のYインデックス
§バリデーション

IDの作成:

let id = RangeId::new(4, [-3,6], [8,9], [5,10]).unwrap();
let s = format!("{}", id);
assert_eq!(s, "4/-3:6/8:9/5:10");

次元の範囲外の検知:

let id = RangeId::new(4, [-3,29], [8,9], [5,10]);
assert_eq!(id, Err(SpatialIdError::FOutOfRange{z:4,f:29}.into()));

ズームレベルの範囲外の検知:

let id = RangeId::new(68, [-3,29], [8,9], [5,10]);
assert_eq!(id, Err(SpatialIdError::ZOutOfRange { z:68 }.into()));
Source

pub unsafe fn new_unchecked( z: u8, f: [i32; 2], x: [u32; 2], y: [u32; 2], ) -> RangeId

検証を行わずに RangeId を構築します。

この関数は RangeId::new と異なり、与えられた z, f1, f2, x1,x2, y1, y2` に対して 一切の範囲チェックや整合性チェックを行いません。 そのため、高速に ID を生成できますが、不正なパラメータを与えた場合の動作は未定義です

§注意

呼び出し側は、以下をすべて満たすことを保証しなければなりません。

  • z が有効なズームレベル(0–63)であること
  • f1,f2 が与えられた z に応じて F_MIN[z]..=F_MAX[z] の範囲内であること
  • x1,x2 および y1,y20..=XY_MAX[z] の範囲内であること

これらが保証されない場合、本構造体の他のメソッド(範囲を前提とした計算)が パニック・不正メモリアクセス・未定義動作を引き起こす可能性があります。

// パラメータが妥当であることを呼び出し側が保証する必要がある
let id = unsafe { RangeId::new_unchecked(5, [-10,-5], [8,9], [5,10]) };

assert_eq!(id.z(), 5);
assert_eq!(id.f(), [-10,-5]);
assert_eq!(id.x(), [8,9]);
assert_eq!(id.y(), [5,10]);
Source§

impl RangeId

Source

pub fn random_using<R: Rng>(rng: &mut R) -> Self

外部から渡された乱数生成器を使って、全ズーム範囲からランダムな RangeId を生成します。

Source

pub fn random_at_using<R: Rng>(rng: &mut R, z: u8) -> Self

外部から渡された乱数生成器を使用して、指定したズームレベルでランダムにRangeIdを生成

Source

pub fn random_within_using<R: Rng>( rng: &mut R, z_range: RangeInclusive<u8>, ) -> Self

外部から渡された乱数生成器を使用して、指定したズームレベル範囲内でランダムにRangeIdを生成

Source

pub fn random() -> Self

全空間(Z=0〜MAX)からランダムにRangeIdを生成

Source

pub fn random_at(z: u8) -> Self

指定したズームレベルでランダムにRangeIdを生成

Source

pub fn random_within(z_range: RangeInclusive<u8>) -> Self

指定ズーム範囲からランダムな RangeId を生成します。

内部で rand::rng() を作って random_within_using に委譲します。

Source§

impl RangeId

Source

pub fn z(&self) -> u8

この RangeId が保持しているズームレベル z を返します。

let id = RangeId::new(5, [-3,29], [8,9], [5,10]).unwrap();
assert_eq!(id.z(), 5u8);
Source

pub fn f(&self) -> [i32; 2]

この RangeId が保持しているズームレベル [f1,f2] を返します。

let id = RangeId::new(5, [-3,29], [8,9], [5,10]).unwrap();
assert_eq!(id.f(), [-3i32,29i32]);
Source

pub fn x(&self) -> [u32; 2]

この RangeId が保持しているズームレベル [x1,x2] を返します。

let id = RangeId::new(5, [-3,29], [8,9], [5,10]).unwrap();
assert_eq!(id.x(), [8u32,9u32]);
Source

pub fn y(&self) -> [u32; 2]

この RangeId が保持しているズームレベル [y1,y2] を返します。

let id = RangeId::new(5, [-3,29], [8,9], [5,10]).unwrap();
assert_eq!(id.y(), [5u32,10u32]);
Source

pub fn set_f(&mut self, value: [i32; 2]) -> Result<(), Error>

Source

pub fn set_x(&mut self, value: [u32; 2]) -> Result<(), Error>

Source

pub fn set_y(&mut self, value: [u32; 2]) -> Result<(), Error>

Source

pub fn spatial_children_at_zoom(&self, target_z: u8) -> Result<RangeId, Error>

指定したズームレベル target_z に細分化した、この RangeId を含むすべての子 RangeId を生成します。

§パラメータ
  • target_z — 生成したい子 RangeId のズームレベル
§バリデーション

1段深いズームへの細分化

let id = RangeId::new(5, [-3,29], [8,9], [5,10]).unwrap();
let result = id.spatial_children_at_zoom(6).unwrap();
assert_eq!(result,  RangeId::new(6, [-6, 59], [16, 19], [10, 21] ).unwrap());

現在より浅いズームを指定した場合

let id = RangeId::new(5, [-3,29], [8,9], [5,10]).unwrap();
let result = id.spatial_children_at_zoom(4);
assert!(matches!(result, Err(Error::SpatialId(SpatialIdError::ZoomLevelTransitionOutOfRange { current_z: 5, target_z: 4 }))));
Source

pub fn spatial_parent_at_zoom(&self, target_z: u8) -> Result<RangeId, Error>

指定したズームレベル target_z に縮約した、この RangeId の親 RangeId を返します。

§パラメータ
  • target_z — 取得したい親 RangeId のズームレベル
§バリデーション

1段浅いズームへの縮約

let id = RangeId::new(5, [1,29], [8,9], [5,10]).unwrap();
let parent = id.spatial_parent_at_zoom(4).unwrap();

assert_eq!(parent.z(), 4);
assert_eq!(parent.f(), [0,14]);
assert_eq!(parent.x(), [4,4]);
assert_eq!(parent.y(), [2,5]);

Fが負の場合の挙動:

let id = RangeId::new(5, [-10,-5], [8,9], [5,10]).unwrap();

let parent = id.spatial_parent_at_zoom(4).unwrap();

assert_eq!(parent.z(), 4);
assert_eq!(parent.f(), [-5,-3]);
assert_eq!(parent.x(), [4,4]);
assert_eq!(parent.y(), [2,5]);

現在より深いズームを指定した場合:

let id = RangeId::new(5, [-10,-5], [8,9], [5,10]).unwrap();
let result = id.spatial_parent_at_zoom(6);
assert!(matches!(result, Err(Error::SpatialId(SpatialIdError::ZoomLevelTransitionOutOfRange { current_z: 5, target_z: 6 }))));

Trait Implementations§

Source§

impl Clone for RangeId

Source§

fn clone(&self) -> RangeId

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RangeId

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for RangeId

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for RangeId

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

RangeId を文字列形式で表示します。

形式は "{z}/{f1}:{f2}/{x1}:{x2}/{y1}:{y2}" です。 また、次元の範囲が単体の場合は自動的にその次元がSingle表示になります。

通常時の範囲表示

let id = RangeId::new(4, [-3,6], [8,9], [5,10]).unwrap();
let s = format!("{}", id);
assert_eq!(s, "4/-3:6/8:9/5:10");

Single範囲に自動圧縮(f1=f2

let id = RangeId::new(4, [-3,-3], [8,9], [5,10]).unwrap();
let s = format!("{}", id);
 assert_eq!(s, "4/-3/8:9/5:10");;
Source§

impl Eq for RangeId

Source§

impl From<&FlexId> for RangeId

Source§

fn from(flex_id: &FlexId) -> Self

Converts to this type from the input type.
Source§

impl From<&SingleId> for RangeId

Source§

fn from(id: &SingleId) -> Self

Converts to this type from the input type.
Source§

impl From<FlexId> for RangeId

Source§

fn from(flex_id: FlexId) -> Self

Converts to this type from the input type.
Source§

impl From<SingleId> for RangeId

Source§

fn from(id: SingleId) -> Self

Converts to this type from the input type.
Source§

impl Hash for RangeId

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl IntoFlexIds for RangeId

Source§

type IntoIter = Box<dyn Iterator<Item = FlexId>>

Source§

fn into_flex_ids(self) -> Self::IntoIter

所有権ごと FlexId の列へ変換する。
Source§

impl IntoSingleIds for RangeId

Source§

type IntoIter = Box<dyn Iterator<Item = SingleId>>

Source§

fn into_single_ids(self) -> Self::IntoIter

所有権ごと SingleId の列へ変換する。
Source§

impl IterFlexIds for RangeId

Source§

type Iter<'a> = Box<dyn Iterator<Item = FlexId> + 'a>

Source§

fn iter_flex_ids(&self) -> Self::Iter<'_>

参照から FlexId の列を列挙する。
Source§

impl IterSingleIds for RangeId

Source§

type Iter<'a> = Box<dyn Iterator<Item = SingleId> + 'a>

Source§

fn iter_single_ids(&self) -> Self::Iter<'_>

参照から SingleId の列を列挙する。
Source§

impl Ord for RangeId

Source§

fn cmp(&self, other: &RangeId) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for RangeId

Source§

fn eq(&self, other: &RangeId) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for RangeId

Source§

fn partial_cmp(&self, other: &RangeId) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Serialize for RangeId

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl SpatialId for RangeId

Source§

fn spatial_center(&self) -> Coordinate

RangeId の中心座標をCoordinate型で返します。

中心座標は空間IDの最も外側の頂点の8点の平均座標です。現実空間における空間IDは完全な直方体ではなく、緯度や高度によって歪みが発生していることに注意する必要があります。

Source§

fn spatial_vertices(&self) -> [Coordinate; 8]

RangeId の最も外側の頂点の8点の座標をCoordinate型の配列として返します。

現実空間における空間IDは完全な直方体ではなく、緯度や高度によって歪みが発生していることに注意する必要があります。

Source§

fn length_f_meters(&self) -> f64

その空間IDのF方向の長さをメートル単位で計算する関数

Source§

fn length_x_meters(&self) -> f64

その空間IDのX方向の長さをメートル単位で計算する関数

Source§

fn length_y_meters(&self) -> f64

その空間IDのY方向の長さをメートル単位で計算する関数

Source§

fn f_min(&self) -> i32

ズームレベルにおける最小のFインデックスを返す。 Read more
Source§

fn f_max(&self) -> i32

ズームレベルにおける最大のFインデックスを返す。 Read more
Source§

fn x_max(&self) -> u32

ズームレベルにおける最大のXインデックスを返す。 Read more
Source§

fn y_max(&self) -> u32

ズームレベルにおける最大のYインデックスを返す。 Read more
Source§

fn move_f(&mut self, by: i32) -> Result<(), Error>

F 方向に指定インデックスだけ移動する。
Source§

fn move_x(&mut self, by: i32)

X 方向に指定インデックスだけ移動する。
Source§

fn move_y(&mut self, by: i32) -> Result<(), Error>

Y 方向に指定インデックスだけ移動する。
Source§

fn temporal(&self) -> &TemporalId

時間 ID を参照で返す。
Source§

fn temporal_mut(&mut self) -> &mut TemporalId

時間 ID を可変参照で返す。
Source§

fn x_min(&self) -> u32

ズームレベルにおける最小のXインデックスを返す。全てのIDにおいて必ず0を返す。 Read more
Source§

fn y_min(&self) -> u32

ズームレベルにおける最小のYインデックスを返す。全てのIDにおいて必ず0を返す。 Read more
Source§

impl StructuralPartialEq for RangeId

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V