## "Fossies" - the Fresh Open Source Software Archive

### Member "selenium-selenium-4.8.1/cpp/webdriver-interactions/interactions_common.cpp" (17 Feb 2023, 1728 Bytes) of package /linux/www/selenium-selenium-4.8.1.tar.gz:

As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:

standard) with prefixed line numbers and

code folding option.
Alternatively you can here

view or

download the uninterpreted source code file.
For more information about "interactions_common.cpp" see the

Fossies "Dox" file reference documentation.

1 /*
2 Licensed to the Software Freedom Conservancy (SFC) under one
3 or more contributor license agreements. See the NOTICE file
4 distributed with this work for additional information
5 regarding copyright ownership. The SFC licenses this file
6 to you under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
9
10 http://www.apache.org/licenses/LICENSE-2.0
11
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
17 */
18
19 #include "interactions_common.h"
20 #include "logging.h"
21
22 #include <assert.h>
23 #include <math.h>
24 #include <stdlib.h>
25
26 unsigned long distanceBetweenPoints(long fromX, long fromY, long toX, long toY)
27 {
28 if (fromX < 0) {
29 LOG(WARN) << "From X appears to be < 0. Rounding to 0. " << fromX;
30 fromX = 0;
31 }
32 if (fromY < 0) {
33 LOG(WARN) << "From Y appears to be < 0. Rounding to 0. " << fromY;
34 fromY = 0;
35 }
36 if (toX < 0) {
37 LOG(WARN) << "To X appears to be < 0. Rounding to 0. " << toX;
38 toX = 0;
39 }
40 if (toY < 0) {
41 LOG(WARN) << "From X appears to be < 0. Rounding to 0. " << toY;
42 toY = 0;
43 }
44
45
46 assert(fromX >= 0);
47 assert(fromY >= 0);
48 assert(toX >= 0);
49 assert(toY >= 0);
50
51
52 long xDiff = abs(toX - fromX);
53 long yDiff = abs(toY - fromY);
54
55 // Cast first argument of pow to double, since conversion of arguments on
56 // Visual Studio ends up creating ambiguity.
57 return (long) sqrt(pow((double) xDiff, 2) + pow((double) yDiff, 2));
58 }