| Crates.io | kasane-logic |
| lib.rs | kasane-logic |
| version | 0.0.6 |
| created_at | 2025-08-22 08:20:52.17997+00 |
| updated_at | 2025-09-21 02:22:55.900329+00 |
| description | This is Kasane-logic |
| homepage | |
| repository | |
| max_upload_size | |
| id | 1806064 |
| size | 1,333,008 |
Kasane Logic is a Rust library that extends the 4-dimensional spatial information notation defined by IPA (Information-technology Promotion Agency) and enables logical operations on space-time IDs. The calculations are implemented using pure Rust functions, and operate correctly and efficiently in any environment without external dependencies.
SpaceTimeIdDimensionRangeSpaceTimeIdSetlogic = { path = "../logic", features = ["serde_support"] }
Enable the serde_support feature to output types compatible with serde and jsonschema.
SpaceTimeId TypeSpaceTimeId represents a region with 4-dimensional space (X, Y, F, T) plus zoom level and time interval.
[!NOTE] A spacetime ID indicates a value where
iis not 0, while a space ID is defined as havingi = 0andt = Any.
let stid = SpaceTimeId::new(
4, // Zoom level
DimensionRange::AfterUnLimitRange(10), // Height (f): 10 and above
DimensionRange::Single(5), // x coordinate
DimensionRange::Single(3), // y coordinate
60, // Time interval (seconds)
DimensionRange::LimitRange(100, 200), // Time index (t)
).unwrap();
Spatial ID represents objects that are valid for all time.
let stid = SpaceTimeId::new(
4, // Zoom level
DimensionRange::AfterUnLimitRange(10), // Height (f): 10 and above
DimensionRange::Single(5), // x coordinate
DimensionRange::Single(3), // y coordinate
0, // i=0 specifies spatial ID
DimensionRange::Any, // Time index shows Any for all values
).unwrap();
The following extended notation has been introduced:
When there are no constraints on a specific dimension (all values are targeted), use -.
Example: When F dimension is undefined
2/-/1/3
This is equivalent to the following set:
2/-4/1/3, 2/-3/1/3, ..., 2/3/1/3
Use : to indicate intervals:
2/1/3/1:5
This is equivalent to:
2/1/3/1, 2/1/3/2, 2/1/3/3, 2/1/3/4, 2/1/3/5
To mean from a starting point to infinity, use : and - together:
2/1/3/1:-
This means
2/1/3/1, 2/1/3/2, 2/1/3/3, ...
DimensionRange<T> TypeGeneric range type representing values for each dimension (X, Y, F, T):
Single(v): Single valueLimitRange(start, end): Closed interval from start to endBeforeUnLimitRange(end): From the lower limit of values to endAfterUnLimitRange(start): From start to the upper limit of valuesAny: Matches all values (entire domain)SpaceTimeId Functions and Methodscoordinates() -> CoordinatesConverts the SpaceTimeId to geographic coordinates (latitude, longitude, altitude).
let stid = SpaceTimeId::new(4, DimensionRange::Single(5), DimensionRange::Single(3), DimensionRange::Single(10), 60, DimensionRange::Single(100)).unwrap();
let coords = stid.coordinates();
println!("Latitude: {:?}, Longitude: {:?}, Altitude: {:?}", coords.latitude, coords.longitude, coords.altitude);
center() -> PointReturns the center point of the spatial region.
let center = stid.center();
println!("Center Point - Latitude: {}, Longitude: {}, Altitude: {}", center.latitude, center.longitude, center.altitude);
vertex() -> [Point; 8]Returns the eight corner vertices of the spatial region.
let vertices = stid.vertex();
for (i, vertex) in vertices.iter().enumerate() {
println!("Vertex{}: Latitude={}, Longitude={}, Altitude={}", i, vertex.latitude, vertex.longitude, vertex.altitude);
}
change_scale(z: Option<u16>, i: Option<u32>) -> Result<SpaceTimeId, String>Changes spatial resolution (zoom level) or temporal resolution (time interval).
// Change zoom level to 6
let scaled = stid.change_scale(Some(6), None)?;
// Change time interval to 30 seconds
let time_scaled = stid.change_scale(None, Some(30))?;
containment_relation(&other: &SpaceTimeId) -> ContainmentDetermines the containment relationship with another SpaceTimeId.
let containment = stid1.containment_relation(&stid2);
match containment {
Containment::Full => println!("stid1 completely contains stid2"),
Containment::Partial(intersection) => println!("Partially overlapping: {}", intersection),
Containment::None => println!("No overlap"),
}
complement(&self) -> SpaceTimeIdSetReturns the complement of this SpaceTimeId (areas not included).
let complement_set = stid.complement();
println!("Complement: {}", complement_set);
pure(&self) -> Vec<SpaceTimeId>Expands all range notations (Any, LimitRange, BeforeUnLimitRange, AfterUnLimitRange) in the spatial dimensions (F, X, Y) into individual SpaceTimeIds with only Single values. The time dimension (T) is preserved as-is.
This function is useful for converting complex range-based SpaceTimeIds into concrete, enumerated SpaceTimeIds for precise processing.
// Create a SpaceTimeId with range dimensions
let stid = SpaceTimeId::new(
2, // Zoom level 2
DimensionRange::LimitRange(0, 1), // F dimension: 0 to 1
DimensionRange::LimitRange(1, 2), // X dimension: 1 to 2
DimensionRange::Single(0), // Y dimension: single value 0
60, // Time interval
DimensionRange::Single(100), // T dimension: single value 100
).unwrap();
// Expand to pure IDs
let pure_ids = stid.pure();
println!("Expanded to {} pure IDs", pure_ids.len()); // Will be 4 IDs (2 F values ร 2 X values ร 1 Y value)
// Each pure ID will have only Single values for F, X, Y dimensions
for pure_id in pure_ids {
println!("{}", pure_id); // e.g., "2/0/1/0_60/100", "2/0/2/0_60/100", etc.
}
Getter methods for accessing values and attributes of each dimension:
f() -> DimensionRange<i32>: F dimension (altitude) valuex() -> DimensionRange<u32>: X dimension valuey() -> DimensionRange<u32>: Y dimension valuet() -> DimensionRange<u32>: T dimension (time index) valuez() -> u16: Zoom leveli() -> u32: Time interval (seconds)Point StructureRepresents a point in 3-dimensional space.
pub struct Point {
pub latitude: f64, // Latitude
pub longitude: f64, // Longitude
pub altitude: f64, // Altitude
}
Coordinates StructureRepresents the coordinate range of a spatial region.
pub struct Coordinates {
pub latitude: (f64, f64), // Latitude range (min, max)
pub longitude: (f64, f64), // Longitude range (min, max)
pub altitude: (f64, f64), // Altitude range (min, max)
}
Containment EnumerationRepresents the type of containment relationship.
pub enum Containment {
Full, // Complete containment
Partial(SpaceTimeId), // Partial overlap (includes intersection area)
None, // No overlap
}
SpaceTimeIdSet TypeManages multiple SpaceTimeId as a set. When adding new elements, any overlapping ranges with existing elements are automatically adjusted, ensuring that only unique IDs for the physical space remain.
let mut set = SpaceTimeIdSet::new();
set.insert(stid);
SpaceTimeIdSet Methodsnew() -> SpaceTimeIdSetCreates a new empty set.
let mut set = SpaceTimeIdSet::new();
insert(&mut self, other: SpaceTimeId)Adds a SpaceTimeId to the set. Automatically adjusts for duplicates or overlaps.
set.insert(stid);
iter() -> impl Iterator<Item = &SpaceTimeId>Returns an iterator for processing elements in the set.
for id in set.iter() {
println!("{}", id);
}
is_empty() -> boolChecks if the set is empty.
if set.is_empty() {
println!("Set is empty");
}
from(id: SpaceTimeId) -> SpaceTimeIdSetCreates a set from a single SpaceTimeId.
let set = SpaceTimeIdSet::from(stid);
|: Union - Combines two sets&: Intersection - Extracts common parts^: Exclusive OR (XOR) - Returns regions in either set but not in both!: Complement - Returns areas not included==: Equality comparison - Returns true if they represent the same spatial regionlet union = set_a | set_b;
let intersection = set_a & set_b;
let xor = set_a ^ set_b;
let complement = !set_a;
assert_eq!(set_a, set_b); // true if physically equivalent
let a = SpaceTimeId::new(...).unwrap();
let b = SpaceTimeId::new(...).unwrap();
let mut set = SpaceTimeIdSet::new();
set.insert(a);
let set2 = SpaceTimeIdSet::from(b);
let union = set | set2;
let common = set & set2;
let outside = !set;
SpaceTimeId Constructornew(z: u16, f: DimensionRange<i32>, x: DimensionRange<u32>, y: DimensionRange<u32>, i: u32, t: DimensionRange<u32>) -> Result<SpaceTimeId, String>SpaceTimeId Instance Methodscoordinates() -> Coordinates - Get geographic coordinatescenter() -> Point - Get center point of spatial regionvertex() -> [Point; 8] - Get eight corner verticeschange_scale(z: Option<u16>, i: Option<u32>) -> Result<SpaceTimeId, String> - Change resolutioncontainment_relation(&other: &SpaceTimeId) -> Containment - Check containment relationshipcomplement() -> SpaceTimeIdSet - Get complement setpure() -> Vec<SpaceTimeId> - Expand range dimensions to individual SpaceTimeIdswith_z(z: u16) -> Result<SpaceTimeId, String> - Create new ID with different zoom levelwith_f(f: DimensionRange<i32>) -> Result<SpaceTimeId, String> - Create new ID with different F dimensionwith_x(x: DimensionRange<u32>) -> Result<SpaceTimeId, String> - Create new ID with different X dimensionwith_y(y: DimensionRange<u32>) -> Result<SpaceTimeId, String> - Create new ID with different Y dimensionwith_i(i: u32) -> Result<SpaceTimeId, String> - Create new ID with different time intervalwith_t(t: DimensionRange<u32>) -> Result<SpaceTimeId, String> - Create new ID with different T dimensionf() -> DimensionRange<i32> - Get F dimension valuex() -> DimensionRange<u32> - Get X dimension valuey() -> DimensionRange<u32> - Get Y dimension valuet() -> DimensionRange<u32> - Get T dimension valuez() -> u16 - Get zoom leveli() -> u32 - Get time intervalSpaceTimeIdSet Methodsnew() -> SpaceTimeIdSet - Create new empty setfrom(id: SpaceTimeId) -> SpaceTimeIdSet - Create set from single IDinsert(&mut self, other: SpaceTimeId) - Add ID to setiter() -> impl Iterator<Item = &SpaceTimeId> - Get iteratoris_empty() -> bool - Check if set is emptypure(&self) -> Vec<SpaceTimeId> - Expand all set elements to pure formSpaceTimeIdSet Operatorsset1 | set2 - Union operationset1 & set2 - Intersection operationset1 ^ set2 - XOR (exclusive OR) operation!set - Complement operationset1 == set2 - Equality comparisonWe welcome all contributions including bug reports, feature suggestions, documentation fixes, and test additions.
<type>/<short-description>(-<issue-number>) (include the issue number if one exists)feat โ New featurefix โ Bug fixdocs โ Documentation updaterefactor โ Code refactoringchore โ Miscellaneous tasks (e.g., CI configuration, dependency updates)feat/add-user-login-123Title format: [type] #<issue-number> short description (include the issue number if one exists)
This library prioritizes accuracy as its primary goal. Therefore, we maintain a comprehensive testing strategy:
cargo testPerformance benchmarks are designed to optimize function performance:
cargo bench