| Crates.io | hotspots |
| lib.rs | hotspots |
| version | 0.2.0 |
| created_at | 2025-12-02 21:09:21.467941+00 |
| updated_at | 2025-12-03 03:39:24.442264+00 |
| description | A lightweight Rust library for working with 2D rectangular hotspots with support for pixel and percentage-based coordinates |
| homepage | https://github.com/josiahbull/hotspots |
| repository | https://github.com/josiahbull/hotspots |
| max_upload_size | |
| id | 1962642 |
| size | 164,317 |
A lightweight, Rust library for working with 2D rectangular hotspots. Supports multiple internal representations (pixel-based and percentage-based), lossless conversions, overlap detection, utiltiies for handling conversions between different points of origins and generally working with hotspots are also provided.
Coordinates are stored as fractions of the maximum value:
high_precision (u32): 4,294,967,296 discrete positionsWhen precision loss occurs: If your image dimensions exceed these values,
multiple adjacent pixels map to the same internal representation. For
percentage-based hotspots on a 100,000×100,000 pixel image with u16, expect ~1-2
pixel rounding errors. Use high_precision for images larger than ~65,000
pixels in either dimension.
Add to your Cargo.toml:
[dependencies]
hotspots = "0.1"
serde: Enable serialization/deserialization supportreflectapi: Enable ReflectAPI schema generationhigh_precision: Use u32 coordinates with instead of u16. See Important Note on Precision for more information.use hotspots::{Hotspot, Coordinate};
// Create a hotspot from two corners (pixel coordinates)
let hotspot = Hotspot::builder().from_pixels((
Coordinate { x: 100, y: 150 },
Coordinate { x: 200, y: 250 },
));
// Access corners
let upper_right = hotspot.upper_right();
let lower_left = hotspot.lower_left();
let upper_left = hotspot.upper_left();
let lower_right = hotspot.lower_right();
use hotspots::{Hotspot, Coordinate, ImageDimensions, repr::PercentageRepr};
// Create a percentage-based hotspot
let dimensions = ImageDimensions { width: 1920, height: 1080 };
let hotspot = Hotspot::builder()
.with_repr::<PercentageRepr>()
.from_percentage(
(
Coordinate { x: 100, y: 200 }, // Internal percentage representation
Coordinate { x: 300, y: 400 }
),
dimensions
);
// Get pixel coordinates for a specific image size
let pixel_coords = hotspot.upper_right(dimensions);
Licensed under either of:
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.