Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
snip
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
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
irp
snip
Commits
8950ff83
Commit
8950ff83
authored
1 month ago
by
Sebastian Mohr
Browse files
Options
Downloads
Patches
Plain Diff
Allow to render grid from data. Seems like we dont need to compute the
grid our-self.
parent
220678f1
No related branches found
No related tags found
No related merge requests found
Pipeline
#591243
skipped
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
packages/snips/src/uprp/stampy.ts
+75
-48
75 additions, 48 deletions
packages/snips/src/uprp/stampy.ts
with
75 additions
and
48 deletions
packages/snips/src/uprp/stampy.ts
+
75
−
48
View file @
8950ff83
...
@@ -190,64 +190,84 @@ export class StampySnip extends BaseSnip {
...
@@ -190,64 +190,84 @@ export class StampySnip extends BaseSnip {
return
this
.
stampy
.
measurement
.
volume
;
return
this
.
stampy
.
measurement
.
volume
;
}
}
get
grid
()
{
return
this
.
stampy
.
measurement
.
grid
;
}
// TODO: Make this dynamic
// TODO: Make this dynamic
get
width
():
number
{
get
width
():
number
{
return
7
00
;
return
4
00
;
}
}
get
height
():
number
{
get
height
():
number
{
return
7
00
;
return
4
00
;
}
}
private
computeScale
():
number
{
/** Compute the scale such that
// compute scale from given data to fit into
* the max values fits inside
// the width and height of the canvas
* the width and height
// TODO: Implement this
*/
return
150
;
private
computeScale
(
width
:
number
,
height
:
number
,
max
:
number
):
number
{
return
Math
.
min
(
width
,
height
)
/
max
;
}
}
public
render
(
ctx
:
RenderContext
):
void
{
public
render
(
ctx
:
RenderContext
):
void
{
// Apply translate, rotate and mirror
// see base.ts
const
transform
=
ctx
.
getTransform
();
this
.
transform
(
ctx
);
this
.
renderGrid
(
ctx
);
ctx
.
setTransform
(
transform
);
}
public
renderGrid
(
ctx
:
RenderContext
):
void
{
const
gridWidth
=
500
;
const
gridHeight
=
500
;
// Draw rect around the area
// Draw rect around the area
ctx
.
rect
(
0
,
0
,
this
.
width
,
this
.
h
eight
);
ctx
.
rect
(
0
,
0
,
gridWidth
,
gridH
eight
);
ctx
.
stroke
();
ctx
.
stroke
();
// Render sample circle
ctx
.
translate
(
gridHeight
/
2
,
gridHeight
/
2
);
const
s
=
this
.
computeScale
();
const
s
=
this
.
computeScale
(
this
.
drawCircle
(
gridWidth
,
ctx
,
gridHeight
,
this
.
width
/
2
,
this
.
volume
.
diameter
*
2.5
,
this
.
height
/
2
,
);
(
this
.
volume
.
diameter
/
2
)
*
s
,
{
// Render grid
const
r
=
(
this
.
volume
.
fovw
*
s
)
/
2
;
const
positions
=
this
.
grid
.
values
;
for
(
let
i
=
0
;
i
<
positions
.
length
;
i
++
)
{
const
x
=
positions
[
i
]
!
[
0
]
!
;
const
y
=
positions
[
i
]
!
[
1
]
!
;
this
.
drawCircle
(
ctx
,
x
*
s
,
y
*
s
,
r
,
{
stroke
:
"
#000
"
,
stroke
:
"
#000
"
,
fill
:
"
red
"
,
fill
:
"
#000
"
,
fill_alpha
:
0.2
,
fill_alpha
:
0.2
,
},
});
);
}
// Render sample circle
this
.
drawCircle
(
ctx
,
0
,
0
,
(
this
.
volume
.
diameter
/
2
)
*
s
,
{
stroke
:
"
#000
"
,
fill
:
"
red
"
,
fill_alpha
:
0.2
,
});
// Render scale
// Render scale
this
.
drawScale
(
ctx
,
s
);
this
.
drawScale
(
ctx
,
s
,
gridWidth
/
2
,
gridHeight
/
2
);
// Render grid points
const
grid
=
new
HexagonalGrid
(
0
,
0
,
0
,
50
,
this
.
width
/
2
,
this
.
height
/
2
,
);
for
(
let
i
=
-
1
;
i
<
2
;
i
++
)
{
// Label
for
(
let
j
=
-
1
;
j
<
2
;
j
++
)
{
ctx
.
font
=
"
bold 18px Arial
"
;
const
{
x
,
y
}
=
grid
.
axialToPixel
(
i
,
j
);
ctx
.
fillStyle
=
"
#000
"
;
this
.
drawCircle
(
ctx
,
x
,
y
,
2
,
{
ctx
.
textBaseline
=
"
top
"
;
stroke
:
"
#000
"
,
ctx
.
fillText
(
fill
:
"
#000
"
,
`Grid (
${
this
.
grid
.
method
}
)`
,
});
-
gridWidth
/
2
+
5
,
const
txt
=
`
${
i
}
,
${
j
}
`
;
-
gridHeight
/
2
+
5
,
ctx
.
fillText
(
txt
,
x
+
5
,
y
+
5
);
);
}
}
}
}
private
drawCircle
(
private
drawCircle
(
...
@@ -306,25 +326,31 @@ export class StampySnip extends BaseSnip {
...
@@ -306,25 +326,31 @@ export class StampySnip extends BaseSnip {
* If the scale is too small, the scale will be multiplied until it is
* If the scale is too small, the scale will be multiplied until it is
* at least 150px.
* at least 150px.
*/
*/
private
drawScale
(
ctx
:
RenderContext
,
scale
:
number
)
{
private
drawScale
(
ctx
:
RenderContext
,
scale
:
number
,
x
:
number
=
0
,
y
:
number
=
0
,
padding
:
number
=
10
,
)
{
ctx
.
save
();
let
mm
=
1
;
let
mm
=
1
;
let
s
=
scale
;
let
s
=
scale
;
while
(
s
<
1
50
)
{
while
(
s
<
50
)
{
mm
*=
2
;
mm
*=
2
;
s
*=
2
;
s
*=
2
;
}
}
// pos
// pos
const
padding
=
10
;
const
rectHeight
=
5
;
const
rectHeight
=
5
;
const
x
=
this
.
width
-
s
-
padding
;
const
_
x
=
x
-
s
-
padding
;
const
y
=
this
.
height
-
rectHeight
-
padding
-
18
;
//18=font size
const
_
y
=
y
-
rectHeight
-
padding
-
18
;
//18=font size
// Render scale rect
// Render scale rect
ctx
.
globalAlpha
=
0.8
;
ctx
.
globalAlpha
=
0.8
;
ctx
.
fillStyle
=
"
#000
"
;
ctx
.
fillStyle
=
"
#000
"
;
ctx
.
beginPath
();
ctx
.
beginPath
();
ctx
.
fillRect
(
x
,
y
,
s
,
rectHeight
);
ctx
.
fillRect
(
_
x
,
_
y
,
s
,
rectHeight
);
ctx
.
stroke
();
ctx
.
stroke
();
// Render text
// Render text
...
@@ -333,7 +359,8 @@ export class StampySnip extends BaseSnip {
...
@@ -333,7 +359,8 @@ export class StampySnip extends BaseSnip {
ctx
.
font
=
"
18px Arial
"
;
ctx
.
font
=
"
18px Arial
"
;
ctx
.
textBaseline
=
"
top
"
;
ctx
.
textBaseline
=
"
top
"
;
const
ts
=
ctx
.
measureText
(
`
${
mm
}
mm`
);
const
ts
=
ctx
.
measureText
(
`
${
mm
}
mm`
);
ctx
.
fillText
(
`
${
mm
}
mm`
,
x
+
s
/
2
-
ts
.
width
/
2
,
y
+
rectHeight
);
ctx
.
fillText
(
`
${
mm
}
mm`
,
_x
+
s
/
2
-
ts
.
width
/
2
,
_y
+
rectHeight
);
ctx
.
restore
();
}
}
}
}
...
...
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