Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
frontend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Jira
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
minerva
frontend
Commits
fecf722b
Commit
fecf722b
authored
1 year ago
by
Adrian Orłów
Browse files
Options
Downloads
Patches
Plain Diff
feat(map): improve readability and tests of point offset util
parent
b64ca935
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!223
reset the pin numbers before search results are fetch (so the results will be...
,
!36
feat(map): add render components and tests
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/utils/map/getPointOffset.test.ts
+8
-14
8 additions, 14 deletions
src/utils/map/getPointOffset.test.ts
src/utils/map/getPointOffset.ts
+4
-8
4 additions, 8 deletions
src/utils/map/getPointOffset.ts
with
12 additions
and
22 deletions
src/utils/map/getPointO
riginAndShifted
.test.ts
→
src/utils/map/getPointO
ffset
.test.ts
+
8
−
14
View file @
fecf722b
/* eslint-disable no-magic-numbers */
/* eslint-disable no-magic-numbers */
import
{
ZodError
}
from
'
zod
'
;
import
{
ZodError
}
from
'
zod
'
;
import
{
getPointO
riginAndShifted
}
from
'
./getPointO
riginAndShifted
'
;
import
{
getPointO
ffset
}
from
'
./getPointO
ffset
'
;
describe
(
'
getPointO
riginAndShifted
- util
'
,
()
=>
{
describe
(
'
getPointO
ffset
- util
'
,
()
=>
{
describe
(
'
when all args are valid
'
,
()
=>
{
describe
(
'
when all args are valid
'
,
()
=>
{
const
validPoint
=
{
const
validPoint
=
{
x
:
256
,
x
:
256
,
y
:
256
,
y
:
256
*
2
,
};
};
const
validMapSize
=
{
const
validMapSize
=
{
...
@@ -18,22 +18,16 @@ describe('getPointOriginAndShifted - util', () => {
...
@@ -18,22 +18,16 @@ describe('getPointOriginAndShifted - util', () => {
};
};
const
results
=
{
const
results
=
{
pointOrigin
:
{
x
:
-
115.2
,
x
:
128
,
y
:
-
102.4
,
y
:
128
,
},
pointShifted
:
{
x
:
12.8
,
y
:
12.8
,
},
};
};
it
(
'
should return valid point origin and shifted values
'
,
()
=>
{
it
(
'
should return valid point origin and shifted values
'
,
()
=>
{
expect
(
getPointO
riginAndShifted
(
validPoint
,
validMapSize
)).
toMatchObject
(
results
);
expect
(
getPointO
ffset
(
validPoint
,
validMapSize
)).
toMatchObject
(
results
);
});
});
it
(
'
should not throw error
'
,
()
=>
{
it
(
'
should not throw error
'
,
()
=>
{
expect
(()
=>
getPointO
riginAndShifted
(
validPoint
,
validMapSize
)).
not
.
toThrow
(
ZodError
);
expect
(()
=>
getPointO
ffset
(
validPoint
,
validMapSize
)).
not
.
toThrow
(
ZodError
);
});
});
});
});
...
@@ -53,7 +47,7 @@ describe('getPointOriginAndShifted - util', () => {
...
@@ -53,7 +47,7 @@ describe('getPointOriginAndShifted - util', () => {
};
};
it
(
'
should throw error
'
,
()
=>
{
it
(
'
should throw error
'
,
()
=>
{
expect
(()
=>
getPointO
riginAndShifted
(
validPoint
,
invalidMapSize
)).
toThrow
(
ZodError
);
expect
(()
=>
getPointO
ffset
(
validPoint
,
invalidMapSize
)).
toThrow
(
ZodError
);
});
});
});
});
});
});
This diff is collapsed.
Click to expand it.
src/utils/map/getPointO
riginAndShifted
.ts
→
src/utils/map/getPointO
ffset
.ts
+
4
−
8
View file @
fecf722b
...
@@ -3,17 +3,13 @@ import { VALID_MAP_SIZE_SCHEMA } from '@/constants/map';
...
@@ -3,17 +3,13 @@ import { VALID_MAP_SIZE_SCHEMA } from '@/constants/map';
import
{
MapSize
}
from
'
@/redux/map/map.types
'
;
import
{
MapSize
}
from
'
@/redux/map/map.types
'
;
import
{
Point
}
from
'
@/types/map
'
;
import
{
Point
}
from
'
@/types/map
'
;
export
const
getPointOriginAndShifted
=
(
export
const
getPointOffset
=
(
point
:
Point
,
mapSize
:
MapSize
):
Point
=>
{
point
:
Point
,
mapSize
:
MapSize
,
):
Record
<
'
pointOrigin
'
|
'
pointShifted
'
,
Point
>
=>
{
// parse throws error if map size may lead to invalid results
// parse throws error if map size may lead to invalid results
VALID_MAP_SIZE_SCHEMA
.
parse
(
mapSize
);
VALID_MAP_SIZE_SCHEMA
.
parse
(
mapSize
);
const
longestSide
=
Math
.
max
(
mapSize
.
width
,
mapSize
.
height
);
const
minZoomShifted
=
mapSize
.
minZoom
*
2
**
mapSize
.
minZoom
;
const
minZoomShifted
=
mapSize
.
minZoom
*
2
**
mapSize
.
minZoom
;
const
zoomFactor
=
const
zoomFactor
=
longestSide
/
(
mapSize
.
tileSize
/
minZoomShifted
);
// eslint-disable-next-line no-bitwise
Math
.
max
(
mapSize
.
width
,
mapSize
.
height
)
/
(
mapSize
.
tileSize
/
minZoomShifted
);
const
pointOrigin
:
Point
=
{
const
pointOrigin
:
Point
=
{
x
:
mapSize
.
tileSize
/
2
,
x
:
mapSize
.
tileSize
/
2
,
...
@@ -25,5 +21,5 @@ export const getPointOriginAndShifted = (
...
@@ -25,5 +21,5 @@ export const getPointOriginAndShifted = (
y
:
point
.
y
/
zoomFactor
,
y
:
point
.
y
/
zoomFactor
,
};
};
return
{
pointOrigin
,
pointShifted
};
return
{
x
:
pointShifted
.
x
-
pointOrigin
.
x
,
y
:
pointShifted
.
y
-
pointOrigin
.
y
};
};
};
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment