Skip to content

Commit b31352c

Browse files
authored
Reduce duplication in PointElement (#8517)
1 parent 5ab5552 commit b31352c

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/elements/element.point.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
import Element from '../core/core.element';
22
import {drawPoint} from '../helpers/helpers.canvas';
33

4+
function inRange(el, pos, axis, useFinalPosition) {
5+
const options = el.options;
6+
const {[axis]: value} = el.getProps([axis], useFinalPosition);
7+
8+
return (Math.abs(pos - value) < options.radius + options.hitRadius);
9+
}
10+
411
export default class PointElement extends Element {
512

613
constructor(cfg) {
@@ -22,16 +29,11 @@ export default class PointElement extends Element {
2229
}
2330

2431
inXRange(mouseX, useFinalPosition) {
25-
const options = this.options;
26-
const {x} = this.getProps(['x'], useFinalPosition);
27-
28-
return (Math.abs(mouseX - x) < options.radius + options.hitRadius);
32+
return inRange(this, mouseX, 'x', useFinalPosition);
2933
}
3034

3135
inYRange(mouseY, useFinalPosition) {
32-
const options = this.options;
33-
const {y} = this.getProps(['x'], useFinalPosition);
34-
return (Math.abs(mouseY - y) < options.radius + options.hitRadius);
36+
return inRange(this, mouseY, 'y', useFinalPosition);
3537
}
3638

3739
getCenterPoint(useFinalPosition) {

0 commit comments

Comments
 (0)