Replace sqrt in Dimension by Fast inverse square root
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
d6eb9ea364
commit
497d2173e8
2 changed files with 24 additions and 2 deletions
|
@ -1,5 +1,6 @@
|
|||
import * as React from 'react';
|
||||
import { NOTCHES_LENGTH } from '../../../utils/default';
|
||||
import { Qrsqrt } from '../../../utils/math';
|
||||
|
||||
interface IDimensionProps {
|
||||
id: string
|
||||
|
@ -32,8 +33,8 @@ export const Dimension: React.FC<IDimensionProps> = (props: IDimensionProps) =>
|
|||
const [deltaX, deltaY] = [(props.xEnd - props.xStart), (props.yEnd - props.yStart)];
|
||||
|
||||
// Get the unit vector
|
||||
const norm = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
|
||||
const [unitX, unitY] = [deltaX / norm, deltaY / norm];
|
||||
const inv = Qrsqrt(deltaX * deltaX + deltaY * deltaY);
|
||||
const [unitX, unitY] = [deltaX * inv, deltaY * inv];
|
||||
|
||||
// Get the perpandicular vector
|
||||
const [perpVecX, perpVecY] = [unitY, -unitX];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue