Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
drawing-app
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
sweng-group-15
drawing-app
Commits
61c598f4
Commit
61c598f4
authored
5 years ago
by
Yuriy Maksymets
Browse files
Options
Downloads
Patches
Plain Diff
Fixed parameters, added more test cases
parent
71143871
Branches
Branches containing commit
No related tags found
1 merge request
!65
Simple shape recognition
Pipeline
#106097
failed
5 years ago
Stage: fetch
Stage: deps
Stage: check
Stage: build
Stage: test
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
__tests__/shape.test.js
+361
-1
361 additions, 1 deletion
__tests__/shape.test.js
src/shapes.js
+1
-1
1 addition, 1 deletion
src/shapes.js
src/tool-selection.js
+1
-1
1 addition, 1 deletion
src/tool-selection.js
with
363 additions
and
3 deletions
__tests__/shape.test.js
+
361
−
1
View file @
61c598f4
...
@@ -194,6 +194,136 @@ describe("shape recognition", () => {
...
@@ -194,6 +194,136 @@ describe("shape recognition", () => {
expect
(
result
.
shape
).
toBe
(
Shapes
.
line
)
expect
(
result
.
shape
).
toBe
(
Shapes
.
line
)
expect
(
result
.
angle
).
toBeGreaterThan
(
12
)
expect
(
result
.
angle
).
toBeGreaterThan
(
12
)
})
})
test
(
"
should recognize line 1
"
,
()
=>
{
const
points
=
[
[
380
,
355
],
[
380
,
356
],
[
381
,
355
],
[
383
,
354
],
[
386
,
352
],
[
391
,
349
],
[
395
,
346
],
[
400
,
343
],
[
405
,
339
],
[
411
,
335
],
[
416
,
332
],
[
425
,
325
],
[
433
,
318
],
[
440
,
312
],
[
447
,
306
],
[
454
,
300
],
[
462
,
293
],
[
471
,
283
],
[
479
,
274
],
[
487
,
266
],
[
498
,
255
],
[
509
,
244
],
[
520
,
235
],
[
531
,
226
],
[
539
,
218
],
[
543
,
215
],
[
550
,
208
],
[
558
,
203
],
[
563
,
199
],
[
567
,
196
],
[
571
,
193
],
[
575
,
190
],
[
577
,
189
],
[
578
,
188
],
[
579
,
187
],
[
580
,
187
],
[
580
,
187
],
[
581
,
187
],
[
581
,
186
],
]
const
result
=
recognizeFromPoints
(
points
)
expect
(
result
.
shape
).
toBe
(
Shapes
.
line
)
})
test
(
"
should recognize line 2
"
,
()
=>
{
const
points
=
[
[
648
,
509
],
[
648
,
509
],
[
648
,
509
],
[
646
,
509
],
[
641
,
509
],
[
634
,
509
],
[
628
,
509
],
[
608
,
509
],
[
591
,
509
],
[
571
,
509
],
[
554
,
509
],
[
534
,
509
],
[
513
,
505
],
[
486
,
499
],
[
462
,
495
],
[
454
,
494
],
[
433
,
490
],
[
413
,
488
],
[
396
,
485
],
[
382
,
485
],
[
368
,
482
],
[
360
,
482
],
[
356
,
482
],
[
348
,
479
],
[
341
,
479
],
[
336
,
478
],
[
331
,
478
],
[
329
,
478
],
[
327
,
477
],
[
326
,
476
],
[
326
,
476
],
[
325
,
476
],
[
325
,
476
],
[
325
,
476
],
[
325
,
476
],
[
323
,
476
],
[
322
,
476
],
[
320
,
476
],
[
319
,
476
],
[
318
,
476
],
[
316
,
476
],
[
315
,
475
],
[
315
,
475
],
[
314
,
475
],
[
314
,
475
],
[
313
,
475
],
]
const
result
=
recognizeFromPoints
(
points
)
expect
(
result
.
shape
).
toBe
(
Shapes
.
line
)
})
test
(
"
should recognize line 3
"
,
()
=>
{
const
points
=
[
[
204
,
590
],
[
205
,
590
],
[
208
,
584
],
[
219
,
574
],
[
254
,
534
],
[
276
,
500
],
[
305
,
456
],
[
334
,
410
],
[
346
,
388
],
[
376
,
336
],
[
404
,
284
],
[
430
,
238
],
[
454
,
197
],
[
458
,
190
],
[
474
,
160
],
[
483
,
142
],
[
485
,
138
],
[
492
,
126
],
[
495
,
121
],
[
498
,
117
],
[
499
,
115
],
[
500
,
114
],
[
500
,
114
],
[
500
,
113
],
]
const
result
=
recognizeFromPoints
(
points
)
expect
(
result
.
shape
).
toBe
(
Shapes
.
line
)
})
})
})
describe
(
"
rectangles
"
,
()
=>
{
describe
(
"
rectangles
"
,
()
=>
{
...
@@ -250,7 +380,237 @@ describe("shape recognition", () => {
...
@@ -250,7 +380,237 @@ describe("shape recognition", () => {
})
})
test
(
"
should recognize half-closed rectangle
"
,
()
=>
{
test
(
"
should recognize half-closed rectangle
"
,
()
=>
{
const
points
=
[[
-
10
,
-
10
],
[
10
,
-
10
],
[
10
,
10
],
[
-
1
,
-
9
]]
const
points
=
[
[
380
,
503
],
[
379
,
503
],
[
379
,
503
],
[
379
,
498
],
[
379
,
491
],
[
379
,
471
],
[
379
,
468
],
[
379
,
457
],
[
379
,
440
],
[
379
,
428
],
[
379
,
412
],
[
379
,
398
],
[
379
,
384
],
[
379
,
373
],
[
379
,
369
],
[
379
,
361
],
[
379
,
354
],
[
379
,
349
],
[
379
,
346
],
[
379
,
344
],
[
379
,
343
],
[
379
,
342
],
[
379
,
341
],
[
381
,
340
],
[
385
,
340
],
[
389
,
340
],
[
398
,
340
],
[
407
,
340
],
[
418
,
340
],
[
429
,
340
],
[
440
,
340
],
[
451
,
340
],
[
463
,
340
],
[
476
,
342
],
[
488
,
343
],
[
502
,
345
],
[
515
,
348
],
[
520
,
349
],
[
531
,
350
],
[
540
,
351
],
[
549
,
352
],
[
552
,
353
],
[
557
,
354
],
[
558
,
355
],
[
560
,
355
],
[
560
,
355
],
[
560
,
355
],
[
561
,
355
],
[
561
,
356
],
[
561
,
356
],
[
561
,
356
],
[
561
,
357
],
[
561
,
360
],
[
561
,
363
],
[
561
,
368
],
[
561
,
377
],
[
561
,
388
],
[
561
,
399
],
[
561
,
406
],
[
561
,
414
],
[
561
,
423
],
[
561
,
432
],
[
561
,
441
],
[
561
,
447
],
[
561
,
452
],
[
561
,
459
],
[
561
,
463
],
[
561
,
468
],
[
561
,
471
],
[
561
,
475
],
[
561
,
478
],
[
561
,
479
],
[
561
,
480
],
[
561
,
480
],
[
561
,
481
],
[
561
,
482
],
[
561
,
482
],
[
561
,
483
],
[
560
,
483
],
[
560
,
483
],
[
558
,
484
],
[
556
,
485
],
[
551
,
487
],
[
546
,
488
],
[
540
,
490
],
[
533
,
492
],
[
522
,
493
],
[
513
,
494
],
[
502
,
496
],
[
491
,
497
],
[
480
,
497
],
[
466
,
499
],
[
452
,
500
],
[
447
,
500
],
[
436
,
500
],
[
427
,
501
],
[
418
,
501
],
[
412
,
503
],
[
407
,
503
],
[
402
,
504
],
[
400
,
504
],
[
398
,
504
],
[
398
,
504
],
[
397
,
504
],
[
396
,
504
],
]
const
result
=
recognizeFromPoints
(
points
)
expect
(
result
.
shape
).
toBe
(
Shapes
.
rectangle
)
})
test
(
"
should recognize half-closed rectangle 2
"
,
()
=>
{
const
points
=
[
[
294
,
477
],
[
293
,
477
],
[
293
,
477
],
[
293
,
473
],
[
293
,
469
],
[
293
,
465
],
[
293
,
459
],
[
293
,
455
],
[
293
,
451
],
[
293
,
444
],
[
293
,
437
],
[
293
,
431
],
[
293
,
423
],
[
293
,
414
],
[
293
,
403
],
[
293
,
394
],
[
293
,
391
],
[
293
,
384
],
[
293
,
379
],
[
293
,
376
],
[
293
,
373
],
[
293
,
372
],
[
293
,
371
],
[
293
,
370
],
[
293
,
370
],
[
293
,
369
],
[
294
,
369
],
[
295
,
368
],
[
298
,
368
],
[
303
,
367
],
[
308
,
366
],
[
317
,
364
],
[
328
,
362
],
[
341
,
360
],
[
358
,
357
],
[
375
,
355
],
[
392
,
352
],
[
412
,
350
],
[
436
,
348
],
[
457
,
346
],
[
480
,
344
],
[
501
,
342
],
[
518
,
342
],
[
535
,
340
],
[
539
,
339
],
[
551
,
339
],
[
559
,
338
],
[
568
,
337
],
[
573
,
337
],
[
576
,
337
],
[
578
,
337
],
[
579
,
337
],
[
579
,
337
],
[
580
,
337
],
[
580
,
337
],
[
581
,
337
],
[
581
,
338
],
[
581
,
341
],
[
581
,
346
],
[
581
,
349
],
[
581
,
358
],
[
579
,
366
],
[
578
,
373
],
[
576
,
382
],
[
575
,
386
],
[
571
,
403
],
[
571
,
407
],
[
568
,
420
],
[
567
,
424
],
[
565
,
430
],
[
562
,
437
],
[
561
,
442
],
[
559
,
447
],
[
558
,
450
],
[
557
,
452
],
[
556
,
454
],
[
556
,
456
],
[
555
,
458
],
[
555
,
459
],
[
554
,
460
],
[
554
,
461
],
[
553
,
462
],
[
553
,
462
],
[
553
,
463
],
[
552
,
463
],
[
552
,
463
],
[
552
,
464
],
[
552
,
464
],
[
551
,
464
],
[
550
,
465
],
[
549
,
465
],
[
544
,
466
],
[
541
,
467
],
[
534
,
468
],
[
527
,
469
],
[
521
,
470
],
[
512
,
472
],
[
509
,
472
],
[
500
,
474
],
[
493
,
475
],
[
485
,
476
],
[
478
,
477
],
[
471
,
478
],
[
465
,
479
],
[
460
,
480
],
[
454
,
481
],
[
450
,
482
],
[
446
,
483
],
[
442
,
483
],
[
439
,
483
],
[
437
,
484
],
[
436
,
484
],
[
435
,
484
],
[
434
,
484
],
[
433
,
484
],
[
433
,
484
],
[
433
,
484
],
]
const
result
=
recognizeFromPoints
(
points
)
const
result
=
recognizeFromPoints
(
points
)
expect
(
result
.
shape
).
toBe
(
Shapes
.
rectangle
)
expect
(
result
.
shape
).
toBe
(
Shapes
.
rectangle
)
})
})
...
...
This diff is collapsed.
Click to expand it.
src/shapes.js
+
1
−
1
View file @
61c598f4
...
@@ -85,7 +85,7 @@ function angleBetweenVectors(p1, p2) {
...
@@ -85,7 +85,7 @@ function angleBetweenVectors(p1, p2) {
}
}
const
LINE_ANGLE_THRESHOLD
=
Math
.
PI
/
6
const
LINE_ANGLE_THRESHOLD
=
Math
.
PI
/
6
const
VECTOR_LEN_THRESHOLD_FRACTION
=
0.
15
const
VECTOR_LEN_THRESHOLD_FRACTION
=
0.
3
function
couldBeLine
(
points
)
{
function
couldBeLine
(
points
)
{
if
(
points
.
length
<
2
)
return
false
if
(
points
.
length
<
2
)
return
false
...
...
This diff is collapsed.
Click to expand it.
src/tool-selection.js
+
1
−
1
View file @
61c598f4
...
@@ -8,7 +8,7 @@ export const Tools = Object.freeze({
...
@@ -8,7 +8,7 @@ export const Tools = Object.freeze({
let
tool
=
Tools
.
PEN
let
tool
=
Tools
.
PEN
let
strokeColour
=
"
#0000ff
"
let
strokeColour
=
"
#0000ff
"
let
strokeRadius
=
5
let
strokeRadius
=
5
let
recognitionEnabled
=
1
//
false
let
recognitionEnabled
=
false
// TODO: The erase radius should also be selectable.
// TODO: The erase radius should also be selectable.
const
ERASE_RADIUS
=
20
const
ERASE_RADIUS
=
20
...
...
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