From 1ed2114f2fbb24cd8fadd17b23636face16604ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20St=C3=B6glehner?= Date: Thu, 11 Aug 2022 08:11:25 +0200 Subject: [PATCH] CATTY-686 Fix computer vision sensors in landscape mode --- src/Catty.xcodeproj/project.pbxproj | 20 +++++-- src/Catty/Functions/FunctionManager.swift | 6 +- .../HeightOfObjectWithIDFunction.swift | 12 ++-- .../WidthOfObjectWithIDFunction.swift | 13 ++-- .../XOfObjectWithIDFunction.swift | 12 ++-- .../YOfObjectWithIDFunction.swift | 12 ++-- src/Catty/Functions/Protocols/Function.swift | 4 ++ .../TextRecognition/TextBlockXFunction.swift | 12 ++-- .../TextRecognition/TextBlockYFunction.swift | 13 ++-- .../PlayerEngine/Formula/FormulaManager.swift | 16 +++-- .../Sensors/BodyPose/LeftAnkleXSensor.swift | 12 ++-- .../Sensors/BodyPose/LeftAnkleYSensor.swift | 11 ++-- .../Sensors/BodyPose/LeftElbowXSensor.swift | 12 ++-- .../Sensors/BodyPose/LeftElbowYSensor.swift | 11 ++-- .../Sensors/BodyPose/LeftHipXSensor.swift | 12 ++-- .../Sensors/BodyPose/LeftHipYSensor.swift | 11 ++-- .../Sensors/BodyPose/LeftKneeXSensor.swift | 12 ++-- .../Sensors/BodyPose/LeftKneeYSensor.swift | 11 ++-- .../BodyPose/LeftShoulderXSensor.swift | 12 ++-- .../BodyPose/LeftShoulderYSensor.swift | 11 ++-- .../Sensors/BodyPose/LeftWristXSensor.swift | 12 ++-- .../Sensors/BodyPose/LeftWristYSensor.swift | 11 ++-- .../Sensors/BodyPose/NeckXSensor.swift | 12 ++-- .../Sensors/BodyPose/NeckYSensor.swift | 11 ++-- .../Sensors/BodyPose/RightAnkleXSensor.swift | 12 ++-- .../Sensors/BodyPose/RightAnkleYSensor.swift | 11 ++-- .../Sensors/BodyPose/RightElbowXSensor.swift | 12 ++-- .../Sensors/BodyPose/RightElbowYSensor.swift | 11 ++-- .../Sensors/BodyPose/RightHipXSensor.swift | 12 ++-- .../Sensors/BodyPose/RightHipYSensor.swift | 11 ++-- .../Sensors/BodyPose/RightKneeXSensor.swift | 12 ++-- .../Sensors/BodyPose/RightKneeYSensor.swift | 11 ++-- .../BodyPose/RightShoulderXSensor.swift | 12 ++-- .../BodyPose/RightShoulderYSensor.swift | 11 ++-- .../Sensors/BodyPose/RightWristXSensor.swift | 12 ++-- .../Sensors/BodyPose/RightWristYSensor.swift | 11 ++-- .../VisualDetectionManager.swift | 39 +++++++----- .../Sensors/Face/FacePositionXSensor.swift | 12 ++-- .../Sensors/Face/FacePositionYSensor.swift | 11 ++-- .../Face/SecondFacePositionXSensor.swift | 11 ++-- .../Face/SecondFacePositionYSensor.swift | 11 ++-- .../Sensors/FacePose/HeadTopXSensor.swift | 12 ++-- .../Sensors/FacePose/HeadTopYSensor.swift | 11 ++-- .../Sensors/FacePose/LeftEarXSensor.swift | 12 ++-- .../Sensors/FacePose/LeftEarYSensor.swift | 11 ++-- .../FacePose/LeftEyeCenterXSensor.swift | 12 ++-- .../FacePose/LeftEyeCenterYSensor.swift | 11 ++-- .../FacePose/LeftEyeInnerXSensor.swift | 12 ++-- .../FacePose/LeftEyeInnerYSensor.swift | 11 ++-- .../FacePose/LeftEyeOuterXSensor.swift | 12 ++-- .../FacePose/LeftEyeOuterYSensor.swift | 11 ++-- .../FacePose/LeftEyebrowCenterXSensor.swift | 12 ++-- .../FacePose/LeftEyebrowCenterYSensor.swift | 11 ++-- .../FacePose/LeftEyebrowInnerXSensor.swift | 12 ++-- .../FacePose/LeftEyebrowInnerYSensor.swift | 11 ++-- .../FacePose/LeftEyebrowOuterXSensor.swift | 12 ++-- .../FacePose/LeftEyebrowOuterYSensor.swift | 11 ++-- .../FacePose/MouthLeftCornerXSensor.swift | 12 ++-- .../FacePose/MouthLeftCornerYSensor.swift | 11 ++-- .../FacePose/MouthRightCornerXSensor.swift | 12 ++-- .../FacePose/MouthRightCornerYSensor.swift | 11 ++-- .../Sensors/FacePose/NoseXSensor.swift | 12 ++-- .../Sensors/FacePose/NoseYSensor.swift | 11 ++-- .../Sensors/FacePose/RightEarXSensor.swift | 12 ++-- .../Sensors/FacePose/RightEarYSensor.swift | 11 ++-- .../FacePose/RightEyeCenterXSensor.swift | 12 ++-- .../FacePose/RightEyeCenterYSensor.swift | 11 ++-- .../FacePose/RightEyeInnerXSensor.swift | 12 ++-- .../FacePose/RightEyeInnerYSensor.swift | 11 ++-- .../FacePose/RightEyeOuterXSensor.swift | 12 ++-- .../FacePose/RightEyeOuterYSensor.swift | 11 ++-- .../FacePose/RightEyebrowCenterXSensor.swift | 12 ++-- .../FacePose/RightEyebrowCenterYSensor.swift | 11 ++-- .../FacePose/RightEyebrowInnerXSensor.swift | 12 ++-- .../FacePose/RightEyebrowInnerYSensor.swift | 11 ++-- .../FacePose/RightEyebrowOuterXSensor.swift | 12 ++-- .../FacePose/RightEyebrowOuterYSensor.swift | 11 ++-- .../HandPose/LeftIndexKnuckleXSensor.swift | 12 ++-- .../HandPose/LeftIndexKnuckleYSensor.swift | 11 ++-- .../LeftMiddleFingerKnuckleXSensor.swift | 12 ++-- .../LeftMiddleFingerKnuckleYSensor.swift | 11 ++-- .../HandPose/LeftPinkyKnuckleXSensor.swift | 12 ++-- .../HandPose/LeftPinkyKnuckleYSensor.swift | 11 ++-- .../LeftRingFingerKnuckleXSensor.swift | 12 ++-- .../LeftRingFingerKnuckleYSensor.swift | 11 ++-- .../HandPose/LeftThumbKnuckleXSensor.swift | 12 ++-- .../HandPose/LeftThumbKnuckleYSensor.swift | 11 ++-- .../HandPose/RightIndexKnuckleXSensor.swift | 12 ++-- .../HandPose/RightIndexKnuckleYSensor.swift | 11 ++-- .../RightMiddleFingerKnuckleXSensor.swift | 12 ++-- .../RightMiddleFingerKnuckleYSensor.swift | 11 ++-- .../HandPose/RightPinkyKnuckleXSensor.swift | 12 ++-- .../HandPose/RightPinkyKnuckleYSensor.swift | 11 ++-- .../RightRingFingerKnuckleXSensor.swift | 12 ++-- .../RightRingFingerKnuckleYSensor.swift | 11 ++-- .../HandPose/RightThumbKnuckleXSensor.swift | 12 ++-- .../HandPose/RightThumbKnuckleYSensor.swift | 11 ++-- .../ObjectRecognitionFunctionsTest.swift | 60 ++++++++++--------- .../TextBlockPositionFunctionTest.swift | 30 +++++----- .../Sensors/BodyPose/AnkleSensorTest.swift | 7 +-- .../Sensors/BodyPose/ElbowSensorTest.swift | 7 +-- .../Sensors/BodyPose/HipSensorTest.swift | 7 +-- .../Sensors/BodyPose/KneeSensorTest.swift | 7 +-- .../Sensors/BodyPose/NeckSensorTest.swift | 10 ++-- .../Sensors/BodyPose/ShoulderSensorTest.swift | 7 +-- .../Sensors/BodyPose/WristSensorTest.swift | 7 +-- .../VisualDetectionManagerTest.swift | 0 .../FaceDetectionSensorTest.swift | 0 .../FacePositionSensorTest.swift | 9 ++- .../{Camera => Face}/FaceSizeSensorTest.swift | 0 .../Sensors/FacePose/EarSensorTest.swift | 7 +-- .../Sensors/FacePose/EyeSensorTest.swift | 7 +-- .../Sensors/FacePose/EyebrowSensorTest.swift | 7 +-- .../Sensors/FacePose/HeadTopSensorTest.swift | 10 ++-- .../Sensors/FacePose/MouthSensorTest.swift | 7 +-- .../Sensors/FacePose/NoseSensorTest.swift | 10 ++-- .../Sensors/HandPose/IndexSensorTest.swift | 7 +-- .../HandPose/MiddleFingerSensorTest.swift | 7 +-- .../Sensors/HandPose/PinkySensorTest.swift | 5 +- .../HandPose/RingFingerSensorTest.swift | 7 +-- .../Sensors/HandPose/ThumbSensorTest.swift | 7 +-- 121 files changed, 623 insertions(+), 756 deletions(-) rename src/CattyTests/PlayerEngine/Sensors/{Camera => DetectionManager}/VisualDetectionManagerTest.swift (100%) rename src/CattyTests/PlayerEngine/Sensors/{Camera => Face}/FaceDetectionSensorTest.swift (100%) rename src/CattyTests/PlayerEngine/Sensors/{Camera => Face}/FacePositionSensorTest.swift (93%) rename src/CattyTests/PlayerEngine/Sensors/{Camera => Face}/FaceSizeSensorTest.swift (100%) diff --git a/src/Catty.xcodeproj/project.pbxproj b/src/Catty.xcodeproj/project.pbxproj index 41fdcc4a33..59b15b73a2 100644 --- a/src/Catty.xcodeproj/project.pbxproj +++ b/src/Catty.xcodeproj/project.pbxproj @@ -4886,6 +4886,14 @@ path = CattyTests/Resources/EmbroideryReference; sourceTree = SOURCE_ROOT; }; + 17399B8F2A0E336800BCECC1 /* DetectionManager */ = { + isa = PBXGroup; + children = ( + 4CD27AA521B55DBB00DDADB5 /* VisualDetectionManagerTest.swift */, + ); + path = DetectionManager; + sourceTree = ""; + }; 180D12E424D979A800341518 /* IO */ = { isa = PBXGroup; children = ( @@ -7155,13 +7163,13 @@ 4C822615213FA7A300F3D750 /* Sensors */ = { isa = PBXGroup; children = ( + 17399B8F2A0E336800BCECC1 /* DetectionManager */, 4974B2BC281A686A00EEF0D9 /* TextRecognition */, - 4C822651213FA7A300F3D750 /* SensorManagerTests.swift */, - 4C822640213FA7A300F3D750 /* Audio */, 49402B9E28117888009FCBF8 /* HandPose */, 49949B4A2806FCEC0073BF65 /* BodyPose */, 49E494E927F5993E0035578D /* FacePose */, - 4C822626213FA7A300F3D750 /* Camera */, + 4C822626213FA7A300F3D750 /* Face */, + 4C822640213FA7A300F3D750 /* Audio */, 4C822632213FA7A300F3D750 /* Date */, 4C822630213FA7A300F3D750 /* Heading */, 4C82262B213FA7A300F3D750 /* Location */, @@ -7170,6 +7178,7 @@ 4C822642213FA7A300F3D750 /* Object */, 4C82264F213FA7A300F3D750 /* Phiro */, 4C822621213FA7A300F3D750 /* Touch */, + 4C822651213FA7A300F3D750 /* SensorManagerTests.swift */, ); name = Sensors; path = PlayerEngine/Sensors; @@ -7203,15 +7212,14 @@ path = Touch; sourceTree = ""; }; - 4C822626213FA7A300F3D750 /* Camera */ = { + 4C822626213FA7A300F3D750 /* Face */ = { isa = PBXGroup; children = ( - 4CD27AA521B55DBB00DDADB5 /* VisualDetectionManagerTest.swift */, 4C822627213FA7A300F3D750 /* FaceDetectionSensorTest.swift */, 4C822628213FA7A300F3D750 /* FaceSizeSensorTest.swift */, 4C822629213FA7A300F3D750 /* FacePositionSensorTest.swift */, ); - path = Camera; + path = Face; sourceTree = ""; }; 4C82262B213FA7A300F3D750 /* Location */ = { diff --git a/src/Catty/Functions/FunctionManager.swift b/src/Catty/Functions/FunctionManager.swift index ad6954a84e..20cd86f484 100644 --- a/src/Catty/Functions/FunctionManager.swift +++ b/src/Catty/Functions/FunctionManager.swift @@ -26,8 +26,10 @@ import BluetoothHelper public static var defaultValueForUndefinedFunction: Double = 0 private static var functionMap = [String: Function]() // TODO: make instance let + private let landscapeMode: Bool - init(functions: [Function]) { + init(functions: [Function], landscapeMode: Bool = false) { + self.landscapeMode = landscapeMode super.init() registerFunctions(functionList: functions) } @@ -58,6 +60,8 @@ import BluetoothHelper value = function.value() as AnyObject } else if let function = function as? SingleParameterDoubleFunction { value = function.value(parameter: firstParameter) as AnyObject + } else if let function = function as? SingleParameterDoubleLandscapeFunction { + value = function.value(parameter: firstParameter, landscapeMode: landscapeMode) as AnyObject } else if let function = function as? DoubleParameterDoubleFunction { value = function.value(firstParameter: firstParameter, secondParameter: secondParameter) as AnyObject } else if let function = function as? ZeroParameterStringFunction { diff --git a/src/Catty/Functions/ObjectRecognition/HeightOfObjectWithIDFunction.swift b/src/Catty/Functions/ObjectRecognition/HeightOfObjectWithIDFunction.swift index 0392b7a46a..68d8c1e0ce 100644 --- a/src/Catty/Functions/ObjectRecognition/HeightOfObjectWithIDFunction.swift +++ b/src/Catty/Functions/ObjectRecognition/HeightOfObjectWithIDFunction.swift @@ -20,7 +20,7 @@ * along with this program. If not, see http://www.gnu.org/licenses/. */ -class HeightOfObjectWithIDFunction: SingleParameterDoubleFunction { +class HeightOfObjectWithIDFunction: SingleParameterDoubleLandscapeFunction { static let tag = "HEIGHT_OF_OBJECT_WITH_ID" static let name = kUIFEFunctionHeightOfObjectWithID @@ -30,10 +30,12 @@ class HeightOfObjectWithIDFunction: SingleParameterDoubleFunction { static let requiredResource = ResourceType.objectRecognition let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageHeight: Double? + let stageSize: CGSize + var stageHeight: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageHeight = Double(stageSize.height) } @@ -45,10 +47,9 @@ class HeightOfObjectWithIDFunction: SingleParameterDoubleFunction { .number(defaultValue: 1) } - func value(parameter: AnyObject?) -> Double { + func value(parameter: AnyObject?, landscapeMode: Bool) -> Double { guard let idAsDouble = parameter as? Double, - let visualDetectionManager = self.getVisualDetectionManager(), - let stageHeight = self.stageHeight + let visualDetectionManager = self.getVisualDetectionManager() else { return type(of: self).defaultValue } let id = Int(idAsDouble) @@ -56,6 +57,7 @@ class HeightOfObjectWithIDFunction: SingleParameterDoubleFunction { return type(of: self).defaultValue } + stageHeight = Double(landscapeMode ? stageSize.width : stageSize.height) let boundingBoxHeight = visualDetectionManager.objectRecognitions[id].boundingBox.height return stageHeight * boundingBoxHeight } diff --git a/src/Catty/Functions/ObjectRecognition/WidthOfObjectWithIDFunction.swift b/src/Catty/Functions/ObjectRecognition/WidthOfObjectWithIDFunction.swift index a2cbc1ca11..581c386f10 100644 --- a/src/Catty/Functions/ObjectRecognition/WidthOfObjectWithIDFunction.swift +++ b/src/Catty/Functions/ObjectRecognition/WidthOfObjectWithIDFunction.swift @@ -20,7 +20,7 @@ * along with this program. If not, see http://www.gnu.org/licenses/. */ -class WidthOfObjectWithIDFunction: SingleParameterDoubleFunction { +class WidthOfObjectWithIDFunction: SingleParameterDoubleLandscapeFunction { static let tag = "WIDTH_OF_OBJECT_WITH_ID" static let name = kUIFEFunctionWidthOfObjectWithID @@ -30,10 +30,12 @@ class WidthOfObjectWithIDFunction: SingleParameterDoubleFunction { static let requiredResource = ResourceType.objectRecognition let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageWidth: Double? + let stageSize: CGSize + var stageWidth: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageWidth = Double(stageSize.width) } @@ -45,10 +47,9 @@ class WidthOfObjectWithIDFunction: SingleParameterDoubleFunction { .number(defaultValue: 1) } - func value(parameter: AnyObject?) -> Double { + func value(parameter: AnyObject?, landscapeMode: Bool) -> Double { guard let idAsDouble = parameter as? Double, - let visualDetectionManager = self.getVisualDetectionManager(), - let stageWidth = self.stageWidth + let visualDetectionManager = self.getVisualDetectionManager() else { return type(of: self).defaultValue } let id = Int(idAsDouble) @@ -57,6 +58,8 @@ class WidthOfObjectWithIDFunction: SingleParameterDoubleFunction { } let boundingBoxWidth = visualDetectionManager.objectRecognitions[id].boundingBox.width + + stageWidth = Double(landscapeMode ? stageSize.height : stageSize.width) return stageWidth * boundingBoxWidth } diff --git a/src/Catty/Functions/ObjectRecognition/XOfObjectWithIDFunction.swift b/src/Catty/Functions/ObjectRecognition/XOfObjectWithIDFunction.swift index ad11be855d..01bf2ff4c0 100644 --- a/src/Catty/Functions/ObjectRecognition/XOfObjectWithIDFunction.swift +++ b/src/Catty/Functions/ObjectRecognition/XOfObjectWithIDFunction.swift @@ -20,7 +20,7 @@ * along with this program. If not, see http://www.gnu.org/licenses/. */ -class XOfObjectWithIDFunction: SingleParameterDoubleFunction { +class XOfObjectWithIDFunction: SingleParameterDoubleLandscapeFunction { static let tag = "X_OF_OBJECT_WITH_ID" static let name = kUIFEFunctionXOfObjectWithID @@ -30,10 +30,12 @@ class XOfObjectWithIDFunction: SingleParameterDoubleFunction { static let requiredResource = ResourceType.objectRecognition let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageWidth: Double? + let stageSize: CGSize + var stageWidth: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageWidth = Double(stageSize.width) } @@ -45,10 +47,9 @@ class XOfObjectWithIDFunction: SingleParameterDoubleFunction { .number(defaultValue: 1) } - func value(parameter: AnyObject?) -> Double { + func value(parameter: AnyObject?, landscapeMode: Bool) -> Double { guard let idAsDouble = parameter as? Double, - let visualDetectionManager = self.getVisualDetectionManager(), - let stageWidth = self.stageWidth + let visualDetectionManager = self.getVisualDetectionManager() else { return type(of: self).defaultValue } let id = Int(idAsDouble) @@ -59,6 +60,7 @@ class XOfObjectWithIDFunction: SingleParameterDoubleFunction { let boundingBox = visualDetectionManager.objectRecognitions[id].boundingBox let objectPositionX = boundingBox.origin.x + boundingBox.width / 2.0 + stageWidth = Double(landscapeMode ? stageSize.height : stageSize.width) return stageWidth * objectPositionX - stageWidth / 2.0 } diff --git a/src/Catty/Functions/ObjectRecognition/YOfObjectWithIDFunction.swift b/src/Catty/Functions/ObjectRecognition/YOfObjectWithIDFunction.swift index f5c1c78858..2d1a2f46e2 100644 --- a/src/Catty/Functions/ObjectRecognition/YOfObjectWithIDFunction.swift +++ b/src/Catty/Functions/ObjectRecognition/YOfObjectWithIDFunction.swift @@ -20,7 +20,7 @@ * along with this program. If not, see http://www.gnu.org/licenses/. */ -class YOfObjectWithIDFunction: SingleParameterDoubleFunction { +class YOfObjectWithIDFunction: SingleParameterDoubleLandscapeFunction { static let tag = "Y_OF_OBJECT_WITH_ID" static let name = kUIFEFunctionYOfObjectWithID @@ -30,10 +30,12 @@ class YOfObjectWithIDFunction: SingleParameterDoubleFunction { static let requiredResource = ResourceType.objectRecognition let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageHeight: Double? + let stageSize: CGSize + var stageHeight: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageHeight = Double(stageSize.height) } @@ -45,10 +47,9 @@ class YOfObjectWithIDFunction: SingleParameterDoubleFunction { .number(defaultValue: 1) } - func value(parameter: AnyObject?) -> Double { + func value(parameter: AnyObject?, landscapeMode: Bool) -> Double { guard let idAsDouble = parameter as? Double, - let visualDetectionManager = self.getVisualDetectionManager(), - let stageHeight = self.stageHeight + let visualDetectionManager = self.getVisualDetectionManager() else { return type(of: self).defaultValue } let id = Int(idAsDouble) @@ -59,6 +60,7 @@ class YOfObjectWithIDFunction: SingleParameterDoubleFunction { let boundingBox = visualDetectionManager.objectRecognitions[id].boundingBox let objectPositionY = boundingBox.origin.y + boundingBox.height / 2.0 + stageHeight = Double(landscapeMode ? stageSize.width : stageSize.height) return stageHeight * objectPositionY - stageHeight / 2.0 } diff --git a/src/Catty/Functions/Protocols/Function.swift b/src/Catty/Functions/Protocols/Function.swift index f020f508f9..233af90dbf 100644 --- a/src/Catty/Functions/Protocols/Function.swift +++ b/src/Catty/Functions/Protocols/Function.swift @@ -150,6 +150,10 @@ protocol SingleParameterDoubleFunction: DoubleFunction, SingleParameterFunctionP func value(parameter: AnyObject?) -> Double } +protocol SingleParameterDoubleLandscapeFunction: DoubleFunction, SingleParameterFunctionProtocol { + func value(parameter: AnyObject?, landscapeMode: Bool) -> Double +} + protocol DoubleParameterDoubleFunction: DoubleFunction, DoubleParameterFunctionProtocol { func value(firstParameter: AnyObject?, secondParameter: AnyObject?) -> Double } diff --git a/src/Catty/Functions/TextRecognition/TextBlockXFunction.swift b/src/Catty/Functions/TextRecognition/TextBlockXFunction.swift index 605605a2cf..24d274004c 100644 --- a/src/Catty/Functions/TextRecognition/TextBlockXFunction.swift +++ b/src/Catty/Functions/TextRecognition/TextBlockXFunction.swift @@ -20,7 +20,7 @@ * along with this program. If not, see http://www.gnu.org/licenses/. */ -class TextBlockXFunction: SingleParameterDoubleFunction { +class TextBlockXFunction: SingleParameterDoubleLandscapeFunction { static let tag = "TEXT_BLOCK_X" static let name = kUIFEFunctionTextBlockX @@ -30,10 +30,12 @@ class TextBlockXFunction: SingleParameterDoubleFunction { static let requiredResource = ResourceType.textRecognition let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageWidth: Double? + let stageSize: CGSize + var stageWidth: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageWidth = Double(stageSize.width) } @@ -45,10 +47,9 @@ class TextBlockXFunction: SingleParameterDoubleFunction { .number(defaultValue: 1) } - func value(parameter: AnyObject?) -> Double { + func value(parameter: AnyObject?, landscapeMode: Bool) -> Double { guard let textBlockNumberAsDouble = parameter as? Double, - let visualDetectionManager = self.getVisualDetectionManager(), - let stageWidth = self.stageWidth + let visualDetectionManager = self.getVisualDetectionManager() else { return type(of: self).defaultValue } let textBlockNumber = Int(textBlockNumberAsDouble) @@ -58,6 +59,7 @@ class TextBlockXFunction: SingleParameterDoubleFunction { let textBlockPositionX = visualDetectionManager.textBlockPosition[textBlockNumber - 1].x + stageWidth = Double(landscapeMode ? stageSize.height : stageSize.width) return stageWidth * textBlockPositionX - stageWidth / 2.0 } diff --git a/src/Catty/Functions/TextRecognition/TextBlockYFunction.swift b/src/Catty/Functions/TextRecognition/TextBlockYFunction.swift index e9aa75cb43..a0dfe31c67 100644 --- a/src/Catty/Functions/TextRecognition/TextBlockYFunction.swift +++ b/src/Catty/Functions/TextRecognition/TextBlockYFunction.swift @@ -20,7 +20,7 @@ * along with this program. If not, see http://www.gnu.org/licenses/. */ -class TextBlockYFunction: SingleParameterDoubleFunction { +class TextBlockYFunction: SingleParameterDoubleLandscapeFunction { static let tag = "TEXT_BLOCK_Y" static let name = kUIFEFunctionTextBlockY @@ -30,10 +30,12 @@ class TextBlockYFunction: SingleParameterDoubleFunction { static let requiredResource = ResourceType.textRecognition let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageHeight: Double? + let stageSize: CGSize + var stageHeight: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageHeight = Double(stageSize.height) } @@ -45,10 +47,9 @@ class TextBlockYFunction: SingleParameterDoubleFunction { .number(defaultValue: 1) } - func value(parameter: AnyObject?) -> Double { + func value(parameter: AnyObject?, landscapeMode: Bool) -> Double { guard let textBlockNumberAsDouble = parameter as? Double, - let visualDetectionManager = self.getVisualDetectionManager(), - let stageHeight = self.stageHeight + let visualDetectionManager = self.getVisualDetectionManager() else { return type(of: self).defaultValue } let textBlockNumber = Int(textBlockNumberAsDouble) @@ -57,6 +58,8 @@ class TextBlockYFunction: SingleParameterDoubleFunction { } let textBlockPositionY = visualDetectionManager.textBlockPosition[textBlockNumber - 1].y + + stageHeight = Double(landscapeMode ? stageSize.width : stageSize.height) return stageHeight * textBlockPositionY - stageHeight / 2.0 } diff --git a/src/Catty/PlayerEngine/Formula/FormulaManager.swift b/src/Catty/PlayerEngine/Formula/FormulaManager.swift index ecc45e29f1..91753bef32 100644 --- a/src/Catty/PlayerEngine/Formula/FormulaManager.swift +++ b/src/Catty/PlayerEngine/Formula/FormulaManager.swift @@ -59,7 +59,8 @@ import CoreMotion FormulaManager.buildFunctionManager(stageSize: stageSize, touchManager: touchManager, visualDetectionManager: visualDetectionManager, - bluetoothService: bluetoothService) + bluetoothService: bluetoothService, + landscapeMode: landscapeMode) let operatorManager = FormulaManager.buildOperatorManager() @@ -157,12 +158,15 @@ import CoreMotion private static func buildFunctionManager(stageSize: CGSize, touchManager: TouchManagerProtocol, visualDetectionManager: VisualDetectionManager, - bluetoothService: BluetoothService) -> FunctionManager { + bluetoothService: BluetoothService, + landscapeMode: Bool) -> FunctionManager { - FunctionManager(functions: CatrobatSetup.registeredFunctions(stageSize: stageSize, - touchManager: touchManager, - visualDetectionManager: visualDetectionManager, - bluetoothService: bluetoothService)) + let functions = CatrobatSetup.registeredFunctions(stageSize: stageSize, + touchManager: touchManager, + visualDetectionManager: visualDetectionManager, + bluetoothService: bluetoothService) + + return FunctionManager(functions: functions, landscapeMode: landscapeMode) } private static func buildOperatorManager() -> OperatorManagerProtocol { diff --git a/src/Catty/PlayerEngine/Sensors/BodyPose/LeftAnkleXSensor.swift b/src/Catty/PlayerEngine/Sensors/BodyPose/LeftAnkleXSensor.swift index 17858c3c7a..21097cef25 100644 --- a/src/Catty/PlayerEngine/Sensors/BodyPose/LeftAnkleXSensor.swift +++ b/src/Catty/PlayerEngine/Sensors/BodyPose/LeftAnkleXSensor.swift @@ -29,10 +29,12 @@ class LeftAnkleXSensor: DeviceDoubleSensor { static let requiredResource = ResourceType.bodyPoseDetection let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageWidth: Double? + let stageSize: CGSize + var stageWidth: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageWidth = Double(stageSize.width) } @@ -41,17 +43,13 @@ class LeftAnkleXSensor: DeviceDoubleSensor { } func rawValue(landscapeMode: Bool) -> Double { + stageWidth = Double(landscapeMode ? stageSize.height : stageSize.width) guard let positionX = self.getVisualDetectionManager()?.bodyPosePositionRatioDictionary[self.tag()] else { return type(of: self).defaultRawValue } return positionX } func convertToStandardized(rawValue: Double) -> Double { - if rawValue == type(of: self).defaultRawValue { - return rawValue - } - guard let stageWidth = self.stageWidth else { - return type(of: self).defaultRawValue } - return stageWidth * rawValue - stageWidth / 2.0 + stageWidth * rawValue - stageWidth / 2.0 } func formulaEditorSections(for spriteObject: SpriteObject) -> [FormulaEditorSection] { diff --git a/src/Catty/PlayerEngine/Sensors/BodyPose/LeftAnkleYSensor.swift b/src/Catty/PlayerEngine/Sensors/BodyPose/LeftAnkleYSensor.swift index 732b2b283a..90a6e256c7 100644 --- a/src/Catty/PlayerEngine/Sensors/BodyPose/LeftAnkleYSensor.swift +++ b/src/Catty/PlayerEngine/Sensors/BodyPose/LeftAnkleYSensor.swift @@ -29,10 +29,12 @@ class LeftAnkleYSensor: DeviceDoubleSensor { static let requiredResource = ResourceType.bodyPoseDetection let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageHeight: Double? + let stageSize: CGSize + var stageHeight: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageHeight = Double(stageSize.height) } @@ -41,16 +43,13 @@ class LeftAnkleYSensor: DeviceDoubleSensor { } func rawValue(landscapeMode: Bool) -> Double { + stageHeight = Double(landscapeMode ? stageSize.width : stageSize.height) guard let positionY = self.getVisualDetectionManager()?.bodyPosePositionRatioDictionary[self.tag()] else { return type(of: self).defaultRawValue } return positionY } func convertToStandardized(rawValue: Double) -> Double { - if rawValue == type(of: self).defaultRawValue { - return rawValue - } - guard let stageHeight = self.stageHeight else { return type(of: self).defaultRawValue } - return stageHeight * rawValue - stageHeight / 2.0 + stageHeight * rawValue - stageHeight / 2.0 } func formulaEditorSections(for spriteObject: SpriteObject) -> [FormulaEditorSection] { diff --git a/src/Catty/PlayerEngine/Sensors/BodyPose/LeftElbowXSensor.swift b/src/Catty/PlayerEngine/Sensors/BodyPose/LeftElbowXSensor.swift index ccabc25ce7..b3401efbc2 100644 --- a/src/Catty/PlayerEngine/Sensors/BodyPose/LeftElbowXSensor.swift +++ b/src/Catty/PlayerEngine/Sensors/BodyPose/LeftElbowXSensor.swift @@ -29,10 +29,12 @@ class LeftElbowXSensor: DeviceDoubleSensor { static let requiredResource = ResourceType.bodyPoseDetection let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageWidth: Double? + let stageSize: CGSize + var stageWidth: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageWidth = Double(stageSize.width) } @@ -41,17 +43,13 @@ class LeftElbowXSensor: DeviceDoubleSensor { } func rawValue(landscapeMode: Bool) -> Double { + stageWidth = Double(landscapeMode ? stageSize.height : stageSize.width) guard let positionX = self.getVisualDetectionManager()?.bodyPosePositionRatioDictionary[self.tag()] else { return type(of: self).defaultRawValue } return positionX } func convertToStandardized(rawValue: Double) -> Double { - if rawValue == type(of: self).defaultRawValue { - return rawValue - } - guard let stageWidth = self.stageWidth else { - return type(of: self).defaultRawValue } - return stageWidth * rawValue - stageWidth / 2.0 + stageWidth * rawValue - stageWidth / 2.0 } func formulaEditorSections(for spriteObject: SpriteObject) -> [FormulaEditorSection] { diff --git a/src/Catty/PlayerEngine/Sensors/BodyPose/LeftElbowYSensor.swift b/src/Catty/PlayerEngine/Sensors/BodyPose/LeftElbowYSensor.swift index 907780e032..3609f6739a 100644 --- a/src/Catty/PlayerEngine/Sensors/BodyPose/LeftElbowYSensor.swift +++ b/src/Catty/PlayerEngine/Sensors/BodyPose/LeftElbowYSensor.swift @@ -29,10 +29,12 @@ class LeftElbowYSensor: DeviceDoubleSensor { static let requiredResource = ResourceType.bodyPoseDetection let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageHeight: Double? + let stageSize: CGSize + var stageHeight: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageHeight = Double(stageSize.height) } @@ -41,16 +43,13 @@ class LeftElbowYSensor: DeviceDoubleSensor { } func rawValue(landscapeMode: Bool) -> Double { + stageHeight = Double(landscapeMode ? stageSize.width : stageSize.height) guard let positionY = self.getVisualDetectionManager()?.bodyPosePositionRatioDictionary[self.tag()] else { return type(of: self).defaultRawValue } return positionY } func convertToStandardized(rawValue: Double) -> Double { - if rawValue == type(of: self).defaultRawValue { - return rawValue - } - guard let stageHeight = self.stageHeight else { return type(of: self).defaultRawValue } - return stageHeight * rawValue - stageHeight / 2.0 + stageHeight * rawValue - stageHeight / 2.0 } func formulaEditorSections(for spriteObject: SpriteObject) -> [FormulaEditorSection] { diff --git a/src/Catty/PlayerEngine/Sensors/BodyPose/LeftHipXSensor.swift b/src/Catty/PlayerEngine/Sensors/BodyPose/LeftHipXSensor.swift index 3a4722bbd0..99cfcfdeb9 100644 --- a/src/Catty/PlayerEngine/Sensors/BodyPose/LeftHipXSensor.swift +++ b/src/Catty/PlayerEngine/Sensors/BodyPose/LeftHipXSensor.swift @@ -29,10 +29,12 @@ class LeftHipXSensor: DeviceDoubleSensor { static let requiredResource = ResourceType.bodyPoseDetection let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageWidth: Double? + let stageSize: CGSize + var stageWidth: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageWidth = Double(stageSize.width) } @@ -41,17 +43,13 @@ class LeftHipXSensor: DeviceDoubleSensor { } func rawValue(landscapeMode: Bool) -> Double { + stageWidth = Double(landscapeMode ? stageSize.height : stageSize.width) guard let positionX = self.getVisualDetectionManager()?.bodyPosePositionRatioDictionary[self.tag()] else { return type(of: self).defaultRawValue } return positionX } func convertToStandardized(rawValue: Double) -> Double { - if rawValue == type(of: self).defaultRawValue { - return rawValue - } - guard let stageWidth = self.stageWidth else { - return type(of: self).defaultRawValue } - return stageWidth * rawValue - stageWidth / 2.0 + stageWidth * rawValue - stageWidth / 2.0 } func formulaEditorSections(for spriteObject: SpriteObject) -> [FormulaEditorSection] { diff --git a/src/Catty/PlayerEngine/Sensors/BodyPose/LeftHipYSensor.swift b/src/Catty/PlayerEngine/Sensors/BodyPose/LeftHipYSensor.swift index 936dbc9fdb..f8c2f729c3 100644 --- a/src/Catty/PlayerEngine/Sensors/BodyPose/LeftHipYSensor.swift +++ b/src/Catty/PlayerEngine/Sensors/BodyPose/LeftHipYSensor.swift @@ -29,10 +29,12 @@ class LeftHipYSensor: DeviceDoubleSensor { static let requiredResource = ResourceType.bodyPoseDetection let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageHeight: Double? + let stageSize: CGSize + var stageHeight: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageHeight = Double(stageSize.height) } @@ -41,16 +43,13 @@ class LeftHipYSensor: DeviceDoubleSensor { } func rawValue(landscapeMode: Bool) -> Double { + stageHeight = Double(landscapeMode ? stageSize.width : stageSize.height) guard let positionY = self.getVisualDetectionManager()?.bodyPosePositionRatioDictionary[self.tag()] else { return type(of: self).defaultRawValue } return positionY } func convertToStandardized(rawValue: Double) -> Double { - if rawValue == type(of: self).defaultRawValue { - return rawValue - } - guard let stageHeight = self.stageHeight else { return type(of: self).defaultRawValue } - return stageHeight * rawValue - stageHeight / 2.0 + stageHeight * rawValue - stageHeight / 2.0 } func formulaEditorSections(for spriteObject: SpriteObject) -> [FormulaEditorSection] { diff --git a/src/Catty/PlayerEngine/Sensors/BodyPose/LeftKneeXSensor.swift b/src/Catty/PlayerEngine/Sensors/BodyPose/LeftKneeXSensor.swift index 8ecaf30053..c83bc7c243 100644 --- a/src/Catty/PlayerEngine/Sensors/BodyPose/LeftKneeXSensor.swift +++ b/src/Catty/PlayerEngine/Sensors/BodyPose/LeftKneeXSensor.swift @@ -29,10 +29,12 @@ class LeftKneeXSensor: DeviceDoubleSensor { static let requiredResource = ResourceType.bodyPoseDetection let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageWidth: Double? + let stageSize: CGSize + var stageWidth: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageWidth = Double(stageSize.width) } @@ -41,17 +43,13 @@ class LeftKneeXSensor: DeviceDoubleSensor { } func rawValue(landscapeMode: Bool) -> Double { + stageWidth = Double(landscapeMode ? stageSize.height : stageSize.width) guard let positionX = self.getVisualDetectionManager()?.bodyPosePositionRatioDictionary[self.tag()] else { return type(of: self).defaultRawValue } return positionX } func convertToStandardized(rawValue: Double) -> Double { - if rawValue == type(of: self).defaultRawValue { - return rawValue - } - guard let stageWidth = self.stageWidth else { - return type(of: self).defaultRawValue } - return stageWidth * rawValue - stageWidth / 2.0 + stageWidth * rawValue - stageWidth / 2.0 } func formulaEditorSections(for spriteObject: SpriteObject) -> [FormulaEditorSection] { diff --git a/src/Catty/PlayerEngine/Sensors/BodyPose/LeftKneeYSensor.swift b/src/Catty/PlayerEngine/Sensors/BodyPose/LeftKneeYSensor.swift index 51361dcbfe..81c71499df 100644 --- a/src/Catty/PlayerEngine/Sensors/BodyPose/LeftKneeYSensor.swift +++ b/src/Catty/PlayerEngine/Sensors/BodyPose/LeftKneeYSensor.swift @@ -29,10 +29,12 @@ class LeftKneeYSensor: DeviceDoubleSensor { static let requiredResource = ResourceType.bodyPoseDetection let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageHeight: Double? + let stageSize: CGSize + var stageHeight: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageHeight = Double(stageSize.height) } @@ -41,16 +43,13 @@ class LeftKneeYSensor: DeviceDoubleSensor { } func rawValue(landscapeMode: Bool) -> Double { + stageHeight = Double(landscapeMode ? stageSize.width : stageSize.height) guard let positionY = self.getVisualDetectionManager()?.bodyPosePositionRatioDictionary[self.tag()] else { return type(of: self).defaultRawValue } return positionY } func convertToStandardized(rawValue: Double) -> Double { - if rawValue == type(of: self).defaultRawValue { - return rawValue - } - guard let stageHeight = self.stageHeight else { return type(of: self).defaultRawValue } - return stageHeight * rawValue - stageHeight / 2.0 + stageHeight * rawValue - stageHeight / 2.0 } func formulaEditorSections(for spriteObject: SpriteObject) -> [FormulaEditorSection] { diff --git a/src/Catty/PlayerEngine/Sensors/BodyPose/LeftShoulderXSensor.swift b/src/Catty/PlayerEngine/Sensors/BodyPose/LeftShoulderXSensor.swift index 45c776ab5f..7a4f681322 100644 --- a/src/Catty/PlayerEngine/Sensors/BodyPose/LeftShoulderXSensor.swift +++ b/src/Catty/PlayerEngine/Sensors/BodyPose/LeftShoulderXSensor.swift @@ -29,10 +29,12 @@ class LeftShoulderXSensor: DeviceDoubleSensor { static let requiredResource = ResourceType.bodyPoseDetection let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageWidth: Double? + let stageSize: CGSize + var stageWidth: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageWidth = Double(stageSize.width) } @@ -41,17 +43,13 @@ class LeftShoulderXSensor: DeviceDoubleSensor { } func rawValue(landscapeMode: Bool) -> Double { + stageWidth = Double(landscapeMode ? stageSize.height : stageSize.width) guard let positionX = self.getVisualDetectionManager()?.bodyPosePositionRatioDictionary[self.tag()] else { return type(of: self).defaultRawValue } return positionX } func convertToStandardized(rawValue: Double) -> Double { - if rawValue == type(of: self).defaultRawValue { - return rawValue - } - guard let stageWidth = self.stageWidth else { - return type(of: self).defaultRawValue } - return stageWidth * rawValue - stageWidth / 2.0 + stageWidth * rawValue - stageWidth / 2.0 } func formulaEditorSections(for spriteObject: SpriteObject) -> [FormulaEditorSection] { diff --git a/src/Catty/PlayerEngine/Sensors/BodyPose/LeftShoulderYSensor.swift b/src/Catty/PlayerEngine/Sensors/BodyPose/LeftShoulderYSensor.swift index 8c66321811..5ffd331def 100644 --- a/src/Catty/PlayerEngine/Sensors/BodyPose/LeftShoulderYSensor.swift +++ b/src/Catty/PlayerEngine/Sensors/BodyPose/LeftShoulderYSensor.swift @@ -29,10 +29,12 @@ class LeftShoulderYSensor: DeviceDoubleSensor { static let requiredResource = ResourceType.bodyPoseDetection let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageHeight: Double? + let stageSize: CGSize + var stageHeight: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageHeight = Double(stageSize.height) } @@ -41,16 +43,13 @@ class LeftShoulderYSensor: DeviceDoubleSensor { } func rawValue(landscapeMode: Bool) -> Double { + stageHeight = Double(landscapeMode ? stageSize.width : stageSize.height) guard let positionY = self.getVisualDetectionManager()?.bodyPosePositionRatioDictionary[self.tag()] else { return type(of: self).defaultRawValue } return positionY } func convertToStandardized(rawValue: Double) -> Double { - if rawValue == type(of: self).defaultRawValue { - return rawValue - } - guard let stageHeight = self.stageHeight else { return type(of: self).defaultRawValue } - return stageHeight * rawValue - stageHeight / 2.0 + stageHeight * rawValue - stageHeight / 2.0 } func formulaEditorSections(for spriteObject: SpriteObject) -> [FormulaEditorSection] { diff --git a/src/Catty/PlayerEngine/Sensors/BodyPose/LeftWristXSensor.swift b/src/Catty/PlayerEngine/Sensors/BodyPose/LeftWristXSensor.swift index 1b6a3d8792..596695a861 100644 --- a/src/Catty/PlayerEngine/Sensors/BodyPose/LeftWristXSensor.swift +++ b/src/Catty/PlayerEngine/Sensors/BodyPose/LeftWristXSensor.swift @@ -29,10 +29,12 @@ class LeftWristXSensor: DeviceDoubleSensor { static let requiredResource = ResourceType.bodyPoseDetection let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageWidth: Double? + let stageSize: CGSize + var stageWidth: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageWidth = Double(stageSize.width) } @@ -41,17 +43,13 @@ class LeftWristXSensor: DeviceDoubleSensor { } func rawValue(landscapeMode: Bool) -> Double { + stageWidth = Double(landscapeMode ? stageSize.height : stageSize.width) guard let positionX = self.getVisualDetectionManager()?.bodyPosePositionRatioDictionary[self.tag()] else { return type(of: self).defaultRawValue } return positionX } func convertToStandardized(rawValue: Double) -> Double { - if rawValue == type(of: self).defaultRawValue { - return rawValue - } - guard let stageWidth = self.stageWidth else { - return type(of: self).defaultRawValue } - return stageWidth * rawValue - stageWidth / 2.0 + stageWidth * rawValue - stageWidth / 2.0 } func formulaEditorSections(for spriteObject: SpriteObject) -> [FormulaEditorSection] { diff --git a/src/Catty/PlayerEngine/Sensors/BodyPose/LeftWristYSensor.swift b/src/Catty/PlayerEngine/Sensors/BodyPose/LeftWristYSensor.swift index 7d15526019..3faf45da86 100644 --- a/src/Catty/PlayerEngine/Sensors/BodyPose/LeftWristYSensor.swift +++ b/src/Catty/PlayerEngine/Sensors/BodyPose/LeftWristYSensor.swift @@ -29,10 +29,12 @@ class LeftWristYSensor: DeviceDoubleSensor { static let requiredResource = ResourceType.bodyPoseDetection let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageHeight: Double? + let stageSize: CGSize + var stageHeight: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageHeight = Double(stageSize.height) } @@ -41,16 +43,13 @@ class LeftWristYSensor: DeviceDoubleSensor { } func rawValue(landscapeMode: Bool) -> Double { + stageHeight = Double(landscapeMode ? stageSize.width : stageSize.height) guard let positionY = self.getVisualDetectionManager()?.bodyPosePositionRatioDictionary[self.tag()] else { return type(of: self).defaultRawValue } return positionY } func convertToStandardized(rawValue: Double) -> Double { - if rawValue == type(of: self).defaultRawValue { - return rawValue - } - guard let stageHeight = self.stageHeight else { return type(of: self).defaultRawValue } - return stageHeight * rawValue - stageHeight / 2.0 + stageHeight * rawValue - stageHeight / 2.0 } func formulaEditorSections(for spriteObject: SpriteObject) -> [FormulaEditorSection] { diff --git a/src/Catty/PlayerEngine/Sensors/BodyPose/NeckXSensor.swift b/src/Catty/PlayerEngine/Sensors/BodyPose/NeckXSensor.swift index 19a89cc6f6..b9ba39388d 100644 --- a/src/Catty/PlayerEngine/Sensors/BodyPose/NeckXSensor.swift +++ b/src/Catty/PlayerEngine/Sensors/BodyPose/NeckXSensor.swift @@ -29,10 +29,12 @@ class NeckXSensor: DeviceDoubleSensor { static let requiredResource = ResourceType.bodyPoseDetection let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageWidth: Double? + let stageSize: CGSize + var stageWidth: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageWidth = Double(stageSize.width) } @@ -41,17 +43,13 @@ class NeckXSensor: DeviceDoubleSensor { } func rawValue(landscapeMode: Bool) -> Double { + stageWidth = Double(landscapeMode ? stageSize.height : stageSize.width) guard let positionX = self.getVisualDetectionManager()?.bodyPosePositionRatioDictionary[self.tag()] else { return type(of: self).defaultRawValue } return positionX } func convertToStandardized(rawValue: Double) -> Double { - if rawValue == type(of: self).defaultRawValue { - return rawValue - } - guard let stageWidth = self.stageWidth else { - return type(of: self).defaultRawValue } - return stageWidth * rawValue - stageWidth / 2.0 + stageWidth * rawValue - stageWidth / 2.0 } func formulaEditorSections(for spriteObject: SpriteObject) -> [FormulaEditorSection] { diff --git a/src/Catty/PlayerEngine/Sensors/BodyPose/NeckYSensor.swift b/src/Catty/PlayerEngine/Sensors/BodyPose/NeckYSensor.swift index 5fec9c5620..5ce78a4d41 100644 --- a/src/Catty/PlayerEngine/Sensors/BodyPose/NeckYSensor.swift +++ b/src/Catty/PlayerEngine/Sensors/BodyPose/NeckYSensor.swift @@ -29,10 +29,12 @@ class NeckYSensor: DeviceDoubleSensor { static let requiredResource = ResourceType.bodyPoseDetection let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageHeight: Double? + let stageSize: CGSize + var stageHeight: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageHeight = Double(stageSize.height) } @@ -41,16 +43,13 @@ class NeckYSensor: DeviceDoubleSensor { } func rawValue(landscapeMode: Bool) -> Double { + stageHeight = Double(landscapeMode ? stageSize.width : stageSize.height) guard let positionY = self.getVisualDetectionManager()?.bodyPosePositionRatioDictionary[self.tag()] else { return type(of: self).defaultRawValue } return positionY } func convertToStandardized(rawValue: Double) -> Double { - if rawValue == type(of: self).defaultRawValue { - return rawValue - } - guard let stageHeight = self.stageHeight else { return type(of: self).defaultRawValue } - return stageHeight * rawValue - stageHeight / 2.0 + stageHeight * rawValue - stageHeight / 2.0 } func formulaEditorSections(for spriteObject: SpriteObject) -> [FormulaEditorSection] { diff --git a/src/Catty/PlayerEngine/Sensors/BodyPose/RightAnkleXSensor.swift b/src/Catty/PlayerEngine/Sensors/BodyPose/RightAnkleXSensor.swift index 1e6b8a19fa..1e576d9a2f 100644 --- a/src/Catty/PlayerEngine/Sensors/BodyPose/RightAnkleXSensor.swift +++ b/src/Catty/PlayerEngine/Sensors/BodyPose/RightAnkleXSensor.swift @@ -29,10 +29,12 @@ class RightAnkleXSensor: DeviceDoubleSensor { static let requiredResource = ResourceType.bodyPoseDetection let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageWidth: Double? + let stageSize: CGSize + var stageWidth: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageWidth = Double(stageSize.width) } @@ -41,17 +43,13 @@ class RightAnkleXSensor: DeviceDoubleSensor { } func rawValue(landscapeMode: Bool) -> Double { + stageWidth = Double(landscapeMode ? stageSize.height : stageSize.width) guard let positionX = self.getVisualDetectionManager()?.bodyPosePositionRatioDictionary[self.tag()] else { return type(of: self).defaultRawValue } return positionX } func convertToStandardized(rawValue: Double) -> Double { - if rawValue == type(of: self).defaultRawValue { - return rawValue - } - guard let stageWidth = self.stageWidth else { - return type(of: self).defaultRawValue } - return stageWidth * rawValue - stageWidth / 2.0 + stageWidth * rawValue - stageWidth / 2.0 } func formulaEditorSections(for spriteObject: SpriteObject) -> [FormulaEditorSection] { diff --git a/src/Catty/PlayerEngine/Sensors/BodyPose/RightAnkleYSensor.swift b/src/Catty/PlayerEngine/Sensors/BodyPose/RightAnkleYSensor.swift index 5720286c89..9286b2ab22 100644 --- a/src/Catty/PlayerEngine/Sensors/BodyPose/RightAnkleYSensor.swift +++ b/src/Catty/PlayerEngine/Sensors/BodyPose/RightAnkleYSensor.swift @@ -29,10 +29,12 @@ class RightAnkleYSensor: DeviceDoubleSensor { static let requiredResource = ResourceType.bodyPoseDetection let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageHeight: Double? + let stageSize: CGSize + var stageHeight: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageHeight = Double(stageSize.height) } @@ -41,16 +43,13 @@ class RightAnkleYSensor: DeviceDoubleSensor { } func rawValue(landscapeMode: Bool) -> Double { + stageHeight = Double(landscapeMode ? stageSize.width : stageSize.height) guard let positionY = self.getVisualDetectionManager()?.bodyPosePositionRatioDictionary[self.tag()] else { return type(of: self).defaultRawValue } return positionY } func convertToStandardized(rawValue: Double) -> Double { - if rawValue == type(of: self).defaultRawValue { - return rawValue - } - guard let stageHeight = self.stageHeight else { return type(of: self).defaultRawValue } - return stageHeight * rawValue - stageHeight / 2.0 + stageHeight * rawValue - stageHeight / 2.0 } func formulaEditorSections(for spriteObject: SpriteObject) -> [FormulaEditorSection] { diff --git a/src/Catty/PlayerEngine/Sensors/BodyPose/RightElbowXSensor.swift b/src/Catty/PlayerEngine/Sensors/BodyPose/RightElbowXSensor.swift index 237c068456..1506ca4b57 100644 --- a/src/Catty/PlayerEngine/Sensors/BodyPose/RightElbowXSensor.swift +++ b/src/Catty/PlayerEngine/Sensors/BodyPose/RightElbowXSensor.swift @@ -29,10 +29,12 @@ class RightElbowXSensor: DeviceDoubleSensor { static let requiredResource = ResourceType.bodyPoseDetection let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageWidth: Double? + let stageSize: CGSize + var stageWidth: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageWidth = Double(stageSize.width) } @@ -41,17 +43,13 @@ class RightElbowXSensor: DeviceDoubleSensor { } func rawValue(landscapeMode: Bool) -> Double { + stageWidth = Double(landscapeMode ? stageSize.height : stageSize.width) guard let positionX = self.getVisualDetectionManager()?.bodyPosePositionRatioDictionary[self.tag()] else { return type(of: self).defaultRawValue } return positionX } func convertToStandardized(rawValue: Double) -> Double { - if rawValue == type(of: self).defaultRawValue { - return rawValue - } - guard let stageWidth = self.stageWidth else { - return type(of: self).defaultRawValue } - return stageWidth * rawValue - stageWidth / 2.0 + stageWidth * rawValue - stageWidth / 2.0 } func formulaEditorSections(for spriteObject: SpriteObject) -> [FormulaEditorSection] { diff --git a/src/Catty/PlayerEngine/Sensors/BodyPose/RightElbowYSensor.swift b/src/Catty/PlayerEngine/Sensors/BodyPose/RightElbowYSensor.swift index f40ce68dcf..85314e10f6 100644 --- a/src/Catty/PlayerEngine/Sensors/BodyPose/RightElbowYSensor.swift +++ b/src/Catty/PlayerEngine/Sensors/BodyPose/RightElbowYSensor.swift @@ -29,10 +29,12 @@ class RightElbowYSensor: DeviceDoubleSensor { static let requiredResource = ResourceType.bodyPoseDetection let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageHeight: Double? + let stageSize: CGSize + var stageHeight: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageHeight = Double(stageSize.height) } @@ -41,16 +43,13 @@ class RightElbowYSensor: DeviceDoubleSensor { } func rawValue(landscapeMode: Bool) -> Double { + stageHeight = Double(landscapeMode ? stageSize.width : stageSize.height) guard let positionY = self.getVisualDetectionManager()?.bodyPosePositionRatioDictionary[self.tag()] else { return type(of: self).defaultRawValue } return positionY } func convertToStandardized(rawValue: Double) -> Double { - if rawValue == type(of: self).defaultRawValue { - return rawValue - } - guard let stageHeight = self.stageHeight else { return type(of: self).defaultRawValue } - return stageHeight * rawValue - stageHeight / 2.0 + stageHeight * rawValue - stageHeight / 2.0 } func formulaEditorSections(for spriteObject: SpriteObject) -> [FormulaEditorSection] { diff --git a/src/Catty/PlayerEngine/Sensors/BodyPose/RightHipXSensor.swift b/src/Catty/PlayerEngine/Sensors/BodyPose/RightHipXSensor.swift index 2846a74336..2aefa4eae1 100644 --- a/src/Catty/PlayerEngine/Sensors/BodyPose/RightHipXSensor.swift +++ b/src/Catty/PlayerEngine/Sensors/BodyPose/RightHipXSensor.swift @@ -29,10 +29,12 @@ class RightHipXSensor: DeviceDoubleSensor { static let requiredResource = ResourceType.bodyPoseDetection let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageWidth: Double? + let stageSize: CGSize + var stageWidth: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageWidth = Double(stageSize.width) } @@ -41,17 +43,13 @@ class RightHipXSensor: DeviceDoubleSensor { } func rawValue(landscapeMode: Bool) -> Double { + stageWidth = Double(landscapeMode ? stageSize.height : stageSize.width) guard let positionX = self.getVisualDetectionManager()?.bodyPosePositionRatioDictionary[self.tag()] else { return type(of: self).defaultRawValue } return positionX } func convertToStandardized(rawValue: Double) -> Double { - if rawValue == type(of: self).defaultRawValue { - return rawValue - } - guard let stageWidth = self.stageWidth else { - return type(of: self).defaultRawValue } - return stageWidth * rawValue - stageWidth / 2.0 + stageWidth * rawValue - stageWidth / 2.0 } func formulaEditorSections(for spriteObject: SpriteObject) -> [FormulaEditorSection] { diff --git a/src/Catty/PlayerEngine/Sensors/BodyPose/RightHipYSensor.swift b/src/Catty/PlayerEngine/Sensors/BodyPose/RightHipYSensor.swift index 87b93176b2..ed7f9fade9 100644 --- a/src/Catty/PlayerEngine/Sensors/BodyPose/RightHipYSensor.swift +++ b/src/Catty/PlayerEngine/Sensors/BodyPose/RightHipYSensor.swift @@ -29,10 +29,12 @@ class RightHipYSensor: DeviceDoubleSensor { static let requiredResource = ResourceType.bodyPoseDetection let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageHeight: Double? + let stageSize: CGSize + var stageHeight: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageHeight = Double(stageSize.height) } @@ -41,16 +43,13 @@ class RightHipYSensor: DeviceDoubleSensor { } func rawValue(landscapeMode: Bool) -> Double { + stageHeight = Double(landscapeMode ? stageSize.width : stageSize.height) guard let positionY = self.getVisualDetectionManager()?.bodyPosePositionRatioDictionary[self.tag()] else { return type(of: self).defaultRawValue } return positionY } func convertToStandardized(rawValue: Double) -> Double { - if rawValue == type(of: self).defaultRawValue { - return rawValue - } - guard let stageHeight = self.stageHeight else { return type(of: self).defaultRawValue } - return stageHeight * rawValue - stageHeight / 2.0 + stageHeight * rawValue - stageHeight / 2.0 } func formulaEditorSections(for spriteObject: SpriteObject) -> [FormulaEditorSection] { diff --git a/src/Catty/PlayerEngine/Sensors/BodyPose/RightKneeXSensor.swift b/src/Catty/PlayerEngine/Sensors/BodyPose/RightKneeXSensor.swift index 00efd814e8..4de99027a7 100644 --- a/src/Catty/PlayerEngine/Sensors/BodyPose/RightKneeXSensor.swift +++ b/src/Catty/PlayerEngine/Sensors/BodyPose/RightKneeXSensor.swift @@ -29,10 +29,12 @@ class RightKneeXSensor: DeviceDoubleSensor { static let requiredResource = ResourceType.bodyPoseDetection let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageWidth: Double? + let stageSize: CGSize + var stageWidth: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageWidth = Double(stageSize.width) } @@ -41,17 +43,13 @@ class RightKneeXSensor: DeviceDoubleSensor { } func rawValue(landscapeMode: Bool) -> Double { + stageWidth = Double(landscapeMode ? stageSize.height : stageSize.width) guard let positionX = self.getVisualDetectionManager()?.bodyPosePositionRatioDictionary[self.tag()] else { return type(of: self).defaultRawValue } return positionX } func convertToStandardized(rawValue: Double) -> Double { - if rawValue == type(of: self).defaultRawValue { - return rawValue - } - guard let stageWidth = self.stageWidth else { - return type(of: self).defaultRawValue } - return stageWidth * rawValue - stageWidth / 2.0 + stageWidth * rawValue - stageWidth / 2.0 } func formulaEditorSections(for spriteObject: SpriteObject) -> [FormulaEditorSection] { diff --git a/src/Catty/PlayerEngine/Sensors/BodyPose/RightKneeYSensor.swift b/src/Catty/PlayerEngine/Sensors/BodyPose/RightKneeYSensor.swift index 395b173e85..768a25d48a 100644 --- a/src/Catty/PlayerEngine/Sensors/BodyPose/RightKneeYSensor.swift +++ b/src/Catty/PlayerEngine/Sensors/BodyPose/RightKneeYSensor.swift @@ -29,10 +29,12 @@ class RightKneeYSensor: DeviceDoubleSensor { static let requiredResource = ResourceType.bodyPoseDetection let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageHeight: Double? + let stageSize: CGSize + var stageHeight: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageHeight = Double(stageSize.height) } @@ -41,16 +43,13 @@ class RightKneeYSensor: DeviceDoubleSensor { } func rawValue(landscapeMode: Bool) -> Double { + stageHeight = Double(landscapeMode ? stageSize.width : stageSize.height) guard let positionY = self.getVisualDetectionManager()?.bodyPosePositionRatioDictionary[self.tag()] else { return type(of: self).defaultRawValue } return positionY } func convertToStandardized(rawValue: Double) -> Double { - if rawValue == type(of: self).defaultRawValue { - return rawValue - } - guard let stageHeight = self.stageHeight else { return type(of: self).defaultRawValue } - return stageHeight * rawValue - stageHeight / 2.0 + stageHeight * rawValue - stageHeight / 2.0 } func formulaEditorSections(for spriteObject: SpriteObject) -> [FormulaEditorSection] { diff --git a/src/Catty/PlayerEngine/Sensors/BodyPose/RightShoulderXSensor.swift b/src/Catty/PlayerEngine/Sensors/BodyPose/RightShoulderXSensor.swift index dcfc17afd0..69fd33fa87 100644 --- a/src/Catty/PlayerEngine/Sensors/BodyPose/RightShoulderXSensor.swift +++ b/src/Catty/PlayerEngine/Sensors/BodyPose/RightShoulderXSensor.swift @@ -29,10 +29,12 @@ class RightShoulderXSensor: DeviceDoubleSensor { static let requiredResource = ResourceType.bodyPoseDetection let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageWidth: Double? + let stageSize: CGSize + var stageWidth: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageWidth = Double(stageSize.width) } @@ -41,17 +43,13 @@ class RightShoulderXSensor: DeviceDoubleSensor { } func rawValue(landscapeMode: Bool) -> Double { + stageWidth = Double(landscapeMode ? stageSize.height : stageSize.width) guard let positionX = self.getVisualDetectionManager()?.bodyPosePositionRatioDictionary[self.tag()] else { return type(of: self).defaultRawValue } return positionX } func convertToStandardized(rawValue: Double) -> Double { - if rawValue == type(of: self).defaultRawValue { - return rawValue - } - guard let stageWidth = self.stageWidth else { - return type(of: self).defaultRawValue } - return stageWidth * rawValue - stageWidth / 2.0 + stageWidth * rawValue - stageWidth / 2.0 } func formulaEditorSections(for spriteObject: SpriteObject) -> [FormulaEditorSection] { diff --git a/src/Catty/PlayerEngine/Sensors/BodyPose/RightShoulderYSensor.swift b/src/Catty/PlayerEngine/Sensors/BodyPose/RightShoulderYSensor.swift index effdbc4423..96df2a0019 100644 --- a/src/Catty/PlayerEngine/Sensors/BodyPose/RightShoulderYSensor.swift +++ b/src/Catty/PlayerEngine/Sensors/BodyPose/RightShoulderYSensor.swift @@ -29,10 +29,12 @@ class RightShoulderYSensor: DeviceDoubleSensor { static let requiredResource = ResourceType.bodyPoseDetection let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageHeight: Double? + let stageSize: CGSize + var stageHeight: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageHeight = Double(stageSize.height) } @@ -41,16 +43,13 @@ class RightShoulderYSensor: DeviceDoubleSensor { } func rawValue(landscapeMode: Bool) -> Double { + stageHeight = Double(landscapeMode ? stageSize.width : stageSize.height) guard let positionY = self.getVisualDetectionManager()?.bodyPosePositionRatioDictionary[self.tag()] else { return type(of: self).defaultRawValue } return positionY } func convertToStandardized(rawValue: Double) -> Double { - if rawValue == type(of: self).defaultRawValue { - return rawValue - } - guard let stageHeight = self.stageHeight else { return type(of: self).defaultRawValue } - return stageHeight * rawValue - stageHeight / 2.0 + stageHeight * rawValue - stageHeight / 2.0 } func formulaEditorSections(for spriteObject: SpriteObject) -> [FormulaEditorSection] { diff --git a/src/Catty/PlayerEngine/Sensors/BodyPose/RightWristXSensor.swift b/src/Catty/PlayerEngine/Sensors/BodyPose/RightWristXSensor.swift index c74847418c..af6886c572 100644 --- a/src/Catty/PlayerEngine/Sensors/BodyPose/RightWristXSensor.swift +++ b/src/Catty/PlayerEngine/Sensors/BodyPose/RightWristXSensor.swift @@ -29,10 +29,12 @@ class RightWristXSensor: DeviceDoubleSensor { static let requiredResource = ResourceType.bodyPoseDetection let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageWidth: Double? + let stageSize: CGSize + var stageWidth: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageWidth = Double(stageSize.width) } @@ -41,17 +43,13 @@ class RightWristXSensor: DeviceDoubleSensor { } func rawValue(landscapeMode: Bool) -> Double { + stageWidth = Double(landscapeMode ? stageSize.height : stageSize.width) guard let positionX = self.getVisualDetectionManager()?.bodyPosePositionRatioDictionary[self.tag()] else { return type(of: self).defaultRawValue } return positionX } func convertToStandardized(rawValue: Double) -> Double { - if rawValue == type(of: self).defaultRawValue { - return rawValue - } - guard let stageWidth = self.stageWidth else { - return type(of: self).defaultRawValue } - return stageWidth * rawValue - stageWidth / 2.0 + stageWidth * rawValue - stageWidth / 2.0 } func formulaEditorSections(for spriteObject: SpriteObject) -> [FormulaEditorSection] { diff --git a/src/Catty/PlayerEngine/Sensors/BodyPose/RightWristYSensor.swift b/src/Catty/PlayerEngine/Sensors/BodyPose/RightWristYSensor.swift index dc8705a071..1c2bc23f7e 100644 --- a/src/Catty/PlayerEngine/Sensors/BodyPose/RightWristYSensor.swift +++ b/src/Catty/PlayerEngine/Sensors/BodyPose/RightWristYSensor.swift @@ -29,10 +29,12 @@ class RightWristYSensor: DeviceDoubleSensor { static let requiredResource = ResourceType.bodyPoseDetection let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageHeight: Double? + let stageSize: CGSize + var stageHeight: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageHeight = Double(stageSize.height) } @@ -41,16 +43,13 @@ class RightWristYSensor: DeviceDoubleSensor { } func rawValue(landscapeMode: Bool) -> Double { + stageHeight = Double(landscapeMode ? stageSize.width : stageSize.height) guard let positionY = self.getVisualDetectionManager()?.bodyPosePositionRatioDictionary[self.tag()] else { return type(of: self).defaultRawValue } return positionY } func convertToStandardized(rawValue: Double) -> Double { - if rawValue == type(of: self).defaultRawValue { - return rawValue - } - guard let stageHeight = self.stageHeight else { return type(of: self).defaultRawValue } - return stageHeight * rawValue - stageHeight / 2.0 + stageHeight * rawValue - stageHeight / 2.0 } func formulaEditorSections(for spriteObject: SpriteObject) -> [FormulaEditorSection] { diff --git a/src/Catty/PlayerEngine/Sensors/DetectionManager/VisualDetectionManager.swift b/src/Catty/PlayerEngine/Sensors/DetectionManager/VisualDetectionManager.swift index 915380b373..e6cd690e9f 100644 --- a/src/Catty/PlayerEngine/Sensors/DetectionManager/VisualDetectionManager.swift +++ b/src/Catty/PlayerEngine/Sensors/DetectionManager/VisualDetectionManager.swift @@ -238,38 +238,47 @@ class VisualDetectionManager: NSObject, VisualDetectionManagerProtocol, AVCaptur return true } - func cropVideoBuffer(inputBuffer: CVPixelBuffer) -> CVPixelBuffer { + func cropVideoBuffer(inputBuffer: CVPixelBuffer, isLandscape: Bool) -> CVPixelBuffer { CVPixelBufferLockBaseAddress(inputBuffer, .readOnly) guard let baseAddress = CVPixelBufferGetBaseAddress(inputBuffer) else { return inputBuffer } let baseAddressStart = baseAddress.assumingMemoryBound(to: UInt8.self) let bytesPerRow = CVPixelBufferGetBytesPerRow(inputBuffer) - let pixelFormat = CVPixelBufferGetPixelFormatType(inputBuffer) let pixelBufferWidth = CGFloat(CVPixelBufferGetWidth(inputBuffer)) let pixelBufferHeight = CGFloat(CVPixelBufferGetHeight(inputBuffer)) + guard let stageWidth = self.stage?.frame.width else { return inputBuffer } guard let stageHeight = self.stage?.frame.height else { return inputBuffer } + var newBuffer: CVPixelBuffer! + var croppedWidth = pixelBufferWidth + var croppedHeight = pixelBufferHeight + var cropX = 0 + var cropY = 0 - let croppedWidth = pixelBufferHeight / stageHeight * pixelBufferWidth + if isLandscape { + croppedHeight = pixelBufferWidth / stageWidth * pixelBufferHeight - var cropX = Int((pixelBufferWidth - CGFloat(croppedWidth)) / 2.0) - if cropX % 2 != 0 { - cropX += 1 + cropY = Int((pixelBufferHeight - CGFloat(croppedHeight)) / 2.0) + } else { + croppedWidth = pixelBufferHeight / stageHeight * pixelBufferWidth + + cropX = Int((pixelBufferWidth - CGFloat(croppedWidth)) / 2.0) + if cropX % 2 != 0 { + cropX += 1 + } } - let cropStartOffset = Int(CGFloat(cropX) * (CGFloat(bytesPerRow) / pixelBufferWidth)) + let cropStartOffset = Int(CGFloat(cropX) * (CGFloat(bytesPerRow) / pixelBufferWidth) + CGFloat(cropY) * CGFloat(bytesPerRow)) let options = [ kCVPixelBufferCGImageCompatibilityKey: true, kCVPixelBufferCGBitmapContextCompatibilityKey: true, kCVPixelBufferWidthKey: croppedWidth, - kCVPixelBufferHeightKey: pixelBufferHeight + kCVPixelBufferHeightKey: croppedHeight ] as [CFString: Any] - var newBuffer: CVPixelBuffer! - CVPixelBufferCreateWithBytes(kCFAllocatorDefault, Int(croppedWidth), - Int(pixelBufferHeight), + Int(croppedHeight), pixelFormat, &baseAddressStart[cropStartOffset], Int(bytesPerRow), @@ -284,18 +293,18 @@ class VisualDetectionManager: NSObject, VisualDetectionManagerProtocol, AVCaptur func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) { guard let pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer) else { return } - - if connection.isVideoOrientationSupported && !Project.lastUsed().header.landscapeMode && connection.videoOrientation != .portrait { + let isLandscape = Project.lastUsed().header.landscapeMode + if connection.isVideoOrientationSupported && !isLandscape && connection.videoOrientation != .portrait { connection.videoOrientation = .portrait return } - if connection.isVideoOrientationSupported && Project.lastUsed().header.landscapeMode && connection.videoOrientation != .landscapeRight { + if connection.isVideoOrientationSupported && isLandscape && connection.videoOrientation != .landscapeRight { connection.videoOrientation = .landscapeRight return } - let newBuffer = self.cropVideoBuffer(inputBuffer: pixelBuffer) + let newBuffer = self.cropVideoBuffer(inputBuffer: pixelBuffer, isLandscape: isLandscape) var orientation = CGImagePropertyOrientation.up if cameraPosition() == .front { diff --git a/src/Catty/PlayerEngine/Sensors/Face/FacePositionXSensor.swift b/src/Catty/PlayerEngine/Sensors/Face/FacePositionXSensor.swift index 9a68b6cd89..aafba29809 100644 --- a/src/Catty/PlayerEngine/Sensors/Face/FacePositionXSensor.swift +++ b/src/Catty/PlayerEngine/Sensors/Face/FacePositionXSensor.swift @@ -29,10 +29,12 @@ class FacePositionXSensor: DeviceDoubleSensor { static let requiredResource = ResourceType.faceDetection let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageWidth: Double? + let stageSize: CGSize + var stageWidth: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageWidth = Double(stageSize.width) } @@ -41,17 +43,13 @@ class FacePositionXSensor: DeviceDoubleSensor { } func rawValue(landscapeMode: Bool) -> Double { + stageWidth = Double(landscapeMode ? stageSize.height : stageSize.width) guard let positionX = self.getVisualDetectionManager()?.facePositionXRatio[0] else { return type(of: self).defaultRawValue } return positionX } func convertToStandardized(rawValue: Double) -> Double { - if rawValue == type(of: self).defaultRawValue { - return rawValue - } - guard let stageWidth = self.stageWidth else { - return type(of: self).defaultRawValue } - return stageWidth * rawValue - stageWidth / 2.0 + stageWidth * rawValue - stageWidth / 2.0 } func formulaEditorSections(for spriteObject: SpriteObject) -> [FormulaEditorSection] { diff --git a/src/Catty/PlayerEngine/Sensors/Face/FacePositionYSensor.swift b/src/Catty/PlayerEngine/Sensors/Face/FacePositionYSensor.swift index 0aae1b85c0..e881a4e250 100644 --- a/src/Catty/PlayerEngine/Sensors/Face/FacePositionYSensor.swift +++ b/src/Catty/PlayerEngine/Sensors/Face/FacePositionYSensor.swift @@ -29,10 +29,12 @@ class FacePositionYSensor: DeviceDoubleSensor { static let requiredResource = ResourceType.faceDetection let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageHeight: Double? + let stageSize: CGSize + var stageHeight: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageHeight = Double(stageSize.height) } @@ -41,16 +43,13 @@ class FacePositionYSensor: DeviceDoubleSensor { } func rawValue(landscapeMode: Bool) -> Double { + stageHeight = Double(landscapeMode ? stageSize.width : stageSize.height) guard let positionY = self.getVisualDetectionManager()?.facePositionYRatio[0] else { return type(of: self).defaultRawValue } return positionY } func convertToStandardized(rawValue: Double) -> Double { - if rawValue == type(of: self).defaultRawValue { - return rawValue - } - guard let stageHeight = self.stageHeight else { return type(of: self).defaultRawValue } - return stageHeight * rawValue - stageHeight / 2.0 + stageHeight * rawValue - stageHeight / 2.0 } func formulaEditorSections(for spriteObject: SpriteObject) -> [FormulaEditorSection] { diff --git a/src/Catty/PlayerEngine/Sensors/Face/SecondFacePositionXSensor.swift b/src/Catty/PlayerEngine/Sensors/Face/SecondFacePositionXSensor.swift index b40723153b..f6bdddd99d 100644 --- a/src/Catty/PlayerEngine/Sensors/Face/SecondFacePositionXSensor.swift +++ b/src/Catty/PlayerEngine/Sensors/Face/SecondFacePositionXSensor.swift @@ -29,10 +29,12 @@ class SecondFacePositionXSensor: DeviceDoubleSensor { static let requiredResource = ResourceType.faceDetection let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageWidth: Double? + let stageSize: CGSize + var stageWidth: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageWidth = Double(stageSize.width) } @@ -46,12 +48,7 @@ class SecondFacePositionXSensor: DeviceDoubleSensor { } func convertToStandardized(rawValue: Double) -> Double { - if rawValue == type(of: self).defaultRawValue { - return rawValue - } - guard let stageWidth = self.stageWidth else { - return type(of: self).defaultRawValue } - return stageWidth * rawValue - stageWidth / 2.0 + stageWidth * rawValue - stageWidth / 2.0 } func formulaEditorSections(for spriteObject: SpriteObject) -> [FormulaEditorSection] { diff --git a/src/Catty/PlayerEngine/Sensors/Face/SecondFacePositionYSensor.swift b/src/Catty/PlayerEngine/Sensors/Face/SecondFacePositionYSensor.swift index b1b82ae534..8673222b3c 100644 --- a/src/Catty/PlayerEngine/Sensors/Face/SecondFacePositionYSensor.swift +++ b/src/Catty/PlayerEngine/Sensors/Face/SecondFacePositionYSensor.swift @@ -29,10 +29,12 @@ class SecondFacePositionYSensor: DeviceDoubleSensor { static let requiredResource = ResourceType.faceDetection let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageHeight: Double? + let stageSize: CGSize + var stageHeight: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageHeight = Double(stageSize.height) } @@ -41,16 +43,13 @@ class SecondFacePositionYSensor: DeviceDoubleSensor { } func rawValue(landscapeMode: Bool) -> Double { + stageHeight = Double(landscapeMode ? stageSize.width : stageSize.height) guard let positionY = self.getVisualDetectionManager()?.facePositionYRatio[1] else { return type(of: self).defaultRawValue } return positionY } func convertToStandardized(rawValue: Double) -> Double { - if rawValue == type(of: self).defaultRawValue { - return rawValue - } - guard let stageHeight = self.stageHeight else { return type(of: self).defaultRawValue } - return stageHeight * rawValue - stageHeight / 2.0 + stageHeight * rawValue - stageHeight / 2.0 } func formulaEditorSections(for spriteObject: SpriteObject) -> [FormulaEditorSection] { diff --git a/src/Catty/PlayerEngine/Sensors/FacePose/HeadTopXSensor.swift b/src/Catty/PlayerEngine/Sensors/FacePose/HeadTopXSensor.swift index e132541d57..e3018e66b6 100644 --- a/src/Catty/PlayerEngine/Sensors/FacePose/HeadTopXSensor.swift +++ b/src/Catty/PlayerEngine/Sensors/FacePose/HeadTopXSensor.swift @@ -29,10 +29,12 @@ class HeadTopXSensor: DeviceDoubleSensor { static let requiredResource = ResourceType.faceDetection let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageWidth: Double? + let stageSize: CGSize + var stageWidth: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageWidth = Double(stageSize.width) } @@ -41,17 +43,13 @@ class HeadTopXSensor: DeviceDoubleSensor { } func rawValue(landscapeMode: Bool) -> Double { + stageWidth = Double(landscapeMode ? stageSize.height : stageSize.width) guard let positionX = self.getVisualDetectionManager()?.faceLandmarkPositionRatioDictionary[self.tag()] else { return type(of: self).defaultRawValue } return positionX } func convertToStandardized(rawValue: Double) -> Double { - if rawValue == type(of: self).defaultRawValue { - return rawValue - } - guard let stageWidth = self.stageWidth else { - return type(of: self).defaultRawValue } - return stageWidth * rawValue - stageWidth / 2.0 + stageWidth * rawValue - stageWidth / 2.0 } func formulaEditorSections(for spriteObject: SpriteObject) -> [FormulaEditorSection] { diff --git a/src/Catty/PlayerEngine/Sensors/FacePose/HeadTopYSensor.swift b/src/Catty/PlayerEngine/Sensors/FacePose/HeadTopYSensor.swift index 7780551147..a29aa9aaac 100644 --- a/src/Catty/PlayerEngine/Sensors/FacePose/HeadTopYSensor.swift +++ b/src/Catty/PlayerEngine/Sensors/FacePose/HeadTopYSensor.swift @@ -29,10 +29,12 @@ class HeadTopYSensor: DeviceDoubleSensor { static let requiredResource = ResourceType.faceDetection let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageHeight: Double? + let stageSize: CGSize + var stageHeight: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageHeight = Double(stageSize.height) } @@ -41,16 +43,13 @@ class HeadTopYSensor: DeviceDoubleSensor { } func rawValue(landscapeMode: Bool) -> Double { + stageHeight = Double(landscapeMode ? stageSize.width : stageSize.height) guard let positionY = self.getVisualDetectionManager()?.faceLandmarkPositionRatioDictionary[self.tag()] else { return type(of: self).defaultRawValue } return positionY } func convertToStandardized(rawValue: Double) -> Double { - if rawValue == type(of: self).defaultRawValue { - return rawValue - } - guard let stageHeight = self.stageHeight else { return type(of: self).defaultRawValue } - return stageHeight * rawValue - stageHeight / 2.0 + stageHeight * rawValue - stageHeight / 2.0 } func formulaEditorSections(for spriteObject: SpriteObject) -> [FormulaEditorSection] { diff --git a/src/Catty/PlayerEngine/Sensors/FacePose/LeftEarXSensor.swift b/src/Catty/PlayerEngine/Sensors/FacePose/LeftEarXSensor.swift index e0a8b600d5..1013d7d15b 100644 --- a/src/Catty/PlayerEngine/Sensors/FacePose/LeftEarXSensor.swift +++ b/src/Catty/PlayerEngine/Sensors/FacePose/LeftEarXSensor.swift @@ -29,10 +29,12 @@ class LeftEarXSensor: DeviceDoubleSensor { static let requiredResource = ResourceType.faceDetection let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageWidth: Double? + let stageSize: CGSize + var stageWidth: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageWidth = Double(stageSize.width) } @@ -41,17 +43,13 @@ class LeftEarXSensor: DeviceDoubleSensor { } func rawValue(landscapeMode: Bool) -> Double { + stageWidth = Double(landscapeMode ? stageSize.height : stageSize.width) guard let positionX = self.getVisualDetectionManager()?.faceLandmarkPositionRatioDictionary[self.tag()] else { return type(of: self).defaultRawValue } return positionX } func convertToStandardized(rawValue: Double) -> Double { - if rawValue == type(of: self).defaultRawValue { - return rawValue - } - guard let stageWidth = self.stageWidth else { - return type(of: self).defaultRawValue } - return stageWidth * rawValue - stageWidth / 2.0 + stageWidth * rawValue - stageWidth / 2.0 } func formulaEditorSections(for spriteObject: SpriteObject) -> [FormulaEditorSection] { diff --git a/src/Catty/PlayerEngine/Sensors/FacePose/LeftEarYSensor.swift b/src/Catty/PlayerEngine/Sensors/FacePose/LeftEarYSensor.swift index 8ff08657be..0ae3b6d70c 100644 --- a/src/Catty/PlayerEngine/Sensors/FacePose/LeftEarYSensor.swift +++ b/src/Catty/PlayerEngine/Sensors/FacePose/LeftEarYSensor.swift @@ -29,10 +29,12 @@ class LeftEarYSensor: DeviceDoubleSensor { static let requiredResource = ResourceType.faceDetection let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageHeight: Double? + let stageSize: CGSize + var stageHeight: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageHeight = Double(stageSize.height) } @@ -41,16 +43,13 @@ class LeftEarYSensor: DeviceDoubleSensor { } func rawValue(landscapeMode: Bool) -> Double { + stageHeight = Double(landscapeMode ? stageSize.width : stageSize.height) guard let positionY = self.getVisualDetectionManager()?.faceLandmarkPositionRatioDictionary[self.tag()] else { return type(of: self).defaultRawValue } return positionY } func convertToStandardized(rawValue: Double) -> Double { - if rawValue == type(of: self).defaultRawValue { - return rawValue - } - guard let stageHeight = self.stageHeight else { return type(of: self).defaultRawValue } - return stageHeight * rawValue - stageHeight / 2.0 + stageHeight * rawValue - stageHeight / 2.0 } func formulaEditorSections(for spriteObject: SpriteObject) -> [FormulaEditorSection] { diff --git a/src/Catty/PlayerEngine/Sensors/FacePose/LeftEyeCenterXSensor.swift b/src/Catty/PlayerEngine/Sensors/FacePose/LeftEyeCenterXSensor.swift index edabcc7bcc..2d4ed0eb39 100644 --- a/src/Catty/PlayerEngine/Sensors/FacePose/LeftEyeCenterXSensor.swift +++ b/src/Catty/PlayerEngine/Sensors/FacePose/LeftEyeCenterXSensor.swift @@ -29,10 +29,12 @@ class LeftEyeCenterXSensor: DeviceDoubleSensor { static let requiredResource = ResourceType.faceDetection let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageWidth: Double? + let stageSize: CGSize + var stageWidth: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageWidth = Double(stageSize.width) } @@ -41,17 +43,13 @@ class LeftEyeCenterXSensor: DeviceDoubleSensor { } func rawValue(landscapeMode: Bool) -> Double { + stageWidth = Double(landscapeMode ? stageSize.height : stageSize.width) guard let positionX = self.getVisualDetectionManager()?.faceLandmarkPositionRatioDictionary[self.tag()] else { return type(of: self).defaultRawValue } return positionX } func convertToStandardized(rawValue: Double) -> Double { - if rawValue == type(of: self).defaultRawValue { - return rawValue - } - guard let stageWidth = self.stageWidth else { - return type(of: self).defaultRawValue } - return stageWidth * rawValue - stageWidth / 2.0 + stageWidth * rawValue - stageWidth / 2.0 } func formulaEditorSections(for spriteObject: SpriteObject) -> [FormulaEditorSection] { diff --git a/src/Catty/PlayerEngine/Sensors/FacePose/LeftEyeCenterYSensor.swift b/src/Catty/PlayerEngine/Sensors/FacePose/LeftEyeCenterYSensor.swift index f3354ece03..018a2eeb39 100644 --- a/src/Catty/PlayerEngine/Sensors/FacePose/LeftEyeCenterYSensor.swift +++ b/src/Catty/PlayerEngine/Sensors/FacePose/LeftEyeCenterYSensor.swift @@ -29,10 +29,12 @@ class LeftEyeCenterYSensor: DeviceDoubleSensor { static let requiredResource = ResourceType.faceDetection let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageHeight: Double? + let stageSize: CGSize + var stageHeight: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageHeight = Double(stageSize.height) } @@ -41,16 +43,13 @@ class LeftEyeCenterYSensor: DeviceDoubleSensor { } func rawValue(landscapeMode: Bool) -> Double { + stageHeight = Double(landscapeMode ? stageSize.width : stageSize.height) guard let positionY = self.getVisualDetectionManager()?.faceLandmarkPositionRatioDictionary[self.tag()] else { return type(of: self).defaultRawValue } return positionY } func convertToStandardized(rawValue: Double) -> Double { - if rawValue == type(of: self).defaultRawValue { - return rawValue - } - guard let stageHeight = self.stageHeight else { return type(of: self).defaultRawValue } - return stageHeight * rawValue - stageHeight / 2.0 + stageHeight * rawValue - stageHeight / 2.0 } func formulaEditorSections(for spriteObject: SpriteObject) -> [FormulaEditorSection] { diff --git a/src/Catty/PlayerEngine/Sensors/FacePose/LeftEyeInnerXSensor.swift b/src/Catty/PlayerEngine/Sensors/FacePose/LeftEyeInnerXSensor.swift index 8642dccd65..a59da1a4e0 100644 --- a/src/Catty/PlayerEngine/Sensors/FacePose/LeftEyeInnerXSensor.swift +++ b/src/Catty/PlayerEngine/Sensors/FacePose/LeftEyeInnerXSensor.swift @@ -29,10 +29,12 @@ class LeftEyeInnerXSensor: DeviceDoubleSensor { static let requiredResource = ResourceType.faceDetection let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageWidth: Double? + let stageSize: CGSize + var stageWidth: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageWidth = Double(stageSize.width) } @@ -41,17 +43,13 @@ class LeftEyeInnerXSensor: DeviceDoubleSensor { } func rawValue(landscapeMode: Bool) -> Double { + stageWidth = Double(landscapeMode ? stageSize.height : stageSize.width) guard let positionX = self.getVisualDetectionManager()?.faceLandmarkPositionRatioDictionary[self.tag()] else { return type(of: self).defaultRawValue } return positionX } func convertToStandardized(rawValue: Double) -> Double { - if rawValue == type(of: self).defaultRawValue { - return rawValue - } - guard let stageWidth = self.stageWidth else { - return type(of: self).defaultRawValue } - return stageWidth * rawValue - stageWidth / 2.0 + stageWidth * rawValue - stageWidth / 2.0 } func formulaEditorSections(for spriteObject: SpriteObject) -> [FormulaEditorSection] { diff --git a/src/Catty/PlayerEngine/Sensors/FacePose/LeftEyeInnerYSensor.swift b/src/Catty/PlayerEngine/Sensors/FacePose/LeftEyeInnerYSensor.swift index ee421119c0..cdabacb249 100644 --- a/src/Catty/PlayerEngine/Sensors/FacePose/LeftEyeInnerYSensor.swift +++ b/src/Catty/PlayerEngine/Sensors/FacePose/LeftEyeInnerYSensor.swift @@ -29,10 +29,12 @@ class LeftEyeInnerYSensor: DeviceDoubleSensor { static let requiredResource = ResourceType.faceDetection let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageHeight: Double? + let stageSize: CGSize + var stageHeight: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageHeight = Double(stageSize.height) } @@ -41,16 +43,13 @@ class LeftEyeInnerYSensor: DeviceDoubleSensor { } func rawValue(landscapeMode: Bool) -> Double { + stageHeight = Double(landscapeMode ? stageSize.width : stageSize.height) guard let positionY = self.getVisualDetectionManager()?.faceLandmarkPositionRatioDictionary[self.tag()] else { return type(of: self).defaultRawValue } return positionY } func convertToStandardized(rawValue: Double) -> Double { - if rawValue == type(of: self).defaultRawValue { - return rawValue - } - guard let stageHeight = self.stageHeight else { return type(of: self).defaultRawValue } - return stageHeight * rawValue - stageHeight / 2.0 + stageHeight * rawValue - stageHeight / 2.0 } func formulaEditorSections(for spriteObject: SpriteObject) -> [FormulaEditorSection] { diff --git a/src/Catty/PlayerEngine/Sensors/FacePose/LeftEyeOuterXSensor.swift b/src/Catty/PlayerEngine/Sensors/FacePose/LeftEyeOuterXSensor.swift index 0f836d786e..04349ea622 100644 --- a/src/Catty/PlayerEngine/Sensors/FacePose/LeftEyeOuterXSensor.swift +++ b/src/Catty/PlayerEngine/Sensors/FacePose/LeftEyeOuterXSensor.swift @@ -29,10 +29,12 @@ class LeftEyeOuterXSensor: DeviceDoubleSensor { static let requiredResource = ResourceType.faceDetection let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageWidth: Double? + let stageSize: CGSize + var stageWidth: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageWidth = Double(stageSize.width) } @@ -41,17 +43,13 @@ class LeftEyeOuterXSensor: DeviceDoubleSensor { } func rawValue(landscapeMode: Bool) -> Double { + stageWidth = Double(landscapeMode ? stageSize.height : stageSize.width) guard let positionX = self.getVisualDetectionManager()?.faceLandmarkPositionRatioDictionary[self.tag()] else { return type(of: self).defaultRawValue } return positionX } func convertToStandardized(rawValue: Double) -> Double { - if rawValue == type(of: self).defaultRawValue { - return rawValue - } - guard let stageWidth = self.stageWidth else { - return type(of: self).defaultRawValue } - return stageWidth * rawValue - stageWidth / 2.0 + stageWidth * rawValue - stageWidth / 2.0 } func formulaEditorSections(for spriteObject: SpriteObject) -> [FormulaEditorSection] { diff --git a/src/Catty/PlayerEngine/Sensors/FacePose/LeftEyeOuterYSensor.swift b/src/Catty/PlayerEngine/Sensors/FacePose/LeftEyeOuterYSensor.swift index fb52c2a5d8..5a3cbe8a83 100644 --- a/src/Catty/PlayerEngine/Sensors/FacePose/LeftEyeOuterYSensor.swift +++ b/src/Catty/PlayerEngine/Sensors/FacePose/LeftEyeOuterYSensor.swift @@ -29,10 +29,12 @@ class LeftEyeOuterYSensor: DeviceDoubleSensor { static let requiredResource = ResourceType.faceDetection let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageHeight: Double? + let stageSize: CGSize + var stageHeight: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageHeight = Double(stageSize.height) } @@ -41,16 +43,13 @@ class LeftEyeOuterYSensor: DeviceDoubleSensor { } func rawValue(landscapeMode: Bool) -> Double { + stageHeight = Double(landscapeMode ? stageSize.width : stageSize.height) guard let positionY = self.getVisualDetectionManager()?.faceLandmarkPositionRatioDictionary[self.tag()] else { return type(of: self).defaultRawValue } return positionY } func convertToStandardized(rawValue: Double) -> Double { - if rawValue == type(of: self).defaultRawValue { - return rawValue - } - guard let stageHeight = self.stageHeight else { return type(of: self).defaultRawValue } - return stageHeight * rawValue - stageHeight / 2.0 + stageHeight * rawValue - stageHeight / 2.0 } func formulaEditorSections(for spriteObject: SpriteObject) -> [FormulaEditorSection] { diff --git a/src/Catty/PlayerEngine/Sensors/FacePose/LeftEyebrowCenterXSensor.swift b/src/Catty/PlayerEngine/Sensors/FacePose/LeftEyebrowCenterXSensor.swift index 86e0feed23..c562368ec0 100644 --- a/src/Catty/PlayerEngine/Sensors/FacePose/LeftEyebrowCenterXSensor.swift +++ b/src/Catty/PlayerEngine/Sensors/FacePose/LeftEyebrowCenterXSensor.swift @@ -29,10 +29,12 @@ class LeftEyebrowCenterXSensor: DeviceDoubleSensor { static let requiredResource = ResourceType.faceDetection let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageWidth: Double? + let stageSize: CGSize + var stageWidth: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageWidth = Double(stageSize.width) } @@ -41,17 +43,13 @@ class LeftEyebrowCenterXSensor: DeviceDoubleSensor { } func rawValue(landscapeMode: Bool) -> Double { + stageWidth = Double(landscapeMode ? stageSize.height : stageSize.width) guard let positionX = self.getVisualDetectionManager()?.faceLandmarkPositionRatioDictionary[self.tag()] else { return type(of: self).defaultRawValue } return positionX } func convertToStandardized(rawValue: Double) -> Double { - if rawValue == type(of: self).defaultRawValue { - return rawValue - } - guard let stageWidth = self.stageWidth else { - return type(of: self).defaultRawValue } - return stageWidth * rawValue - stageWidth / 2.0 + stageWidth * rawValue - stageWidth / 2.0 } func formulaEditorSections(for spriteObject: SpriteObject) -> [FormulaEditorSection] { diff --git a/src/Catty/PlayerEngine/Sensors/FacePose/LeftEyebrowCenterYSensor.swift b/src/Catty/PlayerEngine/Sensors/FacePose/LeftEyebrowCenterYSensor.swift index 754b3fa5c1..512a586b2a 100644 --- a/src/Catty/PlayerEngine/Sensors/FacePose/LeftEyebrowCenterYSensor.swift +++ b/src/Catty/PlayerEngine/Sensors/FacePose/LeftEyebrowCenterYSensor.swift @@ -29,10 +29,12 @@ class LeftEyebrowCenterYSensor: DeviceDoubleSensor { static let requiredResource = ResourceType.faceDetection let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageHeight: Double? + let stageSize: CGSize + var stageHeight: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageHeight = Double(stageSize.height) } @@ -41,16 +43,13 @@ class LeftEyebrowCenterYSensor: DeviceDoubleSensor { } func rawValue(landscapeMode: Bool) -> Double { + stageHeight = Double(landscapeMode ? stageSize.width : stageSize.height) guard let positionY = self.getVisualDetectionManager()?.faceLandmarkPositionRatioDictionary[self.tag()] else { return type(of: self).defaultRawValue } return positionY } func convertToStandardized(rawValue: Double) -> Double { - if rawValue == type(of: self).defaultRawValue { - return rawValue - } - guard let stageHeight = self.stageHeight else { return type(of: self).defaultRawValue } - return stageHeight * rawValue - stageHeight / 2.0 + stageHeight * rawValue - stageHeight / 2.0 } func formulaEditorSections(for spriteObject: SpriteObject) -> [FormulaEditorSection] { diff --git a/src/Catty/PlayerEngine/Sensors/FacePose/LeftEyebrowInnerXSensor.swift b/src/Catty/PlayerEngine/Sensors/FacePose/LeftEyebrowInnerXSensor.swift index c36a1be588..9c9fa42e81 100644 --- a/src/Catty/PlayerEngine/Sensors/FacePose/LeftEyebrowInnerXSensor.swift +++ b/src/Catty/PlayerEngine/Sensors/FacePose/LeftEyebrowInnerXSensor.swift @@ -29,10 +29,12 @@ class LeftEyebrowInnerXSensor: DeviceDoubleSensor { static let requiredResource = ResourceType.faceDetection let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageWidth: Double? + let stageSize: CGSize + var stageWidth: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageWidth = Double(stageSize.width) } @@ -41,17 +43,13 @@ class LeftEyebrowInnerXSensor: DeviceDoubleSensor { } func rawValue(landscapeMode: Bool) -> Double { + stageWidth = Double(landscapeMode ? stageSize.height : stageSize.width) guard let positionX = self.getVisualDetectionManager()?.faceLandmarkPositionRatioDictionary[self.tag()] else { return type(of: self).defaultRawValue } return positionX } func convertToStandardized(rawValue: Double) -> Double { - if rawValue == type(of: self).defaultRawValue { - return rawValue - } - guard let stageWidth = self.stageWidth else { - return type(of: self).defaultRawValue } - return stageWidth * rawValue - stageWidth / 2.0 + stageWidth * rawValue - stageWidth / 2.0 } func formulaEditorSections(for spriteObject: SpriteObject) -> [FormulaEditorSection] { diff --git a/src/Catty/PlayerEngine/Sensors/FacePose/LeftEyebrowInnerYSensor.swift b/src/Catty/PlayerEngine/Sensors/FacePose/LeftEyebrowInnerYSensor.swift index 4f8abad7e1..7743537c36 100644 --- a/src/Catty/PlayerEngine/Sensors/FacePose/LeftEyebrowInnerYSensor.swift +++ b/src/Catty/PlayerEngine/Sensors/FacePose/LeftEyebrowInnerYSensor.swift @@ -29,10 +29,12 @@ class LeftEyebrowInnerYSensor: DeviceDoubleSensor { static let requiredResource = ResourceType.faceDetection let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageHeight: Double? + let stageSize: CGSize + var stageHeight: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageHeight = Double(stageSize.height) } @@ -41,16 +43,13 @@ class LeftEyebrowInnerYSensor: DeviceDoubleSensor { } func rawValue(landscapeMode: Bool) -> Double { + stageHeight = Double(landscapeMode ? stageSize.width : stageSize.height) guard let positionY = self.getVisualDetectionManager()?.faceLandmarkPositionRatioDictionary[self.tag()] else { return type(of: self).defaultRawValue } return positionY } func convertToStandardized(rawValue: Double) -> Double { - if rawValue == type(of: self).defaultRawValue { - return rawValue - } - guard let stageHeight = self.stageHeight else { return type(of: self).defaultRawValue } - return stageHeight * rawValue - stageHeight / 2.0 + stageHeight * rawValue - stageHeight / 2.0 } func formulaEditorSections(for spriteObject: SpriteObject) -> [FormulaEditorSection] { diff --git a/src/Catty/PlayerEngine/Sensors/FacePose/LeftEyebrowOuterXSensor.swift b/src/Catty/PlayerEngine/Sensors/FacePose/LeftEyebrowOuterXSensor.swift index ed8c21f36d..9a80fab464 100644 --- a/src/Catty/PlayerEngine/Sensors/FacePose/LeftEyebrowOuterXSensor.swift +++ b/src/Catty/PlayerEngine/Sensors/FacePose/LeftEyebrowOuterXSensor.swift @@ -29,10 +29,12 @@ class LeftEyebrowOuterXSensor: DeviceDoubleSensor { static let requiredResource = ResourceType.faceDetection let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageWidth: Double? + let stageSize: CGSize + var stageWidth: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageWidth = Double(stageSize.width) } @@ -41,17 +43,13 @@ class LeftEyebrowOuterXSensor: DeviceDoubleSensor { } func rawValue(landscapeMode: Bool) -> Double { + stageWidth = Double(landscapeMode ? stageSize.height : stageSize.width) guard let positionX = self.getVisualDetectionManager()?.faceLandmarkPositionRatioDictionary[self.tag()] else { return type(of: self).defaultRawValue } return positionX } func convertToStandardized(rawValue: Double) -> Double { - if rawValue == type(of: self).defaultRawValue { - return rawValue - } - guard let stageWidth = self.stageWidth else { - return type(of: self).defaultRawValue } - return stageWidth * rawValue - stageWidth / 2.0 + stageWidth * rawValue - stageWidth / 2.0 } func formulaEditorSections(for spriteObject: SpriteObject) -> [FormulaEditorSection] { diff --git a/src/Catty/PlayerEngine/Sensors/FacePose/LeftEyebrowOuterYSensor.swift b/src/Catty/PlayerEngine/Sensors/FacePose/LeftEyebrowOuterYSensor.swift index 033d5e7f1d..c6fbdccf92 100644 --- a/src/Catty/PlayerEngine/Sensors/FacePose/LeftEyebrowOuterYSensor.swift +++ b/src/Catty/PlayerEngine/Sensors/FacePose/LeftEyebrowOuterYSensor.swift @@ -29,10 +29,12 @@ class LeftEyebrowOuterYSensor: DeviceDoubleSensor { static let requiredResource = ResourceType.faceDetection let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageHeight: Double? + let stageSize: CGSize + var stageHeight: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageHeight = Double(stageSize.height) } @@ -41,16 +43,13 @@ class LeftEyebrowOuterYSensor: DeviceDoubleSensor { } func rawValue(landscapeMode: Bool) -> Double { + stageHeight = Double(landscapeMode ? stageSize.width : stageSize.height) guard let positionY = self.getVisualDetectionManager()?.faceLandmarkPositionRatioDictionary[self.tag()] else { return type(of: self).defaultRawValue } return positionY } func convertToStandardized(rawValue: Double) -> Double { - if rawValue == type(of: self).defaultRawValue { - return rawValue - } - guard let stageHeight = self.stageHeight else { return type(of: self).defaultRawValue } - return stageHeight * rawValue - stageHeight / 2.0 + stageHeight * rawValue - stageHeight / 2.0 } func formulaEditorSections(for spriteObject: SpriteObject) -> [FormulaEditorSection] { diff --git a/src/Catty/PlayerEngine/Sensors/FacePose/MouthLeftCornerXSensor.swift b/src/Catty/PlayerEngine/Sensors/FacePose/MouthLeftCornerXSensor.swift index 3528fac87c..e495b1fe8b 100644 --- a/src/Catty/PlayerEngine/Sensors/FacePose/MouthLeftCornerXSensor.swift +++ b/src/Catty/PlayerEngine/Sensors/FacePose/MouthLeftCornerXSensor.swift @@ -29,10 +29,12 @@ class MouthLeftCornerXSensor: DeviceDoubleSensor { static let requiredResource = ResourceType.faceDetection let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageWidth: Double? + let stageSize: CGSize + var stageWidth: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageWidth = Double(stageSize.width) } @@ -41,17 +43,13 @@ class MouthLeftCornerXSensor: DeviceDoubleSensor { } func rawValue(landscapeMode: Bool) -> Double { + stageWidth = Double(landscapeMode ? stageSize.height : stageSize.width) guard let positionX = self.getVisualDetectionManager()?.faceLandmarkPositionRatioDictionary[self.tag()] else { return type(of: self).defaultRawValue } return positionX } func convertToStandardized(rawValue: Double) -> Double { - if rawValue == type(of: self).defaultRawValue { - return rawValue - } - guard let stageWidth = self.stageWidth else { - return type(of: self).defaultRawValue } - return stageWidth * rawValue - stageWidth / 2.0 + stageWidth * rawValue - stageWidth / 2.0 } func formulaEditorSections(for spriteObject: SpriteObject) -> [FormulaEditorSection] { diff --git a/src/Catty/PlayerEngine/Sensors/FacePose/MouthLeftCornerYSensor.swift b/src/Catty/PlayerEngine/Sensors/FacePose/MouthLeftCornerYSensor.swift index 4956b0544e..fe41bfcb2d 100644 --- a/src/Catty/PlayerEngine/Sensors/FacePose/MouthLeftCornerYSensor.swift +++ b/src/Catty/PlayerEngine/Sensors/FacePose/MouthLeftCornerYSensor.swift @@ -29,10 +29,12 @@ class MouthLeftCornerYSensor: DeviceDoubleSensor { static let requiredResource = ResourceType.faceDetection let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageHeight: Double? + let stageSize: CGSize + var stageHeight: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageHeight = Double(stageSize.height) } @@ -41,16 +43,13 @@ class MouthLeftCornerYSensor: DeviceDoubleSensor { } func rawValue(landscapeMode: Bool) -> Double { + stageHeight = Double(landscapeMode ? stageSize.width : stageSize.height) guard let positionY = self.getVisualDetectionManager()?.faceLandmarkPositionRatioDictionary[self.tag()] else { return type(of: self).defaultRawValue } return positionY } func convertToStandardized(rawValue: Double) -> Double { - if rawValue == type(of: self).defaultRawValue { - return rawValue - } - guard let stageHeight = self.stageHeight else { return type(of: self).defaultRawValue } - return stageHeight * rawValue - stageHeight / 2.0 + stageHeight * rawValue - stageHeight / 2.0 } func formulaEditorSections(for spriteObject: SpriteObject) -> [FormulaEditorSection] { diff --git a/src/Catty/PlayerEngine/Sensors/FacePose/MouthRightCornerXSensor.swift b/src/Catty/PlayerEngine/Sensors/FacePose/MouthRightCornerXSensor.swift index 98d977a601..fd9e19c9c4 100644 --- a/src/Catty/PlayerEngine/Sensors/FacePose/MouthRightCornerXSensor.swift +++ b/src/Catty/PlayerEngine/Sensors/FacePose/MouthRightCornerXSensor.swift @@ -29,10 +29,12 @@ class MouthRightCornerXSensor: DeviceDoubleSensor { static let requiredResource = ResourceType.faceDetection let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageWidth: Double? + let stageSize: CGSize + var stageWidth: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageWidth = Double(stageSize.width) } @@ -41,17 +43,13 @@ class MouthRightCornerXSensor: DeviceDoubleSensor { } func rawValue(landscapeMode: Bool) -> Double { + stageWidth = Double(landscapeMode ? stageSize.height : stageSize.width) guard let positionX = self.getVisualDetectionManager()?.faceLandmarkPositionRatioDictionary[self.tag()] else { return type(of: self).defaultRawValue } return positionX } func convertToStandardized(rawValue: Double) -> Double { - if rawValue == type(of: self).defaultRawValue { - return rawValue - } - guard let stageWidth = self.stageWidth else { - return type(of: self).defaultRawValue } - return stageWidth * rawValue - stageWidth / 2.0 + stageWidth * rawValue - stageWidth / 2.0 } func formulaEditorSections(for spriteObject: SpriteObject) -> [FormulaEditorSection] { diff --git a/src/Catty/PlayerEngine/Sensors/FacePose/MouthRightCornerYSensor.swift b/src/Catty/PlayerEngine/Sensors/FacePose/MouthRightCornerYSensor.swift index 0f597742e9..825f08e0c4 100644 --- a/src/Catty/PlayerEngine/Sensors/FacePose/MouthRightCornerYSensor.swift +++ b/src/Catty/PlayerEngine/Sensors/FacePose/MouthRightCornerYSensor.swift @@ -29,10 +29,12 @@ class MouthRightCornerYSensor: DeviceDoubleSensor { static let requiredResource = ResourceType.faceDetection let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageHeight: Double? + let stageSize: CGSize + var stageHeight: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageHeight = Double(stageSize.height) } @@ -41,16 +43,13 @@ class MouthRightCornerYSensor: DeviceDoubleSensor { } func rawValue(landscapeMode: Bool) -> Double { + stageHeight = Double(landscapeMode ? stageSize.width : stageSize.height) guard let positionY = self.getVisualDetectionManager()?.faceLandmarkPositionRatioDictionary[self.tag()] else { return type(of: self).defaultRawValue } return positionY } func convertToStandardized(rawValue: Double) -> Double { - if rawValue == type(of: self).defaultRawValue { - return rawValue - } - guard let stageHeight = self.stageHeight else { return type(of: self).defaultRawValue } - return stageHeight * rawValue - stageHeight / 2.0 + stageHeight * rawValue - stageHeight / 2.0 } func formulaEditorSections(for spriteObject: SpriteObject) -> [FormulaEditorSection] { diff --git a/src/Catty/PlayerEngine/Sensors/FacePose/NoseXSensor.swift b/src/Catty/PlayerEngine/Sensors/FacePose/NoseXSensor.swift index e5ef3d77f0..5e0ee07297 100644 --- a/src/Catty/PlayerEngine/Sensors/FacePose/NoseXSensor.swift +++ b/src/Catty/PlayerEngine/Sensors/FacePose/NoseXSensor.swift @@ -29,10 +29,12 @@ class NoseXSensor: DeviceDoubleSensor { static let requiredResource = ResourceType.faceDetection let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageWidth: Double? + let stageSize: CGSize + var stageWidth: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageWidth = Double(stageSize.width) } @@ -41,17 +43,13 @@ class NoseXSensor: DeviceDoubleSensor { } func rawValue(landscapeMode: Bool) -> Double { + stageWidth = Double(landscapeMode ? stageSize.height : stageSize.width) guard let positionX = self.getVisualDetectionManager()?.faceLandmarkPositionRatioDictionary[self.tag()] else { return type(of: self).defaultRawValue } return positionX } func convertToStandardized(rawValue: Double) -> Double { - if rawValue == type(of: self).defaultRawValue { - return rawValue - } - guard let stageWidth = self.stageWidth else { - return type(of: self).defaultRawValue } - return stageWidth * rawValue - stageWidth / 2.0 + stageWidth * rawValue - stageWidth / 2.0 } func formulaEditorSections(for spriteObject: SpriteObject) -> [FormulaEditorSection] { diff --git a/src/Catty/PlayerEngine/Sensors/FacePose/NoseYSensor.swift b/src/Catty/PlayerEngine/Sensors/FacePose/NoseYSensor.swift index 428b25e0a2..f65d098d4b 100644 --- a/src/Catty/PlayerEngine/Sensors/FacePose/NoseYSensor.swift +++ b/src/Catty/PlayerEngine/Sensors/FacePose/NoseYSensor.swift @@ -29,10 +29,12 @@ class NoseYSensor: DeviceDoubleSensor { static let requiredResource = ResourceType.faceDetection let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageHeight: Double? + let stageSize: CGSize + var stageHeight: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageHeight = Double(stageSize.height) } @@ -41,16 +43,13 @@ class NoseYSensor: DeviceDoubleSensor { } func rawValue(landscapeMode: Bool) -> Double { + stageHeight = Double(landscapeMode ? stageSize.width : stageSize.height) guard let positionY = self.getVisualDetectionManager()?.faceLandmarkPositionRatioDictionary[self.tag()] else { return type(of: self).defaultRawValue } return positionY } func convertToStandardized(rawValue: Double) -> Double { - if rawValue == type(of: self).defaultRawValue { - return rawValue - } - guard let stageHeight = self.stageHeight else { return type(of: self).defaultRawValue } - return stageHeight * rawValue - stageHeight / 2.0 + stageHeight * rawValue - stageHeight / 2.0 } func formulaEditorSections(for spriteObject: SpriteObject) -> [FormulaEditorSection] { diff --git a/src/Catty/PlayerEngine/Sensors/FacePose/RightEarXSensor.swift b/src/Catty/PlayerEngine/Sensors/FacePose/RightEarXSensor.swift index d5c493fadb..8ac8d8293c 100644 --- a/src/Catty/PlayerEngine/Sensors/FacePose/RightEarXSensor.swift +++ b/src/Catty/PlayerEngine/Sensors/FacePose/RightEarXSensor.swift @@ -29,10 +29,12 @@ class RightEarXSensor: DeviceDoubleSensor { static let requiredResource = ResourceType.faceDetection let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageWidth: Double? + let stageSize: CGSize + var stageWidth: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageWidth = Double(stageSize.width) } @@ -41,17 +43,13 @@ class RightEarXSensor: DeviceDoubleSensor { } func rawValue(landscapeMode: Bool) -> Double { + stageWidth = Double(landscapeMode ? stageSize.height : stageSize.width) guard let positionX = self.getVisualDetectionManager()?.faceLandmarkPositionRatioDictionary[self.tag()] else { return type(of: self).defaultRawValue } return positionX } func convertToStandardized(rawValue: Double) -> Double { - if rawValue == type(of: self).defaultRawValue { - return rawValue - } - guard let stageWidth = self.stageWidth else { - return type(of: self).defaultRawValue } - return stageWidth * rawValue - stageWidth / 2.0 + stageWidth * rawValue - stageWidth / 2.0 } func formulaEditorSections(for spriteObject: SpriteObject) -> [FormulaEditorSection] { diff --git a/src/Catty/PlayerEngine/Sensors/FacePose/RightEarYSensor.swift b/src/Catty/PlayerEngine/Sensors/FacePose/RightEarYSensor.swift index 3e355eda2c..38e1bfd11f 100644 --- a/src/Catty/PlayerEngine/Sensors/FacePose/RightEarYSensor.swift +++ b/src/Catty/PlayerEngine/Sensors/FacePose/RightEarYSensor.swift @@ -29,10 +29,12 @@ class RightEarYSensor: DeviceDoubleSensor { static let requiredResource = ResourceType.faceDetection let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageHeight: Double? + let stageSize: CGSize + var stageHeight: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageHeight = Double(stageSize.height) } @@ -41,16 +43,13 @@ class RightEarYSensor: DeviceDoubleSensor { } func rawValue(landscapeMode: Bool) -> Double { + stageHeight = Double(landscapeMode ? stageSize.width : stageSize.height) guard let positionY = self.getVisualDetectionManager()?.faceLandmarkPositionRatioDictionary[self.tag()] else { return type(of: self).defaultRawValue } return positionY } func convertToStandardized(rawValue: Double) -> Double { - if rawValue == type(of: self).defaultRawValue { - return rawValue - } - guard let stageHeight = self.stageHeight else { return type(of: self).defaultRawValue } - return stageHeight * rawValue - stageHeight / 2.0 + stageHeight * rawValue - stageHeight / 2.0 } func formulaEditorSections(for spriteObject: SpriteObject) -> [FormulaEditorSection] { diff --git a/src/Catty/PlayerEngine/Sensors/FacePose/RightEyeCenterXSensor.swift b/src/Catty/PlayerEngine/Sensors/FacePose/RightEyeCenterXSensor.swift index 6e787020ba..e2e2ae37ba 100644 --- a/src/Catty/PlayerEngine/Sensors/FacePose/RightEyeCenterXSensor.swift +++ b/src/Catty/PlayerEngine/Sensors/FacePose/RightEyeCenterXSensor.swift @@ -29,10 +29,12 @@ class RightEyeCenterXSensor: DeviceDoubleSensor { static let requiredResource = ResourceType.faceDetection let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageWidth: Double? + let stageSize: CGSize + var stageWidth: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageWidth = Double(stageSize.width) } @@ -41,17 +43,13 @@ class RightEyeCenterXSensor: DeviceDoubleSensor { } func rawValue(landscapeMode: Bool) -> Double { + stageWidth = Double(landscapeMode ? stageSize.height : stageSize.width) guard let positionX = self.getVisualDetectionManager()?.faceLandmarkPositionRatioDictionary[self.tag()] else { return type(of: self).defaultRawValue } return positionX } func convertToStandardized(rawValue: Double) -> Double { - if rawValue == type(of: self).defaultRawValue { - return rawValue - } - guard let stageWidth = self.stageWidth else { - return type(of: self).defaultRawValue } - return stageWidth * rawValue - stageWidth / 2.0 + stageWidth * rawValue - stageWidth / 2.0 } func formulaEditorSections(for spriteObject: SpriteObject) -> [FormulaEditorSection] { diff --git a/src/Catty/PlayerEngine/Sensors/FacePose/RightEyeCenterYSensor.swift b/src/Catty/PlayerEngine/Sensors/FacePose/RightEyeCenterYSensor.swift index 09b73824e3..cbe62aa05c 100644 --- a/src/Catty/PlayerEngine/Sensors/FacePose/RightEyeCenterYSensor.swift +++ b/src/Catty/PlayerEngine/Sensors/FacePose/RightEyeCenterYSensor.swift @@ -29,10 +29,12 @@ class RightEyeCenterYSensor: DeviceDoubleSensor { static let requiredResource = ResourceType.faceDetection let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageHeight: Double? + let stageSize: CGSize + var stageHeight: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageHeight = Double(stageSize.height) } @@ -41,16 +43,13 @@ class RightEyeCenterYSensor: DeviceDoubleSensor { } func rawValue(landscapeMode: Bool) -> Double { + stageHeight = Double(landscapeMode ? stageSize.width : stageSize.height) guard let positionY = self.getVisualDetectionManager()?.faceLandmarkPositionRatioDictionary[self.tag()] else { return type(of: self).defaultRawValue } return positionY } func convertToStandardized(rawValue: Double) -> Double { - if rawValue == type(of: self).defaultRawValue { - return rawValue - } - guard let stageHeight = self.stageHeight else { return type(of: self).defaultRawValue } - return stageHeight * rawValue - stageHeight / 2.0 + stageHeight * rawValue - stageHeight / 2.0 } func formulaEditorSections(for spriteObject: SpriteObject) -> [FormulaEditorSection] { diff --git a/src/Catty/PlayerEngine/Sensors/FacePose/RightEyeInnerXSensor.swift b/src/Catty/PlayerEngine/Sensors/FacePose/RightEyeInnerXSensor.swift index 963c8e70d6..5822dbd1e9 100644 --- a/src/Catty/PlayerEngine/Sensors/FacePose/RightEyeInnerXSensor.swift +++ b/src/Catty/PlayerEngine/Sensors/FacePose/RightEyeInnerXSensor.swift @@ -29,10 +29,12 @@ class RightEyeInnerXSensor: DeviceDoubleSensor { static let requiredResource = ResourceType.faceDetection let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageWidth: Double? + let stageSize: CGSize + var stageWidth: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageWidth = Double(stageSize.width) } @@ -41,17 +43,13 @@ class RightEyeInnerXSensor: DeviceDoubleSensor { } func rawValue(landscapeMode: Bool) -> Double { + stageWidth = Double(landscapeMode ? stageSize.height : stageSize.width) guard let positionX = self.getVisualDetectionManager()?.faceLandmarkPositionRatioDictionary[self.tag()] else { return type(of: self).defaultRawValue } return positionX } func convertToStandardized(rawValue: Double) -> Double { - if rawValue == type(of: self).defaultRawValue { - return rawValue - } - guard let stageWidth = self.stageWidth else { - return type(of: self).defaultRawValue } - return stageWidth * rawValue - stageWidth / 2.0 + stageWidth * rawValue - stageWidth / 2.0 } func formulaEditorSections(for spriteObject: SpriteObject) -> [FormulaEditorSection] { diff --git a/src/Catty/PlayerEngine/Sensors/FacePose/RightEyeInnerYSensor.swift b/src/Catty/PlayerEngine/Sensors/FacePose/RightEyeInnerYSensor.swift index 91506d6f09..178ac4587d 100644 --- a/src/Catty/PlayerEngine/Sensors/FacePose/RightEyeInnerYSensor.swift +++ b/src/Catty/PlayerEngine/Sensors/FacePose/RightEyeInnerYSensor.swift @@ -29,10 +29,12 @@ class RightEyeInnerYSensor: DeviceDoubleSensor { static let requiredResource = ResourceType.faceDetection let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageHeight: Double? + let stageSize: CGSize + var stageHeight: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageHeight = Double(stageSize.height) } @@ -41,16 +43,13 @@ class RightEyeInnerYSensor: DeviceDoubleSensor { } func rawValue(landscapeMode: Bool) -> Double { + stageHeight = Double(landscapeMode ? stageSize.width : stageSize.height) guard let positionY = self.getVisualDetectionManager()?.faceLandmarkPositionRatioDictionary[self.tag()] else { return type(of: self).defaultRawValue } return positionY } func convertToStandardized(rawValue: Double) -> Double { - if rawValue == type(of: self).defaultRawValue { - return rawValue - } - guard let stageHeight = self.stageHeight else { return type(of: self).defaultRawValue } - return stageHeight * rawValue - stageHeight / 2.0 + stageHeight * rawValue - stageHeight / 2.0 } func formulaEditorSections(for spriteObject: SpriteObject) -> [FormulaEditorSection] { diff --git a/src/Catty/PlayerEngine/Sensors/FacePose/RightEyeOuterXSensor.swift b/src/Catty/PlayerEngine/Sensors/FacePose/RightEyeOuterXSensor.swift index d2fb8a0cd4..0bc56fda54 100644 --- a/src/Catty/PlayerEngine/Sensors/FacePose/RightEyeOuterXSensor.swift +++ b/src/Catty/PlayerEngine/Sensors/FacePose/RightEyeOuterXSensor.swift @@ -29,10 +29,12 @@ class RightEyeOuterXSensor: DeviceDoubleSensor { static let requiredResource = ResourceType.faceDetection let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageWidth: Double? + let stageSize: CGSize + var stageWidth: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageWidth = Double(stageSize.width) } @@ -41,17 +43,13 @@ class RightEyeOuterXSensor: DeviceDoubleSensor { } func rawValue(landscapeMode: Bool) -> Double { + stageWidth = Double(landscapeMode ? stageSize.height : stageSize.width) guard let positionX = self.getVisualDetectionManager()?.faceLandmarkPositionRatioDictionary[self.tag()] else { return type(of: self).defaultRawValue } return positionX } func convertToStandardized(rawValue: Double) -> Double { - if rawValue == type(of: self).defaultRawValue { - return rawValue - } - guard let stageWidth = self.stageWidth else { - return type(of: self).defaultRawValue } - return stageWidth * rawValue - stageWidth / 2.0 + stageWidth * rawValue - stageWidth / 2.0 } func formulaEditorSections(for spriteObject: SpriteObject) -> [FormulaEditorSection] { diff --git a/src/Catty/PlayerEngine/Sensors/FacePose/RightEyeOuterYSensor.swift b/src/Catty/PlayerEngine/Sensors/FacePose/RightEyeOuterYSensor.swift index add9f782d9..8e2351d635 100644 --- a/src/Catty/PlayerEngine/Sensors/FacePose/RightEyeOuterYSensor.swift +++ b/src/Catty/PlayerEngine/Sensors/FacePose/RightEyeOuterYSensor.swift @@ -29,10 +29,12 @@ class RightEyeOuterYSensor: DeviceDoubleSensor { static let requiredResource = ResourceType.faceDetection let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageHeight: Double? + let stageSize: CGSize + var stageHeight: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageHeight = Double(stageSize.height) } @@ -41,16 +43,13 @@ class RightEyeOuterYSensor: DeviceDoubleSensor { } func rawValue(landscapeMode: Bool) -> Double { + stageHeight = Double(landscapeMode ? stageSize.width : stageSize.height) guard let positionY = self.getVisualDetectionManager()?.faceLandmarkPositionRatioDictionary[self.tag()] else { return type(of: self).defaultRawValue } return positionY } func convertToStandardized(rawValue: Double) -> Double { - if rawValue == type(of: self).defaultRawValue { - return rawValue - } - guard let stageHeight = self.stageHeight else { return type(of: self).defaultRawValue } - return stageHeight * rawValue - stageHeight / 2.0 + stageHeight * rawValue - stageHeight / 2.0 } func formulaEditorSections(for spriteObject: SpriteObject) -> [FormulaEditorSection] { diff --git a/src/Catty/PlayerEngine/Sensors/FacePose/RightEyebrowCenterXSensor.swift b/src/Catty/PlayerEngine/Sensors/FacePose/RightEyebrowCenterXSensor.swift index 64c0e901d6..e7aa20cb7c 100644 --- a/src/Catty/PlayerEngine/Sensors/FacePose/RightEyebrowCenterXSensor.swift +++ b/src/Catty/PlayerEngine/Sensors/FacePose/RightEyebrowCenterXSensor.swift @@ -29,10 +29,12 @@ class RightEyebrowCenterXSensor: DeviceDoubleSensor { static let requiredResource = ResourceType.faceDetection let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageWidth: Double? + let stageSize: CGSize + var stageWidth: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageWidth = Double(stageSize.width) } @@ -41,17 +43,13 @@ class RightEyebrowCenterXSensor: DeviceDoubleSensor { } func rawValue(landscapeMode: Bool) -> Double { + stageWidth = Double(landscapeMode ? stageSize.height : stageSize.width) guard let positionX = self.getVisualDetectionManager()?.faceLandmarkPositionRatioDictionary[self.tag()] else { return type(of: self).defaultRawValue } return positionX } func convertToStandardized(rawValue: Double) -> Double { - if rawValue == type(of: self).defaultRawValue { - return rawValue - } - guard let stageWidth = self.stageWidth else { - return type(of: self).defaultRawValue } - return stageWidth * rawValue - stageWidth / 2.0 + stageWidth * rawValue - stageWidth / 2.0 } func formulaEditorSections(for spriteObject: SpriteObject) -> [FormulaEditorSection] { diff --git a/src/Catty/PlayerEngine/Sensors/FacePose/RightEyebrowCenterYSensor.swift b/src/Catty/PlayerEngine/Sensors/FacePose/RightEyebrowCenterYSensor.swift index 2e03c99019..41431bd699 100644 --- a/src/Catty/PlayerEngine/Sensors/FacePose/RightEyebrowCenterYSensor.swift +++ b/src/Catty/PlayerEngine/Sensors/FacePose/RightEyebrowCenterYSensor.swift @@ -29,10 +29,12 @@ class RightEyebrowCenterYSensor: DeviceDoubleSensor { static let requiredResource = ResourceType.faceDetection let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageHeight: Double? + let stageSize: CGSize + var stageHeight: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageHeight = Double(stageSize.height) } @@ -41,16 +43,13 @@ class RightEyebrowCenterYSensor: DeviceDoubleSensor { } func rawValue(landscapeMode: Bool) -> Double { + stageHeight = Double(landscapeMode ? stageSize.width : stageSize.height) guard let positionY = self.getVisualDetectionManager()?.faceLandmarkPositionRatioDictionary[self.tag()] else { return type(of: self).defaultRawValue } return positionY } func convertToStandardized(rawValue: Double) -> Double { - if rawValue == type(of: self).defaultRawValue { - return rawValue - } - guard let stageHeight = self.stageHeight else { return type(of: self).defaultRawValue } - return stageHeight * rawValue - stageHeight / 2.0 + stageHeight * rawValue - stageHeight / 2.0 } func formulaEditorSections(for spriteObject: SpriteObject) -> [FormulaEditorSection] { diff --git a/src/Catty/PlayerEngine/Sensors/FacePose/RightEyebrowInnerXSensor.swift b/src/Catty/PlayerEngine/Sensors/FacePose/RightEyebrowInnerXSensor.swift index bd83d113d0..9c8810b61e 100644 --- a/src/Catty/PlayerEngine/Sensors/FacePose/RightEyebrowInnerXSensor.swift +++ b/src/Catty/PlayerEngine/Sensors/FacePose/RightEyebrowInnerXSensor.swift @@ -29,10 +29,12 @@ class RightEyebrowInnerXSensor: DeviceDoubleSensor { static let requiredResource = ResourceType.faceDetection let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageWidth: Double? + let stageSize: CGSize + var stageWidth: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageWidth = Double(stageSize.width) } @@ -41,17 +43,13 @@ class RightEyebrowInnerXSensor: DeviceDoubleSensor { } func rawValue(landscapeMode: Bool) -> Double { + stageWidth = Double(landscapeMode ? stageSize.height : stageSize.width) guard let positionX = self.getVisualDetectionManager()?.faceLandmarkPositionRatioDictionary[self.tag()] else { return type(of: self).defaultRawValue } return positionX } func convertToStandardized(rawValue: Double) -> Double { - if rawValue == type(of: self).defaultRawValue { - return rawValue - } - guard let stageWidth = self.stageWidth else { - return type(of: self).defaultRawValue } - return stageWidth * rawValue - stageWidth / 2.0 + stageWidth * rawValue - stageWidth / 2.0 } func formulaEditorSections(for spriteObject: SpriteObject) -> [FormulaEditorSection] { diff --git a/src/Catty/PlayerEngine/Sensors/FacePose/RightEyebrowInnerYSensor.swift b/src/Catty/PlayerEngine/Sensors/FacePose/RightEyebrowInnerYSensor.swift index f72128f76c..95045c5ba7 100644 --- a/src/Catty/PlayerEngine/Sensors/FacePose/RightEyebrowInnerYSensor.swift +++ b/src/Catty/PlayerEngine/Sensors/FacePose/RightEyebrowInnerYSensor.swift @@ -29,10 +29,12 @@ class RightEyebrowInnerYSensor: DeviceDoubleSensor { static let requiredResource = ResourceType.faceDetection let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageHeight: Double? + let stageSize: CGSize + var stageHeight: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageHeight = Double(stageSize.height) } @@ -41,16 +43,13 @@ class RightEyebrowInnerYSensor: DeviceDoubleSensor { } func rawValue(landscapeMode: Bool) -> Double { + stageHeight = Double(landscapeMode ? stageSize.width : stageSize.height) guard let positionY = self.getVisualDetectionManager()?.faceLandmarkPositionRatioDictionary[self.tag()] else { return type(of: self).defaultRawValue } return positionY } func convertToStandardized(rawValue: Double) -> Double { - if rawValue == type(of: self).defaultRawValue { - return rawValue - } - guard let stageHeight = self.stageHeight else { return type(of: self).defaultRawValue } - return stageHeight * rawValue - stageHeight / 2.0 + stageHeight * rawValue - stageHeight / 2.0 } func formulaEditorSections(for spriteObject: SpriteObject) -> [FormulaEditorSection] { diff --git a/src/Catty/PlayerEngine/Sensors/FacePose/RightEyebrowOuterXSensor.swift b/src/Catty/PlayerEngine/Sensors/FacePose/RightEyebrowOuterXSensor.swift index 713489318f..a15c435b13 100644 --- a/src/Catty/PlayerEngine/Sensors/FacePose/RightEyebrowOuterXSensor.swift +++ b/src/Catty/PlayerEngine/Sensors/FacePose/RightEyebrowOuterXSensor.swift @@ -29,10 +29,12 @@ class RightEyebrowOuterXSensor: DeviceDoubleSensor { static let requiredResource = ResourceType.faceDetection let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageWidth: Double? + let stageSize: CGSize + var stageWidth: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageWidth = Double(stageSize.width) } @@ -41,17 +43,13 @@ class RightEyebrowOuterXSensor: DeviceDoubleSensor { } func rawValue(landscapeMode: Bool) -> Double { + stageWidth = Double(landscapeMode ? stageSize.height : stageSize.width) guard let positionX = self.getVisualDetectionManager()?.faceLandmarkPositionRatioDictionary[self.tag()] else { return type(of: self).defaultRawValue } return positionX } func convertToStandardized(rawValue: Double) -> Double { - if rawValue == type(of: self).defaultRawValue { - return rawValue - } - guard let stageWidth = self.stageWidth else { - return type(of: self).defaultRawValue } - return stageWidth * rawValue - stageWidth / 2.0 + stageWidth * rawValue - stageWidth / 2.0 } func formulaEditorSections(for spriteObject: SpriteObject) -> [FormulaEditorSection] { diff --git a/src/Catty/PlayerEngine/Sensors/FacePose/RightEyebrowOuterYSensor.swift b/src/Catty/PlayerEngine/Sensors/FacePose/RightEyebrowOuterYSensor.swift index de7652e6cf..d125b98d39 100644 --- a/src/Catty/PlayerEngine/Sensors/FacePose/RightEyebrowOuterYSensor.swift +++ b/src/Catty/PlayerEngine/Sensors/FacePose/RightEyebrowOuterYSensor.swift @@ -29,10 +29,12 @@ class RightEyebrowOuterYSensor: DeviceDoubleSensor { static let requiredResource = ResourceType.faceDetection let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageHeight: Double? + let stageSize: CGSize + var stageHeight: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageHeight = Double(stageSize.height) } @@ -41,16 +43,13 @@ class RightEyebrowOuterYSensor: DeviceDoubleSensor { } func rawValue(landscapeMode: Bool) -> Double { + stageHeight = Double(landscapeMode ? stageSize.width : stageSize.height) guard let positionY = self.getVisualDetectionManager()?.faceLandmarkPositionRatioDictionary[self.tag()] else { return type(of: self).defaultRawValue } return positionY } func convertToStandardized(rawValue: Double) -> Double { - if rawValue == type(of: self).defaultRawValue { - return rawValue - } - guard let stageHeight = self.stageHeight else { return type(of: self).defaultRawValue } - return stageHeight * rawValue - stageHeight / 2.0 + stageHeight * rawValue - stageHeight / 2.0 } func formulaEditorSections(for spriteObject: SpriteObject) -> [FormulaEditorSection] { diff --git a/src/Catty/PlayerEngine/Sensors/HandPose/LeftIndexKnuckleXSensor.swift b/src/Catty/PlayerEngine/Sensors/HandPose/LeftIndexKnuckleXSensor.swift index 77594fd2ed..0abce21f48 100644 --- a/src/Catty/PlayerEngine/Sensors/HandPose/LeftIndexKnuckleXSensor.swift +++ b/src/Catty/PlayerEngine/Sensors/HandPose/LeftIndexKnuckleXSensor.swift @@ -29,10 +29,12 @@ class LeftIndexKnuckleXSensor: DeviceDoubleSensor { static let requiredResource = ResourceType.handPoseDetection let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageWidth: Double? + let stageSize: CGSize + var stageWidth: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageWidth = Double(stageSize.width) } @@ -41,17 +43,13 @@ class LeftIndexKnuckleXSensor: DeviceDoubleSensor { } func rawValue(landscapeMode: Bool) -> Double { + stageWidth = Double(landscapeMode ? stageSize.height : stageSize.width) guard let positionX = self.getVisualDetectionManager()?.handPosePositionRatioDictionary[self.tag()] else { return type(of: self).defaultRawValue } return positionX } func convertToStandardized(rawValue: Double) -> Double { - if rawValue == type(of: self).defaultRawValue { - return rawValue - } - guard let stageWidth = self.stageWidth else { - return type(of: self).defaultRawValue } - return stageWidth * rawValue - stageWidth / 2.0 + stageWidth * rawValue - stageWidth / 2.0 } func formulaEditorSections(for spriteObject: SpriteObject) -> [FormulaEditorSection] { diff --git a/src/Catty/PlayerEngine/Sensors/HandPose/LeftIndexKnuckleYSensor.swift b/src/Catty/PlayerEngine/Sensors/HandPose/LeftIndexKnuckleYSensor.swift index 0ac655828b..15817c35eb 100644 --- a/src/Catty/PlayerEngine/Sensors/HandPose/LeftIndexKnuckleYSensor.swift +++ b/src/Catty/PlayerEngine/Sensors/HandPose/LeftIndexKnuckleYSensor.swift @@ -29,10 +29,12 @@ class LeftIndexKnuckleYSensor: DeviceDoubleSensor { static let requiredResource = ResourceType.handPoseDetection let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageHeight: Double? + let stageSize: CGSize + var stageHeight: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageHeight = Double(stageSize.height) } @@ -41,16 +43,13 @@ class LeftIndexKnuckleYSensor: DeviceDoubleSensor { } func rawValue(landscapeMode: Bool) -> Double { + stageHeight = Double(landscapeMode ? stageSize.width : stageSize.height) guard let positionY = self.getVisualDetectionManager()?.handPosePositionRatioDictionary[self.tag()] else { return type(of: self).defaultRawValue } return positionY } func convertToStandardized(rawValue: Double) -> Double { - if rawValue == type(of: self).defaultRawValue { - return rawValue - } - guard let stageHeight = self.stageHeight else { return type(of: self).defaultRawValue } - return stageHeight * rawValue - stageHeight / 2.0 + stageHeight * rawValue - stageHeight / 2.0 } func formulaEditorSections(for spriteObject: SpriteObject) -> [FormulaEditorSection] { diff --git a/src/Catty/PlayerEngine/Sensors/HandPose/LeftMiddleFingerKnuckleXSensor.swift b/src/Catty/PlayerEngine/Sensors/HandPose/LeftMiddleFingerKnuckleXSensor.swift index dd7461124c..f094b35141 100644 --- a/src/Catty/PlayerEngine/Sensors/HandPose/LeftMiddleFingerKnuckleXSensor.swift +++ b/src/Catty/PlayerEngine/Sensors/HandPose/LeftMiddleFingerKnuckleXSensor.swift @@ -29,10 +29,12 @@ class LeftMiddleFingerKnuckleXSensor: DeviceDoubleSensor { static let requiredResource = ResourceType.handPoseDetection let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageWidth: Double? + let stageSize: CGSize + var stageWidth: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageWidth = Double(stageSize.width) } @@ -41,17 +43,13 @@ class LeftMiddleFingerKnuckleXSensor: DeviceDoubleSensor { } func rawValue(landscapeMode: Bool) -> Double { + stageWidth = Double(landscapeMode ? stageSize.height : stageSize.width) guard let positionX = self.getVisualDetectionManager()?.handPosePositionRatioDictionary[self.tag()] else { return type(of: self).defaultRawValue } return positionX } func convertToStandardized(rawValue: Double) -> Double { - if rawValue == type(of: self).defaultRawValue { - return rawValue - } - guard let stageWidth = self.stageWidth else { - return type(of: self).defaultRawValue } - return stageWidth * rawValue - stageWidth / 2.0 + stageWidth * rawValue - stageWidth / 2.0 } func formulaEditorSections(for spriteObject: SpriteObject) -> [FormulaEditorSection] { diff --git a/src/Catty/PlayerEngine/Sensors/HandPose/LeftMiddleFingerKnuckleYSensor.swift b/src/Catty/PlayerEngine/Sensors/HandPose/LeftMiddleFingerKnuckleYSensor.swift index 2f1951fdfa..1a82c46069 100644 --- a/src/Catty/PlayerEngine/Sensors/HandPose/LeftMiddleFingerKnuckleYSensor.swift +++ b/src/Catty/PlayerEngine/Sensors/HandPose/LeftMiddleFingerKnuckleYSensor.swift @@ -29,10 +29,12 @@ class LeftMiddleFingerKnuckleYSensor: DeviceDoubleSensor { static let requiredResource = ResourceType.handPoseDetection let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageHeight: Double? + let stageSize: CGSize + var stageHeight: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageHeight = Double(stageSize.height) } @@ -41,16 +43,13 @@ class LeftMiddleFingerKnuckleYSensor: DeviceDoubleSensor { } func rawValue(landscapeMode: Bool) -> Double { + stageHeight = Double(landscapeMode ? stageSize.width : stageSize.height) guard let positionY = self.getVisualDetectionManager()?.handPosePositionRatioDictionary[self.tag()] else { return type(of: self).defaultRawValue } return positionY } func convertToStandardized(rawValue: Double) -> Double { - if rawValue == type(of: self).defaultRawValue { - return rawValue - } - guard let stageHeight = self.stageHeight else { return type(of: self).defaultRawValue } - return stageHeight * rawValue - stageHeight / 2.0 + stageHeight * rawValue - stageHeight / 2.0 } func formulaEditorSections(for spriteObject: SpriteObject) -> [FormulaEditorSection] { diff --git a/src/Catty/PlayerEngine/Sensors/HandPose/LeftPinkyKnuckleXSensor.swift b/src/Catty/PlayerEngine/Sensors/HandPose/LeftPinkyKnuckleXSensor.swift index 4a4b1bfee6..37ae699558 100644 --- a/src/Catty/PlayerEngine/Sensors/HandPose/LeftPinkyKnuckleXSensor.swift +++ b/src/Catty/PlayerEngine/Sensors/HandPose/LeftPinkyKnuckleXSensor.swift @@ -29,10 +29,12 @@ class LeftPinkyKnuckleXSensor: DeviceDoubleSensor { static let requiredResource = ResourceType.handPoseDetection let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageWidth: Double? + let stageSize: CGSize + var stageWidth: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageWidth = Double(stageSize.width) } @@ -41,17 +43,13 @@ class LeftPinkyKnuckleXSensor: DeviceDoubleSensor { } func rawValue(landscapeMode: Bool) -> Double { + stageWidth = Double(landscapeMode ? stageSize.height : stageSize.width) guard let positionX = self.getVisualDetectionManager()?.handPosePositionRatioDictionary[self.tag()] else { return type(of: self).defaultRawValue } return positionX } func convertToStandardized(rawValue: Double) -> Double { - if rawValue == type(of: self).defaultRawValue { - return rawValue - } - guard let stageWidth = self.stageWidth else { - return type(of: self).defaultRawValue } - return stageWidth * rawValue - stageWidth / 2.0 + stageWidth * rawValue - stageWidth / 2.0 } func formulaEditorSections(for spriteObject: SpriteObject) -> [FormulaEditorSection] { diff --git a/src/Catty/PlayerEngine/Sensors/HandPose/LeftPinkyKnuckleYSensor.swift b/src/Catty/PlayerEngine/Sensors/HandPose/LeftPinkyKnuckleYSensor.swift index a79721f3f8..1352aa159f 100644 --- a/src/Catty/PlayerEngine/Sensors/HandPose/LeftPinkyKnuckleYSensor.swift +++ b/src/Catty/PlayerEngine/Sensors/HandPose/LeftPinkyKnuckleYSensor.swift @@ -29,10 +29,12 @@ class LeftPinkyKnuckleYSensor: DeviceDoubleSensor { static let requiredResource = ResourceType.handPoseDetection let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageHeight: Double? + let stageSize: CGSize + var stageHeight: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageHeight = Double(stageSize.height) } @@ -41,16 +43,13 @@ class LeftPinkyKnuckleYSensor: DeviceDoubleSensor { } func rawValue(landscapeMode: Bool) -> Double { + stageHeight = Double(landscapeMode ? stageSize.width : stageSize.height) guard let positionY = self.getVisualDetectionManager()?.handPosePositionRatioDictionary[self.tag()] else { return type(of: self).defaultRawValue } return positionY } func convertToStandardized(rawValue: Double) -> Double { - if rawValue == type(of: self).defaultRawValue { - return rawValue - } - guard let stageHeight = self.stageHeight else { return type(of: self).defaultRawValue } - return stageHeight * rawValue - stageHeight / 2.0 + stageHeight * rawValue - stageHeight / 2.0 } func formulaEditorSections(for spriteObject: SpriteObject) -> [FormulaEditorSection] { diff --git a/src/Catty/PlayerEngine/Sensors/HandPose/LeftRingFingerKnuckleXSensor.swift b/src/Catty/PlayerEngine/Sensors/HandPose/LeftRingFingerKnuckleXSensor.swift index 7252261ce2..1b30b7e3bb 100644 --- a/src/Catty/PlayerEngine/Sensors/HandPose/LeftRingFingerKnuckleXSensor.swift +++ b/src/Catty/PlayerEngine/Sensors/HandPose/LeftRingFingerKnuckleXSensor.swift @@ -29,10 +29,12 @@ class LeftRingFingerKnuckleXSensor: DeviceDoubleSensor { static let requiredResource = ResourceType.handPoseDetection let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageWidth: Double? + let stageSize: CGSize + var stageWidth: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageWidth = Double(stageSize.width) } @@ -41,17 +43,13 @@ class LeftRingFingerKnuckleXSensor: DeviceDoubleSensor { } func rawValue(landscapeMode: Bool) -> Double { + stageWidth = Double(landscapeMode ? stageSize.height : stageSize.width) guard let positionX = self.getVisualDetectionManager()?.handPosePositionRatioDictionary[self.tag()] else { return type(of: self).defaultRawValue } return positionX } func convertToStandardized(rawValue: Double) -> Double { - if rawValue == type(of: self).defaultRawValue { - return rawValue - } - guard let stageWidth = self.stageWidth else { - return type(of: self).defaultRawValue } - return stageWidth * rawValue - stageWidth / 2.0 + stageWidth * rawValue - stageWidth / 2.0 } func formulaEditorSections(for spriteObject: SpriteObject) -> [FormulaEditorSection] { diff --git a/src/Catty/PlayerEngine/Sensors/HandPose/LeftRingFingerKnuckleYSensor.swift b/src/Catty/PlayerEngine/Sensors/HandPose/LeftRingFingerKnuckleYSensor.swift index f4dc18128a..a1e6f6d7c6 100644 --- a/src/Catty/PlayerEngine/Sensors/HandPose/LeftRingFingerKnuckleYSensor.swift +++ b/src/Catty/PlayerEngine/Sensors/HandPose/LeftRingFingerKnuckleYSensor.swift @@ -29,10 +29,12 @@ class LeftRingFingerKnuckleYSensor: DeviceDoubleSensor { static let requiredResource = ResourceType.handPoseDetection let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageHeight: Double? + let stageSize: CGSize + var stageHeight: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageHeight = Double(stageSize.height) } @@ -41,16 +43,13 @@ class LeftRingFingerKnuckleYSensor: DeviceDoubleSensor { } func rawValue(landscapeMode: Bool) -> Double { + stageHeight = Double(landscapeMode ? stageSize.width : stageSize.height) guard let positionY = self.getVisualDetectionManager()?.handPosePositionRatioDictionary[self.tag()] else { return type(of: self).defaultRawValue } return positionY } func convertToStandardized(rawValue: Double) -> Double { - if rawValue == type(of: self).defaultRawValue { - return rawValue - } - guard let stageHeight = self.stageHeight else { return type(of: self).defaultRawValue } - return stageHeight * rawValue - stageHeight / 2.0 + stageHeight * rawValue - stageHeight / 2.0 } func formulaEditorSections(for spriteObject: SpriteObject) -> [FormulaEditorSection] { diff --git a/src/Catty/PlayerEngine/Sensors/HandPose/LeftThumbKnuckleXSensor.swift b/src/Catty/PlayerEngine/Sensors/HandPose/LeftThumbKnuckleXSensor.swift index 9343b91e8f..aa6091cabd 100644 --- a/src/Catty/PlayerEngine/Sensors/HandPose/LeftThumbKnuckleXSensor.swift +++ b/src/Catty/PlayerEngine/Sensors/HandPose/LeftThumbKnuckleXSensor.swift @@ -29,10 +29,12 @@ class LeftThumbKnuckleXSensor: DeviceDoubleSensor { static let requiredResource = ResourceType.handPoseDetection let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageWidth: Double? + let stageSize: CGSize + var stageWidth: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageWidth = Double(stageSize.width) } @@ -41,17 +43,13 @@ class LeftThumbKnuckleXSensor: DeviceDoubleSensor { } func rawValue(landscapeMode: Bool) -> Double { + stageWidth = Double(landscapeMode ? stageSize.height : stageSize.width) guard let positionX = self.getVisualDetectionManager()?.handPosePositionRatioDictionary[self.tag()] else { return type(of: self).defaultRawValue } return positionX } func convertToStandardized(rawValue: Double) -> Double { - if rawValue == type(of: self).defaultRawValue { - return rawValue - } - guard let stageWidth = self.stageWidth else { - return type(of: self).defaultRawValue } - return stageWidth * rawValue - stageWidth / 2.0 + stageWidth * rawValue - stageWidth / 2.0 } func formulaEditorSections(for spriteObject: SpriteObject) -> [FormulaEditorSection] { diff --git a/src/Catty/PlayerEngine/Sensors/HandPose/LeftThumbKnuckleYSensor.swift b/src/Catty/PlayerEngine/Sensors/HandPose/LeftThumbKnuckleYSensor.swift index e0ca483bcc..c5b38e6aa3 100644 --- a/src/Catty/PlayerEngine/Sensors/HandPose/LeftThumbKnuckleYSensor.swift +++ b/src/Catty/PlayerEngine/Sensors/HandPose/LeftThumbKnuckleYSensor.swift @@ -29,10 +29,12 @@ class LeftThumbKnuckleYSensor: DeviceDoubleSensor { static let requiredResource = ResourceType.handPoseDetection let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageHeight: Double? + let stageSize: CGSize + var stageHeight: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageHeight = Double(stageSize.height) } @@ -41,16 +43,13 @@ class LeftThumbKnuckleYSensor: DeviceDoubleSensor { } func rawValue(landscapeMode: Bool) -> Double { + stageHeight = Double(landscapeMode ? stageSize.width : stageSize.height) guard let positionY = self.getVisualDetectionManager()?.handPosePositionRatioDictionary[self.tag()] else { return type(of: self).defaultRawValue } return positionY } func convertToStandardized(rawValue: Double) -> Double { - if rawValue == type(of: self).defaultRawValue { - return rawValue - } - guard let stageHeight = self.stageHeight else { return type(of: self).defaultRawValue } - return stageHeight * rawValue - stageHeight / 2.0 + stageHeight * rawValue - stageHeight / 2.0 } func formulaEditorSections(for spriteObject: SpriteObject) -> [FormulaEditorSection] { diff --git a/src/Catty/PlayerEngine/Sensors/HandPose/RightIndexKnuckleXSensor.swift b/src/Catty/PlayerEngine/Sensors/HandPose/RightIndexKnuckleXSensor.swift index 268f564189..dce42b185a 100644 --- a/src/Catty/PlayerEngine/Sensors/HandPose/RightIndexKnuckleXSensor.swift +++ b/src/Catty/PlayerEngine/Sensors/HandPose/RightIndexKnuckleXSensor.swift @@ -29,10 +29,12 @@ class RightIndexKnuckleXSensor: DeviceDoubleSensor { static let requiredResource = ResourceType.handPoseDetection let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageWidth: Double? + let stageSize: CGSize + var stageWidth: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageWidth = Double(stageSize.width) } @@ -41,17 +43,13 @@ class RightIndexKnuckleXSensor: DeviceDoubleSensor { } func rawValue(landscapeMode: Bool) -> Double { + stageWidth = Double(landscapeMode ? stageSize.height : stageSize.width) guard let positionX = self.getVisualDetectionManager()?.handPosePositionRatioDictionary[self.tag()] else { return type(of: self).defaultRawValue } return positionX } func convertToStandardized(rawValue: Double) -> Double { - if rawValue == type(of: self).defaultRawValue { - return rawValue - } - guard let stageWidth = self.stageWidth else { - return type(of: self).defaultRawValue } - return stageWidth * rawValue - stageWidth / 2.0 + stageWidth * rawValue - stageWidth / 2.0 } func formulaEditorSections(for spriteObject: SpriteObject) -> [FormulaEditorSection] { diff --git a/src/Catty/PlayerEngine/Sensors/HandPose/RightIndexKnuckleYSensor.swift b/src/Catty/PlayerEngine/Sensors/HandPose/RightIndexKnuckleYSensor.swift index 5e6451795f..2e7b4c8f6e 100644 --- a/src/Catty/PlayerEngine/Sensors/HandPose/RightIndexKnuckleYSensor.swift +++ b/src/Catty/PlayerEngine/Sensors/HandPose/RightIndexKnuckleYSensor.swift @@ -29,10 +29,12 @@ class RightIndexKnuckleYSensor: DeviceDoubleSensor { static let requiredResource = ResourceType.handPoseDetection let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageHeight: Double? + let stageSize: CGSize + var stageHeight: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageHeight = Double(stageSize.height) } @@ -41,16 +43,13 @@ class RightIndexKnuckleYSensor: DeviceDoubleSensor { } func rawValue(landscapeMode: Bool) -> Double { + stageHeight = Double(landscapeMode ? stageSize.width : stageSize.height) guard let positionY = self.getVisualDetectionManager()?.handPosePositionRatioDictionary[self.tag()] else { return type(of: self).defaultRawValue } return positionY } func convertToStandardized(rawValue: Double) -> Double { - if rawValue == type(of: self).defaultRawValue { - return rawValue - } - guard let stageHeight = self.stageHeight else { return type(of: self).defaultRawValue } - return stageHeight * rawValue - stageHeight / 2.0 + stageHeight * rawValue - stageHeight / 2.0 } func formulaEditorSections(for spriteObject: SpriteObject) -> [FormulaEditorSection] { diff --git a/src/Catty/PlayerEngine/Sensors/HandPose/RightMiddleFingerKnuckleXSensor.swift b/src/Catty/PlayerEngine/Sensors/HandPose/RightMiddleFingerKnuckleXSensor.swift index 34c671f96f..25bd8c3552 100644 --- a/src/Catty/PlayerEngine/Sensors/HandPose/RightMiddleFingerKnuckleXSensor.swift +++ b/src/Catty/PlayerEngine/Sensors/HandPose/RightMiddleFingerKnuckleXSensor.swift @@ -29,10 +29,12 @@ class RightMiddleFingerKnuckleXSensor: DeviceDoubleSensor { static let requiredResource = ResourceType.handPoseDetection let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageWidth: Double? + let stageSize: CGSize + var stageWidth: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageWidth = Double(stageSize.width) } @@ -41,17 +43,13 @@ class RightMiddleFingerKnuckleXSensor: DeviceDoubleSensor { } func rawValue(landscapeMode: Bool) -> Double { + stageWidth = Double(landscapeMode ? stageSize.height : stageSize.width) guard let positionX = self.getVisualDetectionManager()?.handPosePositionRatioDictionary[self.tag()] else { return type(of: self).defaultRawValue } return positionX } func convertToStandardized(rawValue: Double) -> Double { - if rawValue == type(of: self).defaultRawValue { - return rawValue - } - guard let stageWidth = self.stageWidth else { - return type(of: self).defaultRawValue } - return stageWidth * rawValue - stageWidth / 2.0 + stageWidth * rawValue - stageWidth / 2.0 } func formulaEditorSections(for spriteObject: SpriteObject) -> [FormulaEditorSection] { diff --git a/src/Catty/PlayerEngine/Sensors/HandPose/RightMiddleFingerKnuckleYSensor.swift b/src/Catty/PlayerEngine/Sensors/HandPose/RightMiddleFingerKnuckleYSensor.swift index fbe8399e32..aa0614db7f 100644 --- a/src/Catty/PlayerEngine/Sensors/HandPose/RightMiddleFingerKnuckleYSensor.swift +++ b/src/Catty/PlayerEngine/Sensors/HandPose/RightMiddleFingerKnuckleYSensor.swift @@ -29,10 +29,12 @@ class RightMiddleFingerKnuckleYSensor: DeviceDoubleSensor { static let requiredResource = ResourceType.handPoseDetection let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageHeight: Double? + let stageSize: CGSize + var stageHeight: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageHeight = Double(stageSize.height) } @@ -41,16 +43,13 @@ class RightMiddleFingerKnuckleYSensor: DeviceDoubleSensor { } func rawValue(landscapeMode: Bool) -> Double { + stageHeight = Double(landscapeMode ? stageSize.width : stageSize.height) guard let positionY = self.getVisualDetectionManager()?.handPosePositionRatioDictionary[self.tag()] else { return type(of: self).defaultRawValue } return positionY } func convertToStandardized(rawValue: Double) -> Double { - if rawValue == type(of: self).defaultRawValue { - return rawValue - } - guard let stageHeight = self.stageHeight else { return type(of: self).defaultRawValue } - return stageHeight * rawValue - stageHeight / 2.0 + stageHeight * rawValue - stageHeight / 2.0 } func formulaEditorSections(for spriteObject: SpriteObject) -> [FormulaEditorSection] { diff --git a/src/Catty/PlayerEngine/Sensors/HandPose/RightPinkyKnuckleXSensor.swift b/src/Catty/PlayerEngine/Sensors/HandPose/RightPinkyKnuckleXSensor.swift index 19be06b7b2..980689b7e0 100644 --- a/src/Catty/PlayerEngine/Sensors/HandPose/RightPinkyKnuckleXSensor.swift +++ b/src/Catty/PlayerEngine/Sensors/HandPose/RightPinkyKnuckleXSensor.swift @@ -29,10 +29,12 @@ class RightPinkyKnuckleXSensor: DeviceDoubleSensor { static let requiredResource = ResourceType.handPoseDetection let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageWidth: Double? + let stageSize: CGSize + var stageWidth: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageWidth = Double(stageSize.width) } @@ -41,17 +43,13 @@ class RightPinkyKnuckleXSensor: DeviceDoubleSensor { } func rawValue(landscapeMode: Bool) -> Double { + stageWidth = Double(landscapeMode ? stageSize.height : stageSize.width) guard let positionX = self.getVisualDetectionManager()?.handPosePositionRatioDictionary[self.tag()] else { return type(of: self).defaultRawValue } return positionX } func convertToStandardized(rawValue: Double) -> Double { - if rawValue == type(of: self).defaultRawValue { - return rawValue - } - guard let stageWidth = self.stageWidth else { - return type(of: self).defaultRawValue } - return stageWidth * rawValue - stageWidth / 2.0 + stageWidth * rawValue - stageWidth / 2.0 } func formulaEditorSections(for spriteObject: SpriteObject) -> [FormulaEditorSection] { diff --git a/src/Catty/PlayerEngine/Sensors/HandPose/RightPinkyKnuckleYSensor.swift b/src/Catty/PlayerEngine/Sensors/HandPose/RightPinkyKnuckleYSensor.swift index be73328cc2..d2faad851e 100644 --- a/src/Catty/PlayerEngine/Sensors/HandPose/RightPinkyKnuckleYSensor.swift +++ b/src/Catty/PlayerEngine/Sensors/HandPose/RightPinkyKnuckleYSensor.swift @@ -29,10 +29,12 @@ class RightPinkyKnuckleYSensor: DeviceDoubleSensor { static let requiredResource = ResourceType.handPoseDetection let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageHeight: Double? + let stageSize: CGSize + var stageHeight: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageHeight = Double(stageSize.height) } @@ -41,16 +43,13 @@ class RightPinkyKnuckleYSensor: DeviceDoubleSensor { } func rawValue(landscapeMode: Bool) -> Double { + stageHeight = Double(landscapeMode ? stageSize.width : stageSize.height) guard let positionY = self.getVisualDetectionManager()?.handPosePositionRatioDictionary[self.tag()] else { return type(of: self).defaultRawValue } return positionY } func convertToStandardized(rawValue: Double) -> Double { - if rawValue == type(of: self).defaultRawValue { - return rawValue - } - guard let stageHeight = self.stageHeight else { return type(of: self).defaultRawValue } - return stageHeight * rawValue - stageHeight / 2.0 + stageHeight * rawValue - stageHeight / 2.0 } func formulaEditorSections(for spriteObject: SpriteObject) -> [FormulaEditorSection] { diff --git a/src/Catty/PlayerEngine/Sensors/HandPose/RightRingFingerKnuckleXSensor.swift b/src/Catty/PlayerEngine/Sensors/HandPose/RightRingFingerKnuckleXSensor.swift index 5ab3b49154..356ae0064f 100644 --- a/src/Catty/PlayerEngine/Sensors/HandPose/RightRingFingerKnuckleXSensor.swift +++ b/src/Catty/PlayerEngine/Sensors/HandPose/RightRingFingerKnuckleXSensor.swift @@ -29,10 +29,12 @@ class RightRingFingerKnuckleXSensor: DeviceDoubleSensor { static let requiredResource = ResourceType.handPoseDetection let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageWidth: Double? + let stageSize: CGSize + var stageWidth: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageWidth = Double(stageSize.width) } @@ -41,17 +43,13 @@ class RightRingFingerKnuckleXSensor: DeviceDoubleSensor { } func rawValue(landscapeMode: Bool) -> Double { + stageWidth = Double(landscapeMode ? stageSize.height : stageSize.width) guard let positionX = self.getVisualDetectionManager()?.handPosePositionRatioDictionary[self.tag()] else { return type(of: self).defaultRawValue } return positionX } func convertToStandardized(rawValue: Double) -> Double { - if rawValue == type(of: self).defaultRawValue { - return rawValue - } - guard let stageWidth = self.stageWidth else { - return type(of: self).defaultRawValue } - return stageWidth * rawValue - stageWidth / 2.0 + stageWidth * rawValue - stageWidth / 2.0 } func formulaEditorSections(for spriteObject: SpriteObject) -> [FormulaEditorSection] { diff --git a/src/Catty/PlayerEngine/Sensors/HandPose/RightRingFingerKnuckleYSensor.swift b/src/Catty/PlayerEngine/Sensors/HandPose/RightRingFingerKnuckleYSensor.swift index 55c40a20f7..2136d7b10d 100644 --- a/src/Catty/PlayerEngine/Sensors/HandPose/RightRingFingerKnuckleYSensor.swift +++ b/src/Catty/PlayerEngine/Sensors/HandPose/RightRingFingerKnuckleYSensor.swift @@ -29,10 +29,12 @@ class RightRingFingerKnuckleYSensor: DeviceDoubleSensor { static let requiredResource = ResourceType.handPoseDetection let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageHeight: Double? + let stageSize: CGSize + var stageHeight: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageHeight = Double(stageSize.height) } @@ -41,16 +43,13 @@ class RightRingFingerKnuckleYSensor: DeviceDoubleSensor { } func rawValue(landscapeMode: Bool) -> Double { + stageHeight = Double(landscapeMode ? stageSize.width : stageSize.height) guard let positionY = self.getVisualDetectionManager()?.handPosePositionRatioDictionary[self.tag()] else { return type(of: self).defaultRawValue } return positionY } func convertToStandardized(rawValue: Double) -> Double { - if rawValue == type(of: self).defaultRawValue { - return rawValue - } - guard let stageHeight = self.stageHeight else { return type(of: self).defaultRawValue } - return stageHeight * rawValue - stageHeight / 2.0 + stageHeight * rawValue - stageHeight / 2.0 } func formulaEditorSections(for spriteObject: SpriteObject) -> [FormulaEditorSection] { diff --git a/src/Catty/PlayerEngine/Sensors/HandPose/RightThumbKnuckleXSensor.swift b/src/Catty/PlayerEngine/Sensors/HandPose/RightThumbKnuckleXSensor.swift index ad2839c52b..552dd8f8b8 100644 --- a/src/Catty/PlayerEngine/Sensors/HandPose/RightThumbKnuckleXSensor.swift +++ b/src/Catty/PlayerEngine/Sensors/HandPose/RightThumbKnuckleXSensor.swift @@ -29,10 +29,12 @@ class RightThumbKnuckleXSensor: DeviceDoubleSensor { static let requiredResource = ResourceType.handPoseDetection let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageWidth: Double? + let stageSize: CGSize + var stageWidth: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageWidth = Double(stageSize.width) } @@ -41,17 +43,13 @@ class RightThumbKnuckleXSensor: DeviceDoubleSensor { } func rawValue(landscapeMode: Bool) -> Double { + stageWidth = Double(landscapeMode ? stageSize.height : stageSize.width) guard let positionX = self.getVisualDetectionManager()?.handPosePositionRatioDictionary[self.tag()] else { return type(of: self).defaultRawValue } return positionX } func convertToStandardized(rawValue: Double) -> Double { - if rawValue == type(of: self).defaultRawValue { - return rawValue - } - guard let stageWidth = self.stageWidth else { - return type(of: self).defaultRawValue } - return stageWidth * rawValue - stageWidth / 2.0 + stageWidth * rawValue - stageWidth / 2.0 } func formulaEditorSections(for spriteObject: SpriteObject) -> [FormulaEditorSection] { diff --git a/src/Catty/PlayerEngine/Sensors/HandPose/RightThumbKnuckleYSensor.swift b/src/Catty/PlayerEngine/Sensors/HandPose/RightThumbKnuckleYSensor.swift index c1f8382565..dcd1144d0d 100644 --- a/src/Catty/PlayerEngine/Sensors/HandPose/RightThumbKnuckleYSensor.swift +++ b/src/Catty/PlayerEngine/Sensors/HandPose/RightThumbKnuckleYSensor.swift @@ -29,10 +29,12 @@ class RightThumbKnuckleYSensor: DeviceDoubleSensor { static let requiredResource = ResourceType.handPoseDetection let getVisualDetectionManager: () -> VisualDetectionManagerProtocol? - let stageHeight: Double? + let stageSize: CGSize + var stageHeight: Double init(stageSize: CGSize, visualDetectionManagerGetter: @escaping () -> VisualDetectionManagerProtocol?) { self.getVisualDetectionManager = visualDetectionManagerGetter + self.stageSize = stageSize self.stageHeight = Double(stageSize.height) } @@ -41,16 +43,13 @@ class RightThumbKnuckleYSensor: DeviceDoubleSensor { } func rawValue(landscapeMode: Bool) -> Double { + stageHeight = Double(landscapeMode ? stageSize.width : stageSize.height) guard let positionY = self.getVisualDetectionManager()?.handPosePositionRatioDictionary[self.tag()] else { return type(of: self).defaultRawValue } return positionY } func convertToStandardized(rawValue: Double) -> Double { - if rawValue == type(of: self).defaultRawValue { - return rawValue - } - guard let stageHeight = self.stageHeight else { return type(of: self).defaultRawValue } - return stageHeight * rawValue - stageHeight / 2.0 + stageHeight * rawValue - stageHeight / 2.0 } func formulaEditorSections(for spriteObject: SpriteObject) -> [FormulaEditorSection] { diff --git a/src/CattyTests/PlayerEngine/Functions/ObjectRecognition/ObjectRecognitionFunctionsTest.swift b/src/CattyTests/PlayerEngine/Functions/ObjectRecognition/ObjectRecognitionFunctionsTest.swift index 1514e354b7..5c634d00fa 100644 --- a/src/CattyTests/PlayerEngine/Functions/ObjectRecognition/ObjectRecognitionFunctionsTest.swift +++ b/src/CattyTests/PlayerEngine/Functions/ObjectRecognition/ObjectRecognitionFunctionsTest.swift @@ -96,25 +96,29 @@ class ObjectRecognitionFunctionsTest: XCTestCase { let labelOfObjectWithIDFunction = LabelOfObjectWithIDFunction(visualDetectionManagerGetter: { nil }) XCTAssertEqual(type(of: labelOfObjectWithIDFunction).defaultValue, labelOfObjectWithIDFunction.value(parameter: 1 as AnyObject)) - XCTAssertEqual(type(of: xOfObjectWithIDFunction).defaultValue, xOfObjectWithIDFunction.value(parameter: "invalidParameter" as AnyObject), accuracy: Double.epsilon) - XCTAssertEqual(type(of: xOfObjectWithIDFunction).defaultValue, xOfObjectWithIDFunction.value(parameter: nil), accuracy: Double.epsilon) + XCTAssertEqual(type(of: xOfObjectWithIDFunction).defaultValue, xOfObjectWithIDFunction.value(parameter: "invalidParameter" as AnyObject, landscapeMode: false), accuracy: Double.epsilon) + XCTAssertEqual(type(of: xOfObjectWithIDFunction).defaultValue, xOfObjectWithIDFunction.value(parameter: nil, landscapeMode: false), accuracy: Double.epsilon) let xOfObjectWithIDFunction = XOfObjectWithIDFunction(stageSize: stageSize, visualDetectionManagerGetter: { nil }) - XCTAssertEqual(type(of: xOfObjectWithIDFunction).defaultValue, xOfObjectWithIDFunction.value(parameter: 1 as AnyObject), accuracy: Double.epsilon) + XCTAssertEqual(type(of: xOfObjectWithIDFunction).defaultValue, xOfObjectWithIDFunction.value(parameter: 1 as AnyObject, landscapeMode: false), accuracy: Double.epsilon) - XCTAssertEqual(type(of: yOfObjectWithIDFunction).defaultValue, yOfObjectWithIDFunction.value(parameter: "invalidParameter" as AnyObject), accuracy: Double.epsilon) - XCTAssertEqual(type(of: yOfObjectWithIDFunction).defaultValue, yOfObjectWithIDFunction.value(parameter: nil), accuracy: Double.epsilon) + XCTAssertEqual(type(of: yOfObjectWithIDFunction).defaultValue, yOfObjectWithIDFunction.value(parameter: "invalidParameter" as AnyObject, landscapeMode: false), accuracy: Double.epsilon) + XCTAssertEqual(type(of: yOfObjectWithIDFunction).defaultValue, yOfObjectWithIDFunction.value(parameter: nil, landscapeMode: false), accuracy: Double.epsilon) let yOfObjectWithIDFunction = YOfObjectWithIDFunction(stageSize: stageSize, visualDetectionManagerGetter: { nil }) - XCTAssertEqual(type(of: yOfObjectWithIDFunction).defaultValue, yOfObjectWithIDFunction.value(parameter: 1 as AnyObject), accuracy: Double.epsilon) + XCTAssertEqual(type(of: yOfObjectWithIDFunction).defaultValue, yOfObjectWithIDFunction.value(parameter: 1 as AnyObject, landscapeMode: false), accuracy: Double.epsilon) - XCTAssertEqual(type(of: widthOfObjectWithIDFunction).defaultValue, widthOfObjectWithIDFunction.value(parameter: "invalidParameter" as AnyObject), accuracy: Double.epsilon) - XCTAssertEqual(type(of: widthOfObjectWithIDFunction).defaultValue, widthOfObjectWithIDFunction.value(parameter: nil), accuracy: Double.epsilon) + XCTAssertEqual(type(of: widthOfObjectWithIDFunction).defaultValue, + widthOfObjectWithIDFunction.value(parameter: "invalidParameter" as AnyObject, landscapeMode: false), + accuracy: Double.epsilon) + XCTAssertEqual(type(of: widthOfObjectWithIDFunction).defaultValue, widthOfObjectWithIDFunction.value(parameter: nil, landscapeMode: false), accuracy: Double.epsilon) let widthOfObjectWithIDFunction = WidthOfObjectWithIDFunction(stageSize: stageSize, visualDetectionManagerGetter: { nil }) - XCTAssertEqual(type(of: widthOfObjectWithIDFunction).defaultValue, widthOfObjectWithIDFunction.value(parameter: 1 as AnyObject), accuracy: Double.epsilon) + XCTAssertEqual(type(of: widthOfObjectWithIDFunction).defaultValue, widthOfObjectWithIDFunction.value(parameter: 1 as AnyObject, landscapeMode: false), accuracy: Double.epsilon) - XCTAssertEqual(type(of: heightOfObjectWithIDFunction).defaultValue, heightOfObjectWithIDFunction.value(parameter: "invalidParameter" as AnyObject), accuracy: Double.epsilon) - XCTAssertEqual(type(of: heightOfObjectWithIDFunction).defaultValue, heightOfObjectWithIDFunction.value(parameter: nil), accuracy: Double.epsilon) + XCTAssertEqual(type(of: heightOfObjectWithIDFunction).defaultValue, + heightOfObjectWithIDFunction.value(parameter: "invalidParameter" as AnyObject, landscapeMode: false), + accuracy: Double.epsilon) + XCTAssertEqual(type(of: heightOfObjectWithIDFunction).defaultValue, heightOfObjectWithIDFunction.value(parameter: nil, landscapeMode: false), accuracy: Double.epsilon) let heightOfObjectWithIDFunction = HeightOfObjectWithIDFunction(stageSize: stageSize, visualDetectionManagerGetter: { nil }) - XCTAssertEqual(type(of: heightOfObjectWithIDFunction).defaultValue, heightOfObjectWithIDFunction.value(parameter: 1 as AnyObject), accuracy: Double.epsilon) + XCTAssertEqual(type(of: heightOfObjectWithIDFunction).defaultValue, heightOfObjectWithIDFunction.value(parameter: 1 as AnyObject, landscapeMode: false), accuracy: Double.epsilon) } func testValue() { @@ -125,34 +129,34 @@ class ObjectRecognitionFunctionsTest: XCTestCase { XCTAssertEqual(type(of: idOfDetectedObjectFunction).defaultValue, idOfDetectedObjectFunction.value(parameter: 0 as AnyObject), accuracy: Double.epsilon) XCTAssertEqual(type(of: objectWithIDVisibleFunction).defaultValue, objectWithIDVisibleFunction.value(parameter: -1 as AnyObject), accuracy: Double.epsilon) XCTAssertEqual(type(of: labelOfObjectWithIDFunction).defaultValue, labelOfObjectWithIDFunction.value(parameter: -1 as AnyObject)) - XCTAssertEqual(type(of: xOfObjectWithIDFunction).defaultValue, xOfObjectWithIDFunction.value(parameter: -1 as AnyObject), accuracy: Double.epsilon) - XCTAssertEqual(type(of: yOfObjectWithIDFunction).defaultValue, yOfObjectWithIDFunction.value(parameter: -1 as AnyObject), accuracy: Double.epsilon) - XCTAssertEqual(type(of: widthOfObjectWithIDFunction).defaultValue, widthOfObjectWithIDFunction.value(parameter: -1 as AnyObject), accuracy: Double.epsilon) - XCTAssertEqual(type(of: heightOfObjectWithIDFunction).defaultValue, heightOfObjectWithIDFunction.value(parameter: -1 as AnyObject), accuracy: Double.epsilon) + XCTAssertEqual(type(of: xOfObjectWithIDFunction).defaultValue, xOfObjectWithIDFunction.value(parameter: -1 as AnyObject, landscapeMode: false), accuracy: Double.epsilon) + XCTAssertEqual(type(of: yOfObjectWithIDFunction).defaultValue, yOfObjectWithIDFunction.value(parameter: -1 as AnyObject, landscapeMode: false), accuracy: Double.epsilon) + XCTAssertEqual(type(of: widthOfObjectWithIDFunction).defaultValue, widthOfObjectWithIDFunction.value(parameter: -1 as AnyObject, landscapeMode: false), accuracy: Double.epsilon) + XCTAssertEqual(type(of: heightOfObjectWithIDFunction).defaultValue, heightOfObjectWithIDFunction.value(parameter: -1 as AnyObject, landscapeMode: false), accuracy: Double.epsilon) XCTAssertEqual(0.0, idOfDetectedObjectFunction.value(parameter: 1 as AnyObject), accuracy: Double.epsilon) XCTAssertEqual(1.0, objectWithIDVisibleFunction.value(parameter: 0 as AnyObject), accuracy: Double.epsilon) XCTAssertEqual("keyboard", labelOfObjectWithIDFunction.value(parameter: 0 as AnyObject)) - XCTAssertEqual(convertRatios(boundingBox: boundingBoxes[0], type: .x), xOfObjectWithIDFunction.value(parameter: 0 as AnyObject), accuracy: Double.epsilon) - XCTAssertEqual(convertRatios(boundingBox: boundingBoxes[0], type: .y), yOfObjectWithIDFunction.value(parameter: 0 as AnyObject), accuracy: Double.epsilon) - XCTAssertEqual(convertRatios(boundingBox: boundingBoxes[0], type: .width), widthOfObjectWithIDFunction.value(parameter: 0 as AnyObject), accuracy: Double.epsilon) - XCTAssertEqual(convertRatios(boundingBox: boundingBoxes[0], type: .height), heightOfObjectWithIDFunction.value(parameter: 0 as AnyObject), accuracy: Double.epsilon) + XCTAssertEqual(convertRatios(boundingBox: boundingBoxes[0], type: .x), xOfObjectWithIDFunction.value(parameter: 0 as AnyObject, landscapeMode: false), accuracy: Double.epsilon) + XCTAssertEqual(convertRatios(boundingBox: boundingBoxes[0], type: .y), yOfObjectWithIDFunction.value(parameter: 0 as AnyObject, landscapeMode: false), accuracy: Double.epsilon) + XCTAssertEqual(convertRatios(boundingBox: boundingBoxes[0], type: .width), widthOfObjectWithIDFunction.value(parameter: 0 as AnyObject, landscapeMode: false), accuracy: Double.epsilon) + XCTAssertEqual(convertRatios(boundingBox: boundingBoxes[0], type: .height), heightOfObjectWithIDFunction.value(parameter: 0 as AnyObject, landscapeMode: false), accuracy: Double.epsilon) XCTAssertEqual(1.0, idOfDetectedObjectFunction.value(parameter: 2 as AnyObject), accuracy: Double.epsilon) XCTAssertEqual(1.0, objectWithIDVisibleFunction.value(parameter: 1 as AnyObject), accuracy: Double.epsilon) XCTAssertEqual("mouse", labelOfObjectWithIDFunction.value(parameter: 1 as AnyObject)) - XCTAssertEqual(convertRatios(boundingBox: boundingBoxes[1], type: .x), xOfObjectWithIDFunction.value(parameter: 1 as AnyObject), accuracy: Double.epsilon) - XCTAssertEqual(convertRatios(boundingBox: boundingBoxes[1], type: .y), yOfObjectWithIDFunction.value(parameter: 1 as AnyObject), accuracy: Double.epsilon) - XCTAssertEqual(convertRatios(boundingBox: boundingBoxes[1], type: .width), widthOfObjectWithIDFunction.value(parameter: 1 as AnyObject), accuracy: Double.epsilon) - XCTAssertEqual(convertRatios(boundingBox: boundingBoxes[1], type: .height), heightOfObjectWithIDFunction.value(parameter: 1 as AnyObject), accuracy: Double.epsilon) + XCTAssertEqual(convertRatios(boundingBox: boundingBoxes[1], type: .x), xOfObjectWithIDFunction.value(parameter: 1 as AnyObject, landscapeMode: false), accuracy: Double.epsilon) + XCTAssertEqual(convertRatios(boundingBox: boundingBoxes[1], type: .y), yOfObjectWithIDFunction.value(parameter: 1 as AnyObject, landscapeMode: false), accuracy: Double.epsilon) + XCTAssertEqual(convertRatios(boundingBox: boundingBoxes[1], type: .width), widthOfObjectWithIDFunction.value(parameter: 1 as AnyObject, landscapeMode: false), accuracy: Double.epsilon) + XCTAssertEqual(convertRatios(boundingBox: boundingBoxes[1], type: .height), heightOfObjectWithIDFunction.value(parameter: 1 as AnyObject, landscapeMode: false), accuracy: Double.epsilon) XCTAssertEqual(type(of: idOfDetectedObjectFunction).defaultValue, idOfDetectedObjectFunction.value(parameter: 3 as AnyObject), accuracy: Double.epsilon) XCTAssertEqual(type(of: objectWithIDVisibleFunction).defaultValue, objectWithIDVisibleFunction.value(parameter: 2 as AnyObject), accuracy: Double.epsilon) XCTAssertEqual(type(of: labelOfObjectWithIDFunction).defaultValue, labelOfObjectWithIDFunction.value(parameter: 2 as AnyObject)) - XCTAssertEqual(type(of: xOfObjectWithIDFunction).defaultValue, xOfObjectWithIDFunction.value(parameter: 2 as AnyObject), accuracy: Double.epsilon) - XCTAssertEqual(type(of: yOfObjectWithIDFunction).defaultValue, yOfObjectWithIDFunction.value(parameter: 2 as AnyObject), accuracy: Double.epsilon) - XCTAssertEqual(type(of: widthOfObjectWithIDFunction).defaultValue, widthOfObjectWithIDFunction.value(parameter: 2 as AnyObject), accuracy: Double.epsilon) - XCTAssertEqual(type(of: heightOfObjectWithIDFunction).defaultValue, heightOfObjectWithIDFunction.value(parameter: 2 as AnyObject), accuracy: Double.epsilon) + XCTAssertEqual(type(of: xOfObjectWithIDFunction).defaultValue, xOfObjectWithIDFunction.value(parameter: 2 as AnyObject, landscapeMode: false), accuracy: Double.epsilon) + XCTAssertEqual(type(of: yOfObjectWithIDFunction).defaultValue, yOfObjectWithIDFunction.value(parameter: 2 as AnyObject, landscapeMode: false), accuracy: Double.epsilon) + XCTAssertEqual(type(of: widthOfObjectWithIDFunction).defaultValue, widthOfObjectWithIDFunction.value(parameter: 2 as AnyObject, landscapeMode: false), accuracy: Double.epsilon) + XCTAssertEqual(type(of: heightOfObjectWithIDFunction).defaultValue, heightOfObjectWithIDFunction.value(parameter: 2 as AnyObject, landscapeMode: false), accuracy: Double.epsilon) } func testParameter() { diff --git a/src/CattyTests/PlayerEngine/Functions/TextRecognition/TextBlockPositionFunctionTest.swift b/src/CattyTests/PlayerEngine/Functions/TextRecognition/TextBlockPositionFunctionTest.swift index 1f26a2f0de..538c397241 100644 --- a/src/CattyTests/PlayerEngine/Functions/TextRecognition/TextBlockPositionFunctionTest.swift +++ b/src/CattyTests/PlayerEngine/Functions/TextRecognition/TextBlockPositionFunctionTest.swift @@ -56,19 +56,19 @@ class TextBlockPositionFunctionTest: XCTestCase { func testDefaultValue() { visualDetectionManagerMock.setTextBlockPositionRecognized(at: CGPoint(x: 0.3, y: 0.45), withSizeRatio: 0.5) - XCTAssertEqual(type(of: textBlockXFunction).defaultValue, textBlockXFunction.value(parameter: "invalidParameter" as AnyObject), accuracy: Double.epsilon) - XCTAssertEqual(type(of: textBlockXFunction).defaultValue, textBlockXFunction.value(parameter: nil), accuracy: Double.epsilon) + XCTAssertEqual(type(of: textBlockXFunction).defaultValue, textBlockXFunction.value(parameter: "invalidParameter" as AnyObject, landscapeMode: false), accuracy: Double.epsilon) + XCTAssertEqual(type(of: textBlockXFunction).defaultValue, textBlockXFunction.value(parameter: nil, landscapeMode: false), accuracy: Double.epsilon) let textBlockXFunction = TextBlockXFunction(stageSize: stageSize, visualDetectionManagerGetter: { nil }) - XCTAssertEqual(type(of: textBlockXFunction).defaultValue, textBlockXFunction.value(parameter: 1 as AnyObject), accuracy: Double.epsilon) + XCTAssertEqual(type(of: textBlockXFunction).defaultValue, textBlockXFunction.value(parameter: 1 as AnyObject, landscapeMode: false), accuracy: Double.epsilon) - XCTAssertEqual(type(of: textBlockYFunction).defaultValue, textBlockXFunction.value(parameter: "invalidParameter" as AnyObject), accuracy: Double.epsilon) - XCTAssertEqual(type(of: textBlockYFunction).defaultValue, textBlockXFunction.value(parameter: nil), accuracy: Double.epsilon) + XCTAssertEqual(type(of: textBlockYFunction).defaultValue, textBlockXFunction.value(parameter: "invalidParameter" as AnyObject, landscapeMode: false), accuracy: Double.epsilon) + XCTAssertEqual(type(of: textBlockYFunction).defaultValue, textBlockXFunction.value(parameter: nil, landscapeMode: false), accuracy: Double.epsilon) let textBlockYFunction = TextBlockYFunction(stageSize: stageSize, visualDetectionManagerGetter: { nil }) - XCTAssertEqual(type(of: textBlockYFunction).defaultValue, textBlockYFunction.value(parameter: 1 as AnyObject), accuracy: Double.epsilon) + XCTAssertEqual(type(of: textBlockYFunction).defaultValue, textBlockYFunction.value(parameter: 1 as AnyObject, landscapeMode: false), accuracy: Double.epsilon) XCTAssertEqual(type(of: textBlockSizeFunction).defaultValue, textBlockSizeFunction.value(parameter: "invalidParameter" as AnyObject), accuracy: Double.epsilon) XCTAssertEqual(type(of: textBlockSizeFunction).defaultValue, textBlockSizeFunction.value(parameter: nil), accuracy: Double.epsilon) - let textBlockSizeFunction = TextBlockYFunction(stageSize: stageSize, visualDetectionManagerGetter: { nil }) + let textBlockSizeFunction = TextBlockSizeFunction(stageSize: stageSize, visualDetectionManagerGetter: { nil }) XCTAssertEqual(type(of: textBlockSizeFunction).defaultValue, textBlockSizeFunction.value(parameter: 1 as AnyObject), accuracy: Double.epsilon) } @@ -80,20 +80,20 @@ class TextBlockPositionFunctionTest: XCTestCase { visualDetectionManagerMock.setTextBlockPositionRecognized(at: point, withSizeRatio: sizeRatios[index]) } - XCTAssertEqual(type(of: textBlockXFunction).defaultValue, textBlockXFunction.value(parameter: 0 as AnyObject), accuracy: Double.epsilon) - XCTAssertEqual(type(of: textBlockYFunction).defaultValue, textBlockYFunction.value(parameter: 0 as AnyObject), accuracy: Double.epsilon) + XCTAssertEqual(type(of: textBlockXFunction).defaultValue, textBlockXFunction.value(parameter: 0 as AnyObject, landscapeMode: false), accuracy: Double.epsilon) + XCTAssertEqual(type(of: textBlockYFunction).defaultValue, textBlockYFunction.value(parameter: 0 as AnyObject, landscapeMode: false), accuracy: Double.epsilon) XCTAssertEqual(type(of: textBlockSizeFunction).defaultValue, textBlockSizeFunction.value(parameter: 0 as AnyObject), accuracy: Double.epsilon) - XCTAssertEqual(convertRatios(ratioValue: points[0].x, type: .x), textBlockXFunction.value(parameter: 1 as AnyObject), accuracy: Double.epsilon) - XCTAssertEqual(convertRatios(ratioValue: points[0].y, type: .y), textBlockYFunction.value(parameter: 1 as AnyObject), accuracy: Double.epsilon) + XCTAssertEqual(convertRatios(ratioValue: points[0].x, type: .x), textBlockXFunction.value(parameter: 1 as AnyObject, landscapeMode: false), accuracy: Double.epsilon) + XCTAssertEqual(convertRatios(ratioValue: points[0].y, type: .y), textBlockYFunction.value(parameter: 1 as AnyObject, landscapeMode: false), accuracy: Double.epsilon) XCTAssertEqual(convertRatios(ratioValue: sizeRatios[0], type: .size), textBlockSizeFunction.value(parameter: 1 as AnyObject), accuracy: Double.epsilon) - XCTAssertEqual(convertRatios(ratioValue: points[2].x, type: .x), textBlockXFunction.value(parameter: 3.4 as AnyObject), accuracy: Double.epsilon) - XCTAssertEqual(convertRatios(ratioValue: points[2].y, type: .y), textBlockYFunction.value(parameter: 3.4 as AnyObject), accuracy: Double.epsilon) + XCTAssertEqual(convertRatios(ratioValue: points[2].x, type: .x), textBlockXFunction.value(parameter: 3.4 as AnyObject, landscapeMode: false), accuracy: Double.epsilon) + XCTAssertEqual(convertRatios(ratioValue: points[2].y, type: .y), textBlockYFunction.value(parameter: 3.4 as AnyObject, landscapeMode: false), accuracy: Double.epsilon) XCTAssertEqual(convertRatios(ratioValue: sizeRatios[2], type: .size), textBlockSizeFunction.value(parameter: 3.4 as AnyObject), accuracy: Double.epsilon) - XCTAssertEqual(type(of: textBlockXFunction).defaultValue, textBlockXFunction.value(parameter: 4 as AnyObject), accuracy: Double.epsilon) - XCTAssertEqual(type(of: textBlockYFunction).defaultValue, textBlockYFunction.value(parameter: 4 as AnyObject), accuracy: Double.epsilon) + XCTAssertEqual(type(of: textBlockXFunction).defaultValue, textBlockXFunction.value(parameter: 4 as AnyObject, landscapeMode: false), accuracy: Double.epsilon) + XCTAssertEqual(type(of: textBlockYFunction).defaultValue, textBlockYFunction.value(parameter: 4 as AnyObject, landscapeMode: false), accuracy: Double.epsilon) XCTAssertEqual(type(of: textBlockSizeFunction).defaultValue, textBlockSizeFunction.value(parameter: 4 as AnyObject), accuracy: Double.epsilon) } diff --git a/src/CattyTests/PlayerEngine/Sensors/BodyPose/AnkleSensorTest.swift b/src/CattyTests/PlayerEngine/Sensors/BodyPose/AnkleSensorTest.swift index b0185d8631..bfe5a5fe19 100644 --- a/src/CattyTests/PlayerEngine/Sensors/BodyPose/AnkleSensorTest.swift +++ b/src/CattyTests/PlayerEngine/Sensors/BodyPose/AnkleSensorTest.swift @@ -77,8 +77,6 @@ class AnkleSensorTest: XCTestCase { func testConvertToStandardized() { for ankleSensor in ankleXSensors { - XCTAssertEqual(type(of: ankleSensor).defaultRawValue, ankleSensor.convertToStandardized(rawValue: 0)) - XCTAssertEqual(Double(stageSize.width * 0.02) - Double(stageSize.width / 2), ankleSensor.convertToStandardized(rawValue: 0.02)) XCTAssertEqual(Double(stageSize.width * 0.45) - Double(stageSize.width / 2), ankleSensor.convertToStandardized(rawValue: 0.45)) XCTAssertEqual(Double(stageSize.width * 0.93) - Double(stageSize.width / 2), ankleSensor.convertToStandardized(rawValue: 0.93)) @@ -86,8 +84,6 @@ class AnkleSensorTest: XCTestCase { } for ankleSensor in ankleYSensors { - XCTAssertEqual(type(of: ankleSensor).defaultRawValue, ankleSensor.convertToStandardized(rawValue: 0)) - XCTAssertEqual(Double(stageSize.height * 0.01) - Double(stageSize.height / 2), ankleSensor.convertToStandardized(rawValue: 0.01)) XCTAssertEqual(Double(stageSize.height * 0.4) - Double(stageSize.height / 2), ankleSensor.convertToStandardized(rawValue: 0.4)) XCTAssertEqual(Double(stageSize.height * 0.95) - Double(stageSize.height / 2), ankleSensor.convertToStandardized(rawValue: 0.95)) @@ -99,9 +95,10 @@ class AnkleSensorTest: XCTestCase { for ankleSensor in ankleXSensors + ankleYSensors { let convertToStandardizedValue = ankleSensor.convertToStandardized(rawValue: ankleSensor.rawValue(landscapeMode: false)) let standardizedValue = ankleSensor.standardizedValue(landscapeMode: false) + let convertToStandardizedValueLandscape = ankleSensor.convertToStandardized(rawValue: ankleSensor.rawValue(landscapeMode: true)) let standardizedValueLandscape = ankleSensor.standardizedValue(landscapeMode: true) XCTAssertEqual(convertToStandardizedValue, standardizedValue) - XCTAssertEqual(standardizedValue, standardizedValueLandscape) + XCTAssertEqual(convertToStandardizedValueLandscape, standardizedValueLandscape) } } diff --git a/src/CattyTests/PlayerEngine/Sensors/BodyPose/ElbowSensorTest.swift b/src/CattyTests/PlayerEngine/Sensors/BodyPose/ElbowSensorTest.swift index 5d44a20e4f..2714443008 100644 --- a/src/CattyTests/PlayerEngine/Sensors/BodyPose/ElbowSensorTest.swift +++ b/src/CattyTests/PlayerEngine/Sensors/BodyPose/ElbowSensorTest.swift @@ -77,8 +77,6 @@ final class ElbowSensorTest: XCTestCase { func testConvertToStandardized() { for elbowSensor in elbowXSensors { - XCTAssertEqual(type(of: elbowSensor).defaultRawValue, elbowSensor.convertToStandardized(rawValue: 0)) - XCTAssertEqual(Double(stageSize.width * 0.02) - Double(stageSize.width / 2), elbowSensor.convertToStandardized(rawValue: 0.02)) XCTAssertEqual(Double(stageSize.width * 0.45) - Double(stageSize.width / 2), elbowSensor.convertToStandardized(rawValue: 0.45)) XCTAssertEqual(Double(stageSize.width * 0.93) - Double(stageSize.width / 2), elbowSensor.convertToStandardized(rawValue: 0.93)) @@ -86,8 +84,6 @@ final class ElbowSensorTest: XCTestCase { } for elbowSensor in elbowYSensors { - XCTAssertEqual(type(of: elbowSensor).defaultRawValue, elbowSensor.convertToStandardized(rawValue: 0)) - XCTAssertEqual(Double(stageSize.height * 0.01) - Double(stageSize.height / 2), elbowSensor.convertToStandardized(rawValue: 0.01)) XCTAssertEqual(Double(stageSize.height * 0.4) - Double(stageSize.height / 2), elbowSensor.convertToStandardized(rawValue: 0.4)) XCTAssertEqual(Double(stageSize.height * 0.95) - Double(stageSize.height / 2), elbowSensor.convertToStandardized(rawValue: 0.95)) @@ -99,9 +95,10 @@ final class ElbowSensorTest: XCTestCase { for elbowSensor in elbowXSensors + elbowYSensors { let convertToStandardizedValue = elbowSensor.convertToStandardized(rawValue: elbowSensor.rawValue(landscapeMode: false)) let standardizedValue = elbowSensor.standardizedValue(landscapeMode: false) + let convertToStandardizedValueLandscape = elbowSensor.convertToStandardized(rawValue: elbowSensor.rawValue(landscapeMode: true)) let standardizedValueLandscape = elbowSensor.standardizedValue(landscapeMode: true) XCTAssertEqual(convertToStandardizedValue, standardizedValue) - XCTAssertEqual(standardizedValue, standardizedValueLandscape) + XCTAssertEqual(convertToStandardizedValueLandscape, standardizedValueLandscape) } } diff --git a/src/CattyTests/PlayerEngine/Sensors/BodyPose/HipSensorTest.swift b/src/CattyTests/PlayerEngine/Sensors/BodyPose/HipSensorTest.swift index c0dc508f39..7524954e9e 100644 --- a/src/CattyTests/PlayerEngine/Sensors/BodyPose/HipSensorTest.swift +++ b/src/CattyTests/PlayerEngine/Sensors/BodyPose/HipSensorTest.swift @@ -77,8 +77,6 @@ class HipSensorTest: XCTestCase { func testConvertToStandardized() { for hipSensor in hipXSensors { - XCTAssertEqual(type(of: hipSensor).defaultRawValue, hipSensor.convertToStandardized(rawValue: 0)) - XCTAssertEqual(Double(stageSize.width * 0.02) - Double(stageSize.width / 2), hipSensor.convertToStandardized(rawValue: 0.02)) XCTAssertEqual(Double(stageSize.width * 0.45) - Double(stageSize.width / 2), hipSensor.convertToStandardized(rawValue: 0.45)) XCTAssertEqual(Double(stageSize.width * 0.93) - Double(stageSize.width / 2), hipSensor.convertToStandardized(rawValue: 0.93)) @@ -86,8 +84,6 @@ class HipSensorTest: XCTestCase { } for hipSensor in hipYSensors { - XCTAssertEqual(type(of: hipSensor).defaultRawValue, hipSensor.convertToStandardized(rawValue: 0)) - XCTAssertEqual(Double(stageSize.height * 0.01) - Double(stageSize.height / 2), hipSensor.convertToStandardized(rawValue: 0.01)) XCTAssertEqual(Double(stageSize.height * 0.4) - Double(stageSize.height / 2), hipSensor.convertToStandardized(rawValue: 0.4)) XCTAssertEqual(Double(stageSize.height * 0.95) - Double(stageSize.height / 2), hipSensor.convertToStandardized(rawValue: 0.95)) @@ -99,9 +95,10 @@ class HipSensorTest: XCTestCase { for hipSensor in hipXSensors + hipYSensors { let convertToStandardizedValue = hipSensor.convertToStandardized(rawValue: hipSensor.rawValue(landscapeMode: false)) let standardizedValue = hipSensor.standardizedValue(landscapeMode: false) + let convertToStandardizedValueLandscape = hipSensor.convertToStandardized(rawValue: hipSensor.rawValue(landscapeMode: true)) let standardizedValueLandscape = hipSensor.standardizedValue(landscapeMode: true) XCTAssertEqual(convertToStandardizedValue, standardizedValue) - XCTAssertEqual(standardizedValue, standardizedValueLandscape) + XCTAssertEqual(convertToStandardizedValueLandscape, standardizedValueLandscape) } } diff --git a/src/CattyTests/PlayerEngine/Sensors/BodyPose/KneeSensorTest.swift b/src/CattyTests/PlayerEngine/Sensors/BodyPose/KneeSensorTest.swift index a50eb7f7e2..af84df0688 100644 --- a/src/CattyTests/PlayerEngine/Sensors/BodyPose/KneeSensorTest.swift +++ b/src/CattyTests/PlayerEngine/Sensors/BodyPose/KneeSensorTest.swift @@ -77,8 +77,6 @@ class KneeSensorTest: XCTestCase { func testConvertToStandardized() { for kneeSensor in kneeXSensors { - XCTAssertEqual(type(of: kneeSensor).defaultRawValue, kneeSensor.convertToStandardized(rawValue: 0)) - XCTAssertEqual(Double(stageSize.width * 0.02) - Double(stageSize.width / 2), kneeSensor.convertToStandardized(rawValue: 0.02)) XCTAssertEqual(Double(stageSize.width * 0.45) - Double(stageSize.width / 2), kneeSensor.convertToStandardized(rawValue: 0.45)) XCTAssertEqual(Double(stageSize.width * 0.93) - Double(stageSize.width / 2), kneeSensor.convertToStandardized(rawValue: 0.93)) @@ -86,8 +84,6 @@ class KneeSensorTest: XCTestCase { } for kneeSensor in kneeYSensors { - XCTAssertEqual(type(of: kneeSensor).defaultRawValue, kneeSensor.convertToStandardized(rawValue: 0)) - XCTAssertEqual(Double(stageSize.height * 0.01) - Double(stageSize.height / 2), kneeSensor.convertToStandardized(rawValue: 0.01)) XCTAssertEqual(Double(stageSize.height * 0.4) - Double(stageSize.height / 2), kneeSensor.convertToStandardized(rawValue: 0.4)) XCTAssertEqual(Double(stageSize.height * 0.95) - Double(stageSize.height / 2), kneeSensor.convertToStandardized(rawValue: 0.95)) @@ -99,9 +95,10 @@ class KneeSensorTest: XCTestCase { for kneeSensor in kneeXSensors + kneeYSensors { let convertToStandardizedValue = kneeSensor.convertToStandardized(rawValue: kneeSensor.rawValue(landscapeMode: false)) let standardizedValue = kneeSensor.standardizedValue(landscapeMode: false) + let convertToStandardizedValueLandscape = kneeSensor.convertToStandardized(rawValue: kneeSensor.rawValue(landscapeMode: true)) let standardizedValueLandscape = kneeSensor.standardizedValue(landscapeMode: true) XCTAssertEqual(convertToStandardizedValue, standardizedValue) - XCTAssertEqual(standardizedValue, standardizedValueLandscape) + XCTAssertEqual(convertToStandardizedValueLandscape, standardizedValueLandscape) } } diff --git a/src/CattyTests/PlayerEngine/Sensors/BodyPose/NeckSensorTest.swift b/src/CattyTests/PlayerEngine/Sensors/BodyPose/NeckSensorTest.swift index 1089c7f7e5..ac8f176362 100644 --- a/src/CattyTests/PlayerEngine/Sensors/BodyPose/NeckSensorTest.swift +++ b/src/CattyTests/PlayerEngine/Sensors/BodyPose/NeckSensorTest.swift @@ -67,15 +67,11 @@ final class NeckSensorTest: XCTestCase { } func testConvertToStandardized() { - XCTAssertEqual(type(of: neckXSensor).defaultRawValue, neckXSensor.convertToStandardized(rawValue: 0)) - XCTAssertEqual(Double(stageSize.width * 0.02) - Double(stageSize.width / 2), neckXSensor.convertToStandardized(rawValue: 0.02)) XCTAssertEqual(Double(stageSize.width * 0.45) - Double(stageSize.width / 2), neckXSensor.convertToStandardized(rawValue: 0.45)) XCTAssertEqual(Double(stageSize.width * 0.93) - Double(stageSize.width / 2), neckXSensor.convertToStandardized(rawValue: 0.93)) XCTAssertEqual(Double(stageSize.width / 2), neckXSensor.convertToStandardized(rawValue: 1.0)) - XCTAssertEqual(type(of: neckYSensor).defaultRawValue, neckYSensor.convertToStandardized(rawValue: 0)) - XCTAssertEqual(Double(stageSize.height * 0.01) - Double(stageSize.height / 2), neckYSensor.convertToStandardized(rawValue: 0.01)) XCTAssertEqual(Double(stageSize.height * 0.4) - Double(stageSize.height / 2), neckYSensor.convertToStandardized(rawValue: 0.4)) XCTAssertEqual(Double(stageSize.height * 0.95) - Double(stageSize.height / 2), neckYSensor.convertToStandardized(rawValue: 0.95)) @@ -85,15 +81,17 @@ final class NeckSensorTest: XCTestCase { func testStandardizedValue() { var convertToStandardizedValue = neckXSensor.convertToStandardized(rawValue: neckXSensor.rawValue(landscapeMode: false)) var standardizedValue = neckXSensor.standardizedValue(landscapeMode: false) + var convertToStandardizedValueLandscape = neckXSensor.convertToStandardized(rawValue: neckXSensor.rawValue(landscapeMode: true)) var standardizedValueLandscape = neckXSensor.standardizedValue(landscapeMode: true) XCTAssertEqual(convertToStandardizedValue, standardizedValue) - XCTAssertEqual(standardizedValue, standardizedValueLandscape) + XCTAssertEqual(convertToStandardizedValueLandscape, standardizedValueLandscape) convertToStandardizedValue = neckYSensor.convertToStandardized(rawValue: neckYSensor.rawValue(landscapeMode: false)) standardizedValue = neckYSensor.standardizedValue(landscapeMode: false) + convertToStandardizedValueLandscape = neckYSensor.convertToStandardized(rawValue: neckYSensor.rawValue(landscapeMode: true)) standardizedValueLandscape = neckYSensor.standardizedValue(landscapeMode: true) XCTAssertEqual(convertToStandardizedValue, standardizedValue) - XCTAssertEqual(standardizedValue, standardizedValueLandscape) + XCTAssertEqual(convertToStandardizedValueLandscape, standardizedValueLandscape) } func testTag() { diff --git a/src/CattyTests/PlayerEngine/Sensors/BodyPose/ShoulderSensorTest.swift b/src/CattyTests/PlayerEngine/Sensors/BodyPose/ShoulderSensorTest.swift index b1f66a347a..d2ce211ea9 100644 --- a/src/CattyTests/PlayerEngine/Sensors/BodyPose/ShoulderSensorTest.swift +++ b/src/CattyTests/PlayerEngine/Sensors/BodyPose/ShoulderSensorTest.swift @@ -77,8 +77,6 @@ final class ShoulderSensorTest: XCTestCase { func testConvertToStandardized() { for shoulderSensor in shoulderXSensors { - XCTAssertEqual(type(of: shoulderSensor).defaultRawValue, shoulderSensor.convertToStandardized(rawValue: 0)) - XCTAssertEqual(Double(stageSize.width * 0.02) - Double(stageSize.width / 2), shoulderSensor.convertToStandardized(rawValue: 0.02)) XCTAssertEqual(Double(stageSize.width * 0.45) - Double(stageSize.width / 2), shoulderSensor.convertToStandardized(rawValue: 0.45)) XCTAssertEqual(Double(stageSize.width * 0.93) - Double(stageSize.width / 2), shoulderSensor.convertToStandardized(rawValue: 0.93)) @@ -86,8 +84,6 @@ final class ShoulderSensorTest: XCTestCase { } for shoulderSensor in shoulderYSensors { - XCTAssertEqual(type(of: shoulderSensor).defaultRawValue, shoulderSensor.convertToStandardized(rawValue: 0)) - XCTAssertEqual(Double(stageSize.height * 0.01) - Double(stageSize.height / 2), shoulderSensor.convertToStandardized(rawValue: 0.01)) XCTAssertEqual(Double(stageSize.height * 0.4) - Double(stageSize.height / 2), shoulderSensor.convertToStandardized(rawValue: 0.4)) XCTAssertEqual(Double(stageSize.height * 0.95) - Double(stageSize.height / 2), shoulderSensor.convertToStandardized(rawValue: 0.95)) @@ -99,9 +95,10 @@ final class ShoulderSensorTest: XCTestCase { for shoulderSensor in shoulderXSensors + shoulderYSensors { let convertToStandardizedValue = shoulderSensor.convertToStandardized(rawValue: shoulderSensor.rawValue(landscapeMode: false)) let standardizedValue = shoulderSensor.standardizedValue(landscapeMode: false) + let convertToStandardizedValueLandscape = shoulderSensor.convertToStandardized(rawValue: shoulderSensor.rawValue(landscapeMode: true)) let standardizedValueLandscape = shoulderSensor.standardizedValue(landscapeMode: true) XCTAssertEqual(convertToStandardizedValue, standardizedValue) - XCTAssertEqual(standardizedValue, standardizedValueLandscape) + XCTAssertEqual(convertToStandardizedValueLandscape, standardizedValueLandscape) } } diff --git a/src/CattyTests/PlayerEngine/Sensors/BodyPose/WristSensorTest.swift b/src/CattyTests/PlayerEngine/Sensors/BodyPose/WristSensorTest.swift index 8aabbc76a4..8a0ca79d04 100644 --- a/src/CattyTests/PlayerEngine/Sensors/BodyPose/WristSensorTest.swift +++ b/src/CattyTests/PlayerEngine/Sensors/BodyPose/WristSensorTest.swift @@ -77,8 +77,6 @@ final class WristSensorTest: XCTestCase { func testConvertToStandardized() { for wristSensor in wristXSensors { - XCTAssertEqual(type(of: wristSensor).defaultRawValue, wristSensor.convertToStandardized(rawValue: 0)) - XCTAssertEqual(Double(stageSize.width * 0.02) - Double(stageSize.width / 2), wristSensor.convertToStandardized(rawValue: 0.02)) XCTAssertEqual(Double(stageSize.width * 0.45) - Double(stageSize.width / 2), wristSensor.convertToStandardized(rawValue: 0.45)) XCTAssertEqual(Double(stageSize.width * 0.93) - Double(stageSize.width / 2), wristSensor.convertToStandardized(rawValue: 0.93)) @@ -86,8 +84,6 @@ final class WristSensorTest: XCTestCase { } for wristSensor in wristYSensors { - XCTAssertEqual(type(of: wristSensor).defaultRawValue, wristSensor.convertToStandardized(rawValue: 0)) - XCTAssertEqual(Double(stageSize.height * 0.01) - Double(stageSize.height / 2), wristSensor.convertToStandardized(rawValue: 0.01)) XCTAssertEqual(Double(stageSize.height * 0.4) - Double(stageSize.height / 2), wristSensor.convertToStandardized(rawValue: 0.4)) XCTAssertEqual(Double(stageSize.height * 0.95) - Double(stageSize.height / 2), wristSensor.convertToStandardized(rawValue: 0.95)) @@ -99,9 +95,10 @@ final class WristSensorTest: XCTestCase { for wristSensor in wristXSensors + wristYSensors { let convertToStandardizedValue = wristSensor.convertToStandardized(rawValue: wristSensor.rawValue(landscapeMode: false)) let standardizedValue = wristSensor.standardizedValue(landscapeMode: false) + let convertToStandardizedValueLandscape = wristSensor.convertToStandardized(rawValue: wristSensor.rawValue(landscapeMode: true)) let standardizedValueLandscape = wristSensor.standardizedValue(landscapeMode: true) XCTAssertEqual(convertToStandardizedValue, standardizedValue) - XCTAssertEqual(standardizedValue, standardizedValueLandscape) + XCTAssertEqual(convertToStandardizedValueLandscape, standardizedValueLandscape) } } diff --git a/src/CattyTests/PlayerEngine/Sensors/Camera/VisualDetectionManagerTest.swift b/src/CattyTests/PlayerEngine/Sensors/DetectionManager/VisualDetectionManagerTest.swift similarity index 100% rename from src/CattyTests/PlayerEngine/Sensors/Camera/VisualDetectionManagerTest.swift rename to src/CattyTests/PlayerEngine/Sensors/DetectionManager/VisualDetectionManagerTest.swift diff --git a/src/CattyTests/PlayerEngine/Sensors/Camera/FaceDetectionSensorTest.swift b/src/CattyTests/PlayerEngine/Sensors/Face/FaceDetectionSensorTest.swift similarity index 100% rename from src/CattyTests/PlayerEngine/Sensors/Camera/FaceDetectionSensorTest.swift rename to src/CattyTests/PlayerEngine/Sensors/Face/FaceDetectionSensorTest.swift diff --git a/src/CattyTests/PlayerEngine/Sensors/Camera/FacePositionSensorTest.swift b/src/CattyTests/PlayerEngine/Sensors/Face/FacePositionSensorTest.swift similarity index 93% rename from src/CattyTests/PlayerEngine/Sensors/Camera/FacePositionSensorTest.swift rename to src/CattyTests/PlayerEngine/Sensors/Face/FacePositionSensorTest.swift index 32d9757e80..ceb7447d48 100644 --- a/src/CattyTests/PlayerEngine/Sensors/Camera/FacePositionSensorTest.swift +++ b/src/CattyTests/PlayerEngine/Sensors/Face/FacePositionSensorTest.swift @@ -75,15 +75,12 @@ final class FacePositionSensorTest: XCTestCase { func testConvertToStandardized() { for faceIndex in 0..