@@ -5,19 +5,19 @@ import {
55
66import { scalePartialCoordinate } from './coordinateUtils.js' ;
77
8- function toCanvasCoords ( position , camera ) {
9- const temporaryPosition = position . clone ( ) . applyMatrix4 (
8+ // This changes the value of position.
9+ function toCanvasCoords ( position , camera , canvasSize , maxSize ) {
10+ position . applyMatrix4 (
1011 new Matrix4 ( ) . multiplyMatrices (
1112 camera . projectionMatrix ,
1213 camera . matrixWorldInverse
1314 )
1415 ) ;
1516
16- return new Vector3 (
17- ( temporaryPosition . x + 1 ) * 200 ,
18- ( 1 - temporaryPosition . y ) * 200 ,
19- 0
20- ) ;
17+ return [
18+ ( position . x + 1 ) * 200 * canvasSize / maxSize ,
19+ ( 1 - position . y ) * 200 * canvasSize / maxSize
20+ ] ;
2121}
2222
2323// i is 0, 1 or 2.
@@ -52,14 +52,16 @@ export function positionTickNumbers(
5252
5353 ticks [ i ] . geometry . attributes . position . array [ j * 6 + 2 ] * 7 - ticks [ i ] . geometry . attributes . position . array [ j * 6 + 5 ] * 6
5454 ) ,
55- camera
56- ) . multiplyScalar ( canvasSize / maxSize ) ;
55+ camera ,
56+ canvasSize ,
57+ maxSize
58+ ) ;
5759
58- if ( tickPosition . x < 5 || tickPosition . x > 395 || tickPosition . y < 5 || tickPosition . y > 395 ) {
60+ if ( tickPosition [ 0 ] < 5 || tickPosition [ 0 ] > 395 || tickPosition [ 1 ] < 5 || tickPosition [ 1 ] > 395 ) {
5961 tickNumbers [ i ] [ j ] . style . display = 'none' ;
6062 } else {
61- tickNumbers [ i ] [ j ] . style . left = `${ tickPosition . x } px` ;
62- tickNumbers [ i ] [ j ] . style . top = `${ tickPosition . y } px` ;
63+ tickNumbers [ i ] [ j ] . style . left = `${ tickPosition [ 0 ] } px` ;
64+ tickNumbers [ i ] [ j ] . style . top = `${ tickPosition [ 1 ] } px` ;
6365 tickNumbers [ i ] [ j ] . style . display = '' ;
6466 }
6567 }
0 commit comments