Tanoda
AttachmentPointFlags.cs
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (C) Ultraleap, Inc. 2011-2020. *
3 * *
4 * Use subject to the terms of the Apache License 2.0 available at *
5 * http://www.apache.org/licenses/LICENSE-2.0, or another agreement *
6 * between Ultraleap and you, your company or other organization. *
7 ******************************************************************************/
8
9using UnityEngine;
10
11namespace Leap.Unity.Attachments {
12
16 [System.Flags]
18 None = 0,
19
20 Wrist = 1 << 1,
21 Palm = 1 << 2,
22
23 ThumbProximalJoint = 1 << 3,
24 ThumbDistalJoint = 1 << 4,
25 ThumbTip = 1 << 5,
26
27 IndexKnuckle = 1 << 6,
28 IndexMiddleJoint = 1 << 7,
29 IndexDistalJoint = 1 << 8,
30 IndexTip = 1 << 9,
31
32 MiddleKnuckle = 1 << 10,
33 MiddleMiddleJoint = 1 << 11,
34 MiddleDistalJoint = 1 << 12,
35 MiddleTip = 1 << 13,
36
37 RingKnuckle = 1 << 14,
38 RingMiddleJoint = 1 << 15,
39 RingDistalJoint = 1 << 16,
40 RingTip = 1 << 17,
41
42 PinkyKnuckle = 1 << 18,
43 PinkyMiddleJoint = 1 << 19,
44 PinkyDistalJoint = 1 << 20,
45 PinkyTip = 1 << 21
46 }
47
48 public static class AttachmentPointFlagsExtensions {
49
50 // Takes advantage of two's complement representation for negative integers
51 // to check whether the bit field has a single bit set.
52 // https://en.wikipedia.org/wiki/Two%27s_complement
53 public static bool IsSinglePoint(this AttachmentPointFlags points) {
54 int mask = (int)points;
55 bool isSingleBitSet = mask != 0 && mask == (mask & -mask);
56 return isSingleBitSet;
57 }
58
63 public static bool ContainsPoint(this AttachmentPointFlags points, AttachmentPointFlags singlePoint) {
64#if UNITY_EDITOR
65 // Validation for ensuring singlePoint is really a single point.
66 if (!singlePoint.IsSinglePoint()) {
67 Debug.LogWarning("'ContainsPoint' called with an argument that contains more than one attachment point flag set.");
68 }
69#endif
70 return points.Contains(singlePoint);
71 }
72
79 public static bool Contains(this AttachmentPointFlags points, AttachmentPointFlags otherPoints) {
80 if (points == AttachmentPointFlags.None || otherPoints == AttachmentPointFlags.None) return false;
81 return (points & otherPoints) == otherPoints;
82 }
83
84 }
85
86}
UnityEngine.Debug Debug
Definition: TanodaServer.cs:19
AttachmentPointFlags
Flags for attachment points on the hand.