1
+ //! Axes descriptions of tool capabilities and limits.
2
+
1
3
use crate :: util:: NicheF32 ;
2
4
3
5
bitflags:: bitflags! {
@@ -49,6 +51,7 @@ impl AvailableAxes {
49
51
strum:: IntoStaticStr ,
50
52
strum:: EnumIter ,
51
53
) ]
54
+ /// An individual Tool axis.
52
55
pub enum Axis {
53
56
/// The tool can sense how much force is applied, purpendicular to the pad surface.
54
57
Pressure ,
@@ -60,7 +63,7 @@ pub enum Axis {
60
63
Roll ,
61
64
/// The tool has a scroll wheel. It may report continuous motion as well as discrete steps.
62
65
Wheel ,
63
- /// The tool has an absolute linear slider control, ranging from -1 to 1 with zero being the "natural" position.
66
+ /// The tool has an absolute linear slider control, `[-1, 1]` with zero being the "natural" position.
64
67
Slider ,
65
68
/// The tool has a pressure-sensitive button, reporting how hard the user is pressing on it.
66
69
ButtonPressure ,
@@ -101,8 +104,9 @@ impl<U: Union + Clone> Union for Option<U> {
101
104
}
102
105
}
103
106
104
- /// Granularity of an axis. This does not affect the range of values.
105
- /// Describes the number of unique values between `0` and `1` of the associated unit.
107
+ /// Describes the number of unique values in the entire range of the associated axis.
108
+ ///
109
+ /// This does not affect the range of values nor the interpretation of values reported by a [`Pose`].
106
110
#[ derive( Clone , Copy , Debug , PartialEq , Eq , PartialOrd , Ord ) ]
107
111
#[ repr( transparent) ]
108
112
pub struct Granularity ( pub std:: num:: NonZeroU32 ) ;
@@ -125,12 +129,18 @@ impl Union for PositionGranularity {
125
129
}
126
130
}
127
131
128
- /// Limits of an axis's reported value.
132
+ /// Limits of an axis's reported value. This does not affect the interpretation of a value reported by [`Pose`]
133
+ ///
134
+ /// In many cases, you may ignore this value - this crate makes strong guarantees about the
135
+ /// units values are reported in, and you may rely on those. However, this may desscribe e.g. that a tool only detects
136
+ /// tilt in the +/-45° range.
129
137
/// # Quirks
130
138
/// This is a hint, and the value is not clamped - the hardware is allowed to report a value exceeding this in either direction.
131
139
#[ derive( Clone , Copy , Debug ) ]
132
140
pub struct Limits {
141
+ /// Inclusive minimum
133
142
pub min : f32 ,
143
+ /// Inclusive maximum
134
144
pub max : f32 ,
135
145
}
136
146
impl From < Limits > for std:: ops:: RangeInclusive < f32 > {
@@ -153,7 +163,7 @@ impl Union for Limits {
153
163
}
154
164
}
155
165
156
- /// Represents a normalized axis, always in the range `0..=1 `
166
+ /// Represents a normalized axis, always in the range `[0, 1] `
157
167
/// Since the min and max are fixed, only the granularity is given, if known.
158
168
#[ derive( Clone , Copy , Debug , Default ) ]
159
169
pub struct NormalizedInfo {
@@ -167,14 +177,14 @@ impl Union for NormalizedInfo {
167
177
}
168
178
}
169
179
180
+ /// Info for an axis which may or may not correspond to a physical unit of length.
170
181
#[ derive( Clone , Copy , Debug ) ]
171
182
pub enum LengthInfo {
172
- /// The axis reports a `0..=1 ` range, where the value doesn't necessarily correlate linearly with a
183
+ /// The axis reports a `[0, 1] ` range, where the value doesn't necessarily correlate linearly with a
173
184
/// physical unit of distance.
174
- /// In this case, [`Granularity`] is to be interpreted as the total number of states between 0 and 1.
175
185
Normalized ( NormalizedInfo ) ,
176
186
/// The axis reports a physical distance in centimeters, within the range provided by
177
- /// [`Info::limits`]. In this case, [`Granularity`] is to be interpreted as "dots per cm".
187
+ /// [`Info::limits`].
178
188
Centimeters ( Info ) ,
179
189
}
180
190
impl LengthInfo {
@@ -218,6 +228,7 @@ impl Default for LengthInfo {
218
228
}
219
229
}
220
230
231
+ /// Generic information about an axis with hardware-defined limits.
221
232
#[ derive( Clone , Copy , Debug , Default ) ]
222
233
pub struct Info {
223
234
pub limits : Option < Limits > ,
@@ -245,7 +256,7 @@ impl Union for PositionInfo {
245
256
}
246
257
}
247
258
248
- /// Information about a circular axis, always reporting in the range of `0.. TAU`.
259
+ /// Information about a circular axis, always reporting in the range of `[0, TAU) `.
249
260
#[ derive( Clone , Copy , Debug , Default ) ]
250
261
pub struct CircularInfo {
251
262
pub granularity : Option < Granularity > ,
@@ -258,7 +269,7 @@ impl Union for CircularInfo {
258
269
}
259
270
}
260
271
261
- /// Information about a slider axis, always reporting in the range of `-1..=1 ` with zero being the resting point.
272
+ /// Information about a slider axis, always reporting in the range of `[-1, 1] ` with zero being the resting point.
262
273
#[ derive( Clone , Copy , Debug , Default ) ]
263
274
pub struct SliderInfo {
264
275
pub granularity : Option < Granularity > ,
@@ -272,19 +283,15 @@ impl Union for SliderInfo {
272
283
}
273
284
274
285
/// A report of the limits and capabilities of all axes, or None if the axis is
275
- /// not supported by the device.
286
+ /// not supported by the device. See [`Pose`] for descriptions.
276
287
#[ derive( Debug , Copy , Clone , Default ) ]
277
288
pub struct FullInfo {
278
289
/// The X and Y axes - always supported, and with units of logical pixels.
279
290
pub position : [ PositionInfo ; 2 ] ,
280
- /// A unitless normalized value in [-1, 1]
281
291
pub slider : Option < SliderInfo > ,
282
- /// The rotation around the tool's long axis, always reported in radians `0..TAU` if available.
283
292
pub roll : Option < CircularInfo > ,
284
- // Force axes. Ink *can* report these in grams, but for simplicities sake we normalize. Todo?
285
293
pub pressure : Option < NormalizedInfo > ,
286
294
pub button_pressure : Option < NormalizedInfo > ,
287
- /// X/Y tilt, in radians from vertical. See [`Pose::tilt`].
288
295
pub tilt : Option < Info > ,
289
296
pub wheel : Option < CircularInfo > ,
290
297
pub distance : Option < LengthInfo > ,
@@ -312,6 +319,7 @@ impl Union for FullInfo {
312
319
313
320
#[ derive( thiserror:: Error , Debug , Copy , Clone , PartialEq , Eq , Hash ) ]
314
321
#[ error( "axis not supported" ) ]
322
+ /// An axis was queried that is not reported as available.
315
323
pub struct UnsupportedAxisError ;
316
324
317
325
impl FullInfo {
@@ -441,7 +449,8 @@ pub struct Pose {
441
449
///
442
450
/// This may have sub-pixel precision, and may exceed your window size in the negative or positive directions.
443
451
pub position : [ f32 ; 2 ] ,
444
- /// Perpendicular distance from the surface of the tablet. See [`FullInfo::distance`] for interpretation.
452
+ /// Perpendicular distance from the surface of the tablet. This may be an arbitrary, unitless `[0, 1]` value, or
453
+ /// reported in physical centimeters, see the [`FullInfo::distance`] of the reporting [`Tool`](crate::tool::Tool) for interpretation.
445
454
///
446
455
/// # Quirks
447
456
/// This will not necessarily be zero when in contact with the device, and may
@@ -472,6 +481,6 @@ pub struct Pose {
472
481
/// Absolute slider position, in `[-1, 1]`, where zero is the "natural" position.
473
482
pub slider : NicheF32 ,
474
483
/// The size of the contact ellipse. First element describes the X-axis width of the ellipse,
475
- /// and second describes the Y-axis height. See [`FullInfo::contact_size`] for interpretation .
484
+ /// and second describes the Y-axis height. See [`FullInfo::contact_size`] of the reporting [`Tool`](crate::tool::Tool) for units .
476
485
pub contact_size : Option < [ f32 ; 2 ] > ,
477
486
}
0 commit comments