Path: blob/trunk/cpp/webdriver-interactions/interactions_common.cpp
2867 views
/*1Licensed to the Software Freedom Conservancy (SFC) under one2or more contributor license agreements. See the NOTICE file3distributed with this work for additional information4regarding copyright ownership. The SFC licenses this file5to you under the Apache License, Version 2.0 (the "License");6you may not use this file except in compliance with the License.7You may obtain a copy of the License at89http://www.apache.org/licenses/LICENSE-2.01011Unless required by applicable law or agreed to in writing, software12distributed under the License is distributed on an "AS IS" BASIS,13WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.14See the License for the specific language governing permissions and15limitations under the License.16*/1718#include "interactions_common.h"19#include "logging.h"2021#include <assert.h>22#include <math.h>23#include <stdlib.h>2425unsigned long distanceBetweenPoints(long fromX, long fromY, long toX, long toY)26{27if (fromX < 0) {28LOG(WARN) << "From X appears to be < 0. Rounding to 0. " << fromX;29fromX = 0;30}31if (fromY < 0) {32LOG(WARN) << "From Y appears to be < 0. Rounding to 0. " << fromY;33fromY = 0;34}35if (toX < 0) {36LOG(WARN) << "To X appears to be < 0. Rounding to 0. " << toX;37toX = 0;38}39if (toY < 0) {40LOG(WARN) << "From X appears to be < 0. Rounding to 0. " << toY;41toY = 0;42}434445assert(fromX >= 0);46assert(fromY >= 0);47assert(toX >= 0);48assert(toY >= 0);495051long xDiff = abs(toX - fromX);52long yDiff = abs(toY - fromY);5354// Cast first argument of pow to double, since conversion of arguments on55// Visual Studio ends up creating ambiguity.56return (long) sqrt(pow((double) xDiff, 2) + pow((double) yDiff, 2));57}5859