I have the following table structure for my table called storage_faceencoding.
id: UUID
feature_1: Float
feature_2: Float
feature_3: Float
...
feature_128: Float
I want to query against those 128 feature columns and return the id along with the distance value.
I'm querying against those 128 feature columns like so:
SELECT * from storage_faceencoding ORDER BY sqrt(power(feature_1 - -0.054835572838783264, 2) + power(feature_2 - 0.034169211983680725, 2) + power(feature_3 - 0.0789899230003357, 2) + power(feature_4 - -0.12306179106235504, 2) + power(feature_5 - -0.14243610203266144, 2) + power(feature_6 - 0.0015480183064937592, 2) + power(feature_7 - -0.03730906546115875, 2) + power(feature_8 - -0.04611199349164963, 2) + power(feature_9 - 0.17417974770069122, 2) + power(feature_10 - -0.07324142754077911, 2) + power(feature_11 - 0.2784380316734314, 2) + power(feature_12 - -0.05557965114712715, 2) + power(feature_13 - -0.28433677554130554, 2) + power(feature_14 - 0.003816460259258747, 2) + power(feature_15 - -0.004081043414771557, 2) + power(feature_16 - 0.14893895387649536, 2) + power(feature_17 - -0.12637391686439514, 2) + power(feature_18 - -0.0776168555021286, 2) + power(feature_19 - -0.07115891575813293, 2) + power(feature_20 - 0.013110934756696224, 2) + power(feature_21 - -0.03728703036904335, 2) + power(feature_22 - 0.0312555767595768, 2) + power(feature_23 - -0.013231765478849411, 2) + power(feature_24 - 0.08345625549554825, 2) + power(feature_25 - -0.14501842856407166, 2) + power(feature_26 - -0.3354545533657074, 2) + power(feature_27 - -0.06517831236124039, 2) + power(feature_28 - -0.16320215165615082, 2) + power(feature_29 - -0.029647808521986008, 2) + power(feature_30 - -0.026274608448147774, 2) + power(feature_31 - 0.008217697963118553, 2) + power(feature_32 - 0.09989964962005615, 2) + power(feature_33 - -0.10960874706506729, 2) + power(feature_34 - -0.04241098091006279, 2) + power(feature_35 - 0.03659277781844139, 2) + power(feature_36 - 0.05843937397003174, 2) + power(feature_37 - -0.1882062405347824, 2) + power(feature_38 - -0.1472000777721405, 2) + power(feature_39 - 0.1806768774986267, 2) + power(feature_40 - -0.047331131994724274, 2) + power(feature_41 - -0.1587458848953247, 2) + power(feature_42 - -0.03949886932969093, 2) + power(feature_43 - 0.025885790586471558, 2) + power(feature_44 - 0.23678790032863617, 2) + power(feature_45 - 0.10318232327699661, 2) + power(feature_46 - -0.02302492968738079, 2) + power(feature_47 - 0.1084280014038086, 2) + power(feature_48 - -0.047027621418237686, 2) + power(feature_49 - 0.07425221800804138, 2) + power(feature_50 - -0.2947121560573578, 2) + power(feature_51 - 0.0031417328864336014, 2) + power(feature_52 - 0.121400848031044, 2) + power(feature_53 - 0.07688573747873306, 2) + power(feature_54 - 0.09685630351305008, 2) + power(feature_55 - 0.10917495936155319, 2) + power(feature_56 - -0.1276204138994217, 2) + power(feature_57 - 0.08362210541963577, 2) + power(feature_58 - 0.16328635811805725, 2) + power(feature_59 - -0.25213390588760376, 2) + power(feature_60 - 0.05785408616065979, 2) + power(feature_61 - 0.018559012562036514, 2) + power(feature_62 - -0.01683107763528824, 2) + power(feature_63 - -0.01742824725806713, 2) + power(feature_64 - -0.1193951666355133, 2) + power(feature_65 - 0.2622459828853607, 2) + power(feature_66 - 0.12121666967868805, 2) + power(feature_67 - -0.1520567685365677, 2) + power(feature_68 - -0.1122896820306778, 2) + power(feature_69 - 0.14081937074661255, 2) + power(feature_70 - -0.14206485450267792, 2) + power(feature_71 - -0.10112465173006058, 2) + power(feature_72 - 0.07290071249008179, 2) + power(feature_73 - -0.16641031205654144, 2) + power(feature_74 - -0.21917763352394104, 2) + power(feature_75 - -0.25251486897468567, 2) + power(feature_76 - -0.0048762112855911255, 2) + power(feature_77 - 0.37720248103141785, 2) + power(feature_78 - 0.1548663228750229, 2) + power(feature_79 - -0.12398210912942886, 2) + power(feature_80 - 0.041234225034713745, 2) + power(feature_81 - -0.06544441729784012, 2) + power(feature_82 - -0.09197349101305008, 2) + power(feature_83 - -0.021058330312371254, 2) + power(feature_84 - 0.039639901369810104, 2) + power(feature_85 - -0.0023813657462596893, 2) + power(feature_86 - -0.07752023637294769, 2) + power(feature_87 - -0.03788585215806961, 2) + power(feature_88 - 0.01571604609489441, 2) + power(feature_89 - 0.22586794197559357, 2) + power(feature_90 - -0.08962416648864746, 2) + power(feature_91 - 0.027185270562767982, 2) + power(feature_92 - 0.21015749871730804, 2) + power(feature_93 - 0.014571629464626312, 2) + power(feature_94 - -0.03427625447511673, 2) + power(feature_95 - -0.031976763159036636, 2) + power(feature_96 - -0.02412014827132225, 2) + power(feature_97 - -0.0572514683008194, 2) + power(feature_98 - 0.025131937116384506, 2) + power(feature_99 - -0.055663101375103, 2) + power(feature_100 - 0.06940365582704544, 2) + power(feature_101 - -0.008616405539214611, 2) + power(feature_102 - -0.08647502958774567, 2) + power(feature_103 - -0.002743437420576811, 2) + power(feature_104 - 0.06195132061839104, 2) + power(feature_105 - -0.21810059249401093, 2) + power(feature_106 - 0.18355928361415863, 2) + power(feature_107 - 0.028437575325369835, 2) + power(feature_108 - -0.02596919797360897, 2) + power(feature_109 - 0.03891913592815399, 2) + power(feature_110 - 0.017703840509057045, 2) + power(feature_111 - -0.14867563545703888, 2) + power(feature_112 - -0.035795167088508606, 2) + power(feature_113 - 0.21177658438682556, 2) + power(feature_114 - -0.3009713888168335, 2) + power(feature_115 - 0.20549386739730835, 2) + power(feature_116 - 0.15210166573524475, 2) + power(feature_117 - 0.1311473250389099, 2) + power(feature_118 - 0.1054188460111618, 2) + power(feature_119 - 0.017464492470026016, 2) + power(feature_120 - -0.011423288844525814, 2) + power(feature_121 - -0.0072870198637247086, 2) + power(feature_122 - -0.021593499928712845, 2) + power(feature_123 - -0.21365071833133698, 2) + power(feature_124 - -0.09368597716093063, 2) + power(feature_125 - 0.06633836776018143, 2) + power(feature_126 - -0.05478530377149582, 2) + power(feature_127 - -0.009351606480777264, 2) + power(feature_128 - 0.04693271964788437, 2) ) LIMIT 5
This works and orders the results by the euclidean distance however I also want the distance value returned (i.e. SELECT it).
How would I go about getting that distance value?
Thanks in advance.
You can use an alias to show that distance on the result and then order by that distance:
SELECT *, (sqrt(power(feature_1 - -0.054835572838783264, 2) + power(feature_2 - 0.034169211983680725, 2) + power(feature_3 - 0.0789899230003357, 2) + power(feature_4 - -0.12306179106235504, 2) + power(feature_5 - -0.14243610203266144, 2) + power(feature_6 - 0.0015480183064937592, 2) + power(feature_7 - -0.03730906546115875, 2) + power(feature_8 - -0.04611199349164963, 2) + power(feature_9 - 0.17417974770069122, 2) + power(feature_10 - -0.07324142754077911, 2) + power(feature_11 - 0.2784380316734314, 2) + power(feature_12 - -0.05557965114712715, 2) + power(feature_13 - -0.28433677554130554, 2) + power(feature_14 - 0.003816460259258747, 2) + power(feature_15 - -0.004081043414771557, 2) + power(feature_16 - 0.14893895387649536, 2) + power(feature_17 - -0.12637391686439514, 2) + power(feature_18 - -0.0776168555021286, 2) + power(feature_19 - -0.07115891575813293, 2) + power(feature_20 - 0.013110934756696224, 2) + power(feature_21 - -0.03728703036904335, 2) + power(feature_22 - 0.0312555767595768, 2) + power(feature_23 - -0.013231765478849411, 2) + power(feature_24 - 0.08345625549554825, 2) + power(feature_25 - -0.14501842856407166, 2) + power(feature_26 - -0.3354545533657074, 2) + power(feature_27 - -0.06517831236124039, 2) + power(feature_28 - -0.16320215165615082, 2) + power(feature_29 - -0.029647808521986008, 2) + power(feature_30 - -0.026274608448147774, 2) + power(feature_31 - 0.008217697963118553, 2) + power(feature_32 - 0.09989964962005615, 2) + power(feature_33 - -0.10960874706506729, 2) + power(feature_34 - -0.04241098091006279, 2) + power(feature_35 - 0.03659277781844139, 2) + power(feature_36 - 0.05843937397003174, 2) + power(feature_37 - -0.1882062405347824, 2) + power(feature_38 - -0.1472000777721405, 2) + power(feature_39 - 0.1806768774986267, 2) + power(feature_40 - -0.047331131994724274, 2) + power(feature_41 - -0.1587458848953247, 2) + power(feature_42 - -0.03949886932969093, 2) + power(feature_43 - 0.025885790586471558, 2) + power(feature_44 - 0.23678790032863617, 2) + power(feature_45 - 0.10318232327699661, 2) + power(feature_46 - -0.02302492968738079, 2) + power(feature_47 - 0.1084280014038086, 2) + power(feature_48 - -0.047027621418237686, 2) + power(feature_49 - 0.07425221800804138, 2) + power(feature_50 - -0.2947121560573578, 2) + power(feature_51 - 0.0031417328864336014, 2) + power(feature_52 - 0.121400848031044, 2) + power(feature_53 - 0.07688573747873306, 2) + power(feature_54 - 0.09685630351305008, 2) + power(feature_55 - 0.10917495936155319, 2) + power(feature_56 - -0.1276204138994217, 2) + power(feature_57 - 0.08362210541963577, 2) + power(feature_58 - 0.16328635811805725, 2) + power(feature_59 - -0.25213390588760376, 2) + power(feature_60 - 0.05785408616065979, 2) + power(feature_61 - 0.018559012562036514, 2) + power(feature_62 - -0.01683107763528824, 2) + power(feature_63 - -0.01742824725806713, 2) + power(feature_64 - -0.1193951666355133, 2) + power(feature_65 - 0.2622459828853607, 2) + power(feature_66 - 0.12121666967868805, 2) + power(feature_67 - -0.1520567685365677, 2) + power(feature_68 - -0.1122896820306778, 2) + power(feature_69 - 0.14081937074661255, 2) + power(feature_70 - -0.14206485450267792, 2) + power(feature_71 - -0.10112465173006058, 2) + power(feature_72 - 0.07290071249008179, 2) + power(feature_73 - -0.16641031205654144, 2) + power(feature_74 - -0.21917763352394104, 2) + power(feature_75 - -0.25251486897468567, 2) + power(feature_76 - -0.0048762112855911255, 2) + power(feature_77 - 0.37720248103141785, 2) + power(feature_78 - 0.1548663228750229, 2) + power(feature_79 - -0.12398210912942886, 2) + power(feature_80 - 0.041234225034713745, 2) + power(feature_81 - -0.06544441729784012, 2) + power(feature_82 - -0.09197349101305008, 2) + power(feature_83 - -0.021058330312371254, 2) + power(feature_84 - 0.039639901369810104, 2) + power(feature_85 - -0.0023813657462596893, 2) + power(feature_86 - -0.07752023637294769, 2) + power(feature_87 - -0.03788585215806961, 2) + power(feature_88 - 0.01571604609489441, 2) + power(feature_89 - 0.22586794197559357, 2) + power(feature_90 - -0.08962416648864746, 2) + power(feature_91 - 0.027185270562767982, 2) + power(feature_92 - 0.21015749871730804, 2) + power(feature_93 - 0.014571629464626312, 2) + power(feature_94 - -0.03427625447511673, 2) + power(feature_95 - -0.031976763159036636, 2) + power(feature_96 - -0.02412014827132225, 2) + power(feature_97 - -0.0572514683008194, 2) + power(feature_98 - 0.025131937116384506, 2) + power(feature_99 - -0.055663101375103, 2) + power(feature_100 - 0.06940365582704544, 2) + power(feature_101 - -0.008616405539214611, 2) + power(feature_102 - -0.08647502958774567, 2) + power(feature_103 - -0.002743437420576811, 2) + power(feature_104 - 0.06195132061839104, 2) + power(feature_105 - -0.21810059249401093, 2) + power(feature_106 - 0.18355928361415863, 2) + power(feature_107 - 0.028437575325369835, 2) + power(feature_108 - -0.02596919797360897, 2) + power(feature_109 - 0.03891913592815399, 2) + power(feature_110 - 0.017703840509057045, 2) + power(feature_111 - -0.14867563545703888, 2) + power(feature_112 - -0.035795167088508606, 2) + power(feature_113 - 0.21177658438682556, 2) + power(feature_114 - -0.3009713888168335, 2) + power(feature_115 - 0.20549386739730835, 2) + power(feature_116 - 0.15210166573524475, 2) + power(feature_117 - 0.1311473250389099, 2) + power(feature_118 - 0.1054188460111618, 2) + power(feature_119 - 0.017464492470026016, 2) + power(feature_120 - -0.011423288844525814, 2) + power(feature_121 - -0.0072870198637247086, 2) + power(feature_122 - -0.021593499928712845, 2) + power(feature_123 - -0.21365071833133698, 2) + power(feature_124 - -0.09368597716093063, 2) + power(feature_125 - 0.06633836776018143, 2) + power(feature_126 - -0.05478530377149582, 2) + power(feature_127 - -0.009351606480777264, 2) + power(feature_128 - 0.04693271964788437, 2) )) as distance
from storage_faceencoding ORDER BY distance LIMIT 5
Ok here's the deal: I need to do a comprehensive check in a .csv file (comparing the one in my current sheet to an external one). I decided to divide the list into 10 equal sections (deciles). In each decile I choose a random value belonging to that section and use that row number to compare the two sets of data.
Where things fall apart is inside the FOR function. I am looking for a way to go through each decile (starting from rand0) and have VBA check whether the values of the .csv and the Data sheet in this workbook are equal. If they are not - a function (called get_param) is to be executed.
I dont quite understand how to have VBA go through the FOR function from Dec = 0 to 9 - so in essence from row number rand0 to row number rand9 and perform the inequality check (in the second IF function). The rand & Dec part does not work. I am looking for clues on how to fix this or on a new implementation to do the same thing.
A few more details:
n is the number of rows in the .csv file (equal to a couple of thousand).
np is the number of rows in this file (should be equal to n - if not, execute function). ParamLocation is designated automatically - it should be located in a specific location.
Sub check_changes_param()
Dim Dec As Integer
Call public_dims
Call deciles
Set ParamBook = Workbooks.Open(ParamLocation)
'==========CHECKS IF PARAMETERS.xlsm EXISTS IN THE CORRECT LOCATION==========
If ParamLocation = "" Then
MsgBox "The Parameters.xlsm file does not exist or is in the incorrect location. Please ensure it is located in " & ParamLocation
Else
For Dec = 0 To Dec = 9
If ThisWorkbook.Sheets("Data").Cells(rand & Dec, 11) <> ParamBook.Sheets("Data").Cells(rand & Dec, 11) Or n <> np Then
Call get_param
Exit For
End If
Next Dec
End If
End Sub
Public Sub deciles()
rand0 = Int((n / 10) * 1) * Rnd + 1
rand1 = Int((n / 10) * 2 - (n / 10) * 1 + 1) * Rnd + (n / 10) * 1
rand2 = Int((n / 10) * 3 - (n / 10) * 2 + 1) * Rnd + (n / 10) * 2
rand3 = Int((n / 10) * 4 - (n / 10) * 3 + 1) * Rnd + (n / 10) * 3
rand4 = Int((n / 10) * 5 - (n / 10) * 4 + 1) * Rnd + (n / 10) * 4
rand5 = Int((n / 10) * 6 - (n / 10) * 5 + 1) * Rnd + (n / 10) * 5
rand6 = Int((n / 10) * 7 - (n / 10) * 6 + 1) * Rnd + (n / 10) * 6
rand7 = Int((n / 10) * 8 - (n / 10) * 7 + 1) * Rnd + (n / 10) * 7
rand8 = Int((n / 10) * 9 - (n / 10) * 8 + 1) * Rnd + (n / 10) * 8
rand9 = Int(n - (n / 10) * 9 + 1) * Rnd + (n / 10) * 9
End Sub
Try this instead:
Sub check_changes_param()
Dim Dec As Integer
Call public_dims
Dim deciles As Variant
deciles = decilesArray()
Set ParamBook = Workbooks.Open(ParamLocation)
'==========CHECKS IF PARAMETERS.xlsm EXISTS IN THE CORRECT LOCATION==========
If ParamLocation = "" Then
MsgBox "The Parameters.xlsm file does not exist or is in the incorrect location. Please ensure it is located in " & ParamLocation
Else
For Dec = 0 To UBound(deciles)
If ThisWorkbook.Sheets("Data").Cells(deciles(Dec), 11) <> ParamBook.Sheets("Data").Cells(deciles(Dec), , 11) Or n <> np Then
Call get_param
Exit For
End If
Next Dec
End If
End Sub
Public Function decilesArray() As Variant
randomize()
rand0 = Int((n / 10) * 1) * Rnd + 1
rand1 = Int((n / 10) * 2 - (n / 10) * 1 + 1) * Rnd + (n / 10) * 1
rand2 = Int((n / 10) * 3 - (n / 10) * 2 + 1) * Rnd + (n / 10) * 2
rand3 = Int((n / 10) * 4 - (n / 10) * 3 + 1) * Rnd + (n / 10) * 3
rand4 = Int((n / 10) * 5 - (n / 10) * 4 + 1) * Rnd + (n / 10) * 4
rand5 = Int((n / 10) * 6 - (n / 10) * 5 + 1) * Rnd + (n / 10) * 5
rand6 = Int((n / 10) * 7 - (n / 10) * 6 + 1) * Rnd + (n / 10) * 6
rand7 = Int((n / 10) * 8 - (n / 10) * 7 + 1) * Rnd + (n / 10) * 7
rand8 = Int((n / 10) * 9 - (n / 10) * 8 + 1) * Rnd + (n / 10) * 8
rand9 = Int(n - (n / 10) * 9 + 1) * Rnd + (n / 10) * 9
decilesArray= Array(rand0,rand1,rand2,rand3,rand4,rand5,rand6,rand7,rand8,rand9)
End Sub
I propose this correction,
public dim statements should be defined outside sub or functions.
use an array instead of concatenation to refer to a variable, rand & dec is not a correct VBA syntax to address rand0, ... rand9 variables.
Dim rand(9)
Sub check_changes_param()
Dim Dec As Integer, n
' Call public_dims ' put dim instructions as first instructions of this module
n = 10 'modify 10 to reflect correct value
Call deciles(n)
Set ParamBook = Workbooks.Open(ParamLocation)
'==========CHECKS IF PARAMETERS.xlsm EXISTS IN THE CORRECT LOCATION==========
If ParamLocation = "" Then
MsgBox "The Parameters.xlsm file does not exist or is in the incorrect location. Please ensure it is located in " & ParamLocation
Else
For Dec = 0 To 9
If ThisWorkbook.Sheets("Data").Cells(rand(Dec), 11) <> ParamBook.Sheets("Data").Cells(rand(Dec), 11) Or n <> np Then
Call get_param
Exit For
End If
Next Dec
End If
End Sub
Public Sub deciles(n)
rand(0) = Int((n / 10) * 1) * Rnd + 1
For i = 1 To 8
rand(i) = Int((n / 10) * (i + 1) - (n / 10) * (i + 1) + 1) * Rnd + (n / 10) * i
Next
rand(9) = Int(n - (n / 10) * 9 + 1) * Rnd + (n / 10) * 9
End Sub
I'm new to Corona SDK.
I'm implementing a test using drag-and-drop for an application.
I implemented the code bellow for a container that "attract" the dragging object that is near it.
display.setStatusBar( display.HiddenStatusBar )
local posX, posY = 100, 200
local sizeX, sizeY = 150, 100
local container = display.newRect( posX, posY, sizeX, sizeY )
container:setFillColor( 255,0,0 )
container.strokeWidth = 3
container:setStrokeColor(100, 100, 100)
local myObject = display.newRect( 0, 0, sizeX, sizeY )
myObject.alpha = 0.6
myObject:setFillColor( 0,0,255 )
-- dcenter, d1, d2, d3, d4 are test points: IF THERE ARE AT LEAST 2 POINTS INSIDE THE TARGET CONTAINER, THAN THE OBJECT WILL BE ATRACTED INTO THE CONTAINER
-- uncomment the code bellow to see the test points
-- local dcenter = display.newCircle( (sizeX/2) - 1, (sizeY/2) - 1, 2 )
-- dcenter:setFillColor(120,120,120)
--
-- local d1 = display.newCircle( (sizeX/2) - (((1/3) * sizeX)/2) - 1, (sizeY/2) - (((1/3) * sizeY)/2) - 1, 2 )
-- d1:setFillColor(120,120,120)
--
-- local d2 = display.newCircle( (sizeX/2) - (((1/3) * sizeX)/2) - 1, (sizeY/2) + (((1/3) * sizeY)/2) - 1, 2 )
-- d2:setFillColor(120,120,120)
--
-- local d3 = display.newCircle( (sizeX/2) + (((1/3) * sizeX)/2) - 1, (sizeY/2) - (((1/3) * sizeY)/2) - 1, 2 )
-- d3:setFillColor(120,120,120)
--
-- local d4 = display.newCircle( (sizeX/2) + (((1/3) * sizeX)/2) - 1, (sizeY/2) + (((1/3) * sizeY)/2) - 1, 2 )
-- d4:setFillColor(120,120,120)
-- touch listener function
function myObject:touch( event )
if event.phase == "began" then
self.markX = self.x -- store x location of object
self.markY = self.y -- store y location of object
elseif event.phase == "moved" then
local x = (event.x - event.xStart) + self.markX
local y = (event.y - event.yStart) + self.markY
self.x, self.y = x, y -- move object based on calculations above
-- uncomment the code bellow to see the test points (following myObject)
-- dcenter.x, dcenter.y = x, y
-- d1.x, d1.y = x - (((1/3) * sizeX)/2), y - (((1/3) * sizeY)/2)
-- d2.x, d2.y = x - (((1/3) * sizeX)/2), y + (((1/3) * sizeY)/2)
-- d3.x, d3.y = x + (((1/3) * sizeX)/2), y - (((1/3) * sizeY)/2)
-- d4.x, d4.y = x + (((1/3) * sizeX)/2), y + (((1/3) * sizeY)/2)
if (((x >= ((sizeX/2) + posX - ((2/3) * sizeX))) and (y >= ((sizeY/2) + posY - ((1/3) * sizeY))) and (x <= ((sizeX/2) + posX + ((2/3) * sizeX))) and (y <= ((sizeY/2) + posY + ((1/3) * sizeY)))) or ((x >= ((sizeX/2) + posX - ((1/3) * sizeX))) and (y >= ((sizeY/2) + posY - ((2/3) * sizeY))) and (x <= ((sizeX/2) + posX + ((1/3) * sizeX))) and (y <= ((sizeY/2) + posY + ((2/3) * sizeY)))) or ((x >= ((sizeX/2) + posX - ((1/2) * sizeX))) and (y >= ((sizeY/2) + posY - ((1/2) * sizeY))) and (x <= ((sizeX/2) + posX + ((1/2) * sizeX))) and (y <= ((sizeY/2) + posY + ((1/2) * sizeY))))) then
container:setFillColor( 100,0,0 )
else
container:setFillColor( 255,0,0 )
end
elseif event.phase == "ended" then
local x = (event.x - event.xStart) + self.markX
local y = (event.y - event.yStart) + self.markY
-- main condition: I calculated 3 areas to atract the object to the target container, 2 areas that atract it when it's 1/3 in the target and 1 area that atract it when it's 1/4 in the target
if (((x >= ((sizeX/2) + posX - ((2/3) * sizeX))) and (y >= ((sizeY/2) + posY - ((1/3) * sizeY))) and (x <= ((sizeX/2) + posX + ((2/3) * sizeX))) and (y <= ((sizeY/2) + posY + ((1/3) * sizeY)))) or ((x >= ((sizeX/2) + posX - ((1/3) * sizeX))) and (y >= ((sizeY/2) + posY - ((2/3) * sizeY))) and (x <= ((sizeX/2) + posX + ((1/3) * sizeX))) and (y <= ((sizeY/2) + posY + ((2/3) * sizeY)))) or ((x >= ((sizeX/2) + posX - ((1/2) * sizeX))) and (y >= ((sizeY/2) + posY - ((1/2) * sizeY))) and (x <= ((sizeX/2) + posX + ((1/2) * sizeX))) and (y <= ((sizeY/2) + posY + ((1/2) * sizeY))))) then
self.x, self.y = posX + (sizeX/2), posY + (sizeY/2);
-- uncomment the code bellow to see the test points (following myObject)
-- dcenter.x, dcenter.y = posX + (sizeX/2), posY + (sizeY/2)
-- d1.x, d1.y = posX - (((1/3) * sizeX)/2) + (sizeX/2), posY - (((1/3) * sizeY)/2) + (sizeY/2)
-- d2.x, d2.y = posX - (((1/3) * sizeX)/2) + (sizeX/2), posY + (((1/3) * sizeY)/2) + (sizeY/2)
-- d3.x, d3.y = posX + (((1/3) * sizeX)/2) + (sizeX/2), posY - (((1/3) * sizeY)/2) + (sizeY/2)
-- d4.x, d4.y = posX + (((1/3) * sizeX)/2) + (sizeX/2), posY + (((1/3) * sizeY)/2) + (sizeY/2)
end
end
return true
end
myObject:addEventListener( "touch", myObject )
I just want to know if there is some api for it already.
Nope, there are no API for it.
Also I suggest you use the focus system, so you do not interact with "touch" events of other objects while dragging yours...
Example:
local function myTouchListener(event)
if event.phase == "began" then
display.getCurrentStage( ):setFocus( event.target );
elseif event.phase == "ended" then
display.getCurrentStage( ):setFocus( nil );
end
end