Table of Contents

Struct Distance

Namespace
Ranorex.Core
Assembly
Ranorex.Core.dll

Represents an proportional or fixed distance in pixels.

[TypeConverter(typeof(Distance.DistanceConverter))]
public struct Distance
Inherited Members

Remarks

A fixed distance specifies the distance in pixels. The proportional distance is specified as the percentage of an elements width or height. Proportional distances are only useful when they are used in conjunction with an Ranorex.Core.Recorder.Touch.GestureDirection to calculate the fixed distance based on some element rectangle.

Constructors

Distance(double)

Creates a new proportional distance.

public Distance(double proportionalDistance)

Parameters

proportionalDistance double

The proportional distance. Can exceed 1.0.

Exceptions

ArgumentOutOfRangeException

If proportionalDistance is less than zero.

Distance(int)

Creates a new fixed distance.

public Distance(int fixedDistance)

Parameters

fixedDistance int

The fixed distance in pixels

Exceptions

ArgumentOutOfRangeException

If fixedDistance is less than zero.

Properties

FixedDistance

Gets the fixed distance in pixels. Throws an exception if the distance is a proportional distance.

public int FixedDistance { get; }

Property Value

int

The fixed distance.

Exceptions

InvalidOperationException

If the location is not a fixed location.

IsFixedDistance

Gets a value indicating whether the this instance is a fixed e.g. has a fixed pixel value.

public bool IsFixedDistance { get; }

Property Value

bool

true if this instance is fixed; otherwise false

ProportionalDistance

Gets the proportional distance. Throws an exception if the distance is a fixed distance.

public double ProportionalDistance { get; }

Property Value

double

The proportional distance.

Exceptions

InvalidOperationException

If the location is not a proportional location.

Methods

CalculateFixedDistance(Rectangle, GestureDirection)

Calculates the fixed distance for the specified element rectangle and the given angle.

public int CalculateFixedDistance(Rectangle elementRectangle, GestureDirection angle)

Parameters

elementRectangle Rectangle

The pixel based rectangle to calculate the fixed distance for.

angle GestureDirection

The angle that determines if width or height will be used for the calculation.

Returns

int

The fixed distance in pixels (rounded).

Remarks

If the distance is already a fixed distance, simply the fixed distance value will be returned. The given element rectangle and the gesture angle will not affect the distance. These will only affect the distance, if the distance is a proportional distance. The function will determine by the given angle if the width or the height of the element rectangle will be used to calculate the distance. The height will be used if 225 < angle <= 315 or 45 < angle <= 135; otherwise the width will be used.

Equals(object)

Compares two distances if they are equal.

public override bool Equals(object obj)

Parameters

obj object

The second distance.

Returns

bool

true

FromFixedDistance(int)

Converts from int to a Distance.

public static Distance FromFixedDistance(int fixedDistance)

Parameters

fixedDistance int

The fixed distance in pixels.

Returns

Distance

A new fixed distance instance.

FromProportionalDistance(double)

Converts from double to a Distance.

public static Distance FromProportionalDistance(double proportionalDistance)

Parameters

proportionalDistance double

The proportional distance.

Returns

Distance

A new proportional distance instance.

GetHashCode()

Returns a integer hash code for the current object.

public override int GetHashCode()

Returns

int

A hash code for the current object.

Parse(string)

Converts a string representation of a distance to its distance equivalent.

public static Distance Parse(string s)

Parameters

s string

A string containing the distance to convert.

Returns

Distance

A new distance parsed from the given string

Exceptions

ArgumentNullException

If the given string is null.

ArgumentException

If the given string is not a numeric type (int or double).

ArgumentOutOfRangeException

If the given string is a negative number.

ToString()

Returns a string representation of the distance.

public override string ToString()

Returns

string

Returns the fixed distance e.g. "200" or the proportional distance with format '#.0##' e.g. ".25".

TryParse(string, out Distance)

Converts a string representation of a distance to its distance equivalent. The return value indicates whether the conversion succeeded.

public static bool TryParse(string s, out Distance d)

Parameters

s string

A string containing the distance to convert.

d Distance

The parsed distance

Returns

bool

When this method returns, 'd' contains the distance equivalent if the conversion succeeded, or Distance(0) if the conversion failed. The conversion fails if parameter 's' is null, Empty, it has a invalid format or the given string represents a negative number.

Exceptions

ArgumentNullException

If the given string is null.

ArgumentException

If the given string is not a numeric type (int or double).

ArgumentOutOfRangeException

If the given string is a negative number.

Operators

operator ==(Distance, Distance)

Compares two distances if they are equal.

public static bool operator ==(Distance d1, Distance d2)

Parameters

d1 Distance

First distance

d2 Distance

Second distance

Returns

bool

true if both distances are equal; otherwise false

implicit operator Distance(double)

Performs an implicit conversion from double to a Distance.

public static implicit operator Distance(double proportionalDistance)

Parameters

proportionalDistance double

The proportional distance.

Returns

Distance

A new proportional distance instance.

implicit operator Distance(int)

Performs an implicit conversion from int to a Distance.

public static implicit operator Distance(int fixedDistance)

Parameters

fixedDistance int

The fixed distance in pixels.

Returns

Distance

A new fixed distance instance.

operator !=(Distance, Distance)

Compares two distances if they are not equal.

public static bool operator !=(Distance d1, Distance d2)

Parameters

d1 Distance

First distance

d2 Distance

Second distance

Returns

bool

true if the distances are not equal; otherwise false