Skip to content

Commit

Permalink
Unify Vector-related constant naming scheme across Web and Android im…
Browse files Browse the repository at this point in the history
…plementations (#3052)

## Description

Rename constant determining whether magnitude is sufficient to
`MINIMAL_RECOGNIZABLE_MAGNITUDE` on both `Web` and `Android`

## Test plan

not applicable
  • Loading branch information
latekvo authored Aug 21, 2024
1 parent 40b4e11 commit 7346c2f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Vector(val x: Double, val y: Double) {
val magnitude = hypot(x, y)

init {
val isMagnitudeSufficient = magnitude > MINIMAL_MAGNITUDE
val isMagnitudeSufficient = magnitude > MINIMAL_RECOGNIZABLE_MAGNITUDE

unitX = if (isMagnitudeSufficient) x / magnitude else 0.0
unitY = if (isMagnitudeSufficient) y / magnitude else 0.0
Expand All @@ -39,7 +39,7 @@ class Vector(val x: Double, val y: Double) {
private val VECTOR_LEFT_DOWN: Vector = Vector(-1.0, 1.0)

private val VECTOR_ZERO: Vector = Vector(0.0, 0.0)
private const val MINIMAL_MAGNITUDE = 0.1
private const val MINIMAL_RECOGNIZABLE_MAGNITUDE = 0.1

fun fromDirection(direction: Int): Vector =
when (direction) {
Expand Down
2 changes: 1 addition & 1 deletion src/web/constants.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export const DEFAULT_TOUCH_SLOP = 15;
export const MINIMAL_FLING_VELOCITY = 0.1;
export const MINIMAL_RECOGNIZABLE_MAGNITUDE = 0.1;
7 changes: 4 additions & 3 deletions src/web/tools/Vector.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DiagonalDirections, Directions } from '../../Directions';
import { MINIMAL_FLING_VELOCITY } from '../constants';
import { MINIMAL_RECOGNIZABLE_MAGNITUDE } from '../constants';
import PointerTracker from './PointerTracker';

export default class Vector {
Expand All @@ -14,14 +14,15 @@ export default class Vector {
this.y = y;

this._magnitude = Math.hypot(this.x, this.y);
const isMagnitudeSufficient = this._magnitude > MINIMAL_FLING_VELOCITY;
const isMagnitudeSufficient =
this._magnitude > MINIMAL_RECOGNIZABLE_MAGNITUDE;

this.unitX = isMagnitudeSufficient ? this.x / this._magnitude : 0;
this.unitY = isMagnitudeSufficient ? this.y / this._magnitude : 0;
}

static fromDirection(direction: Directions | DiagonalDirections): Vector {
return DirectionToVectorMappings.get(direction)!;
return DirectionToVectorMappings.get(direction) ?? new Vector(0, 0);
}

static fromVelocity(tracker: PointerTracker, pointerId: number) {
Expand Down

0 comments on commit 7346c2f

Please sign in to comment.