Skip to content

Commit da18ede

Browse files
author
saŭlo
committed
path2d test
1 parent c0acfeb commit da18ede

File tree

4 files changed

+45
-32
lines changed

4 files changed

+45
-32
lines changed

lib/js/tests/Webapi/Canvas/Webapi__Canvas__Canvas2d__test.js

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -160,20 +160,6 @@ ctx.strokeRect(1, 0, 10, 10);
160160

161161
ctx.clearRect(1, 0, 10, 10);
162162

163-
var path1 = new Path2D(undefined);
164-
165-
var path2 = new Path2D("M24.85,10.126c2.018-4.783,6.628-8.125,11.99-8.125c7.223,0,12.425,6.179,13.079,13.543 c0,0,0.353,1.828-0.424,5.119c-1.058,4.482-3.545,8.464-6.898,11.503L24.85,48L7.402,32.165c-3.353-3.038-5.84-7.021-6.898-11.503 c-0.777-3.291-0.424-5.119-0.424-5.119C0.734,8.179,5.936,2,13.159,2C18.522,2,22.832,5.343,24.85,10.126z");
166-
167-
path1.rect(1, 2, 10, 10);
168-
169-
path2.bezierCurveTo(1, 2, 2, 2, 4, 4);
170-
171-
ctx.beginPath();
172-
173-
ctx.stroke(path1);
174-
175-
ctx.fill(path2);
176-
177163
exports.canvasEl = canvasEl;
178164
exports.ctx = ctx;
179165
exports.pointInPath = pointInPath;
@@ -191,6 +177,4 @@ exports.imageFromData = imageFromData;
191177
exports.w = w;
192178
exports.h = h;
193179
exports.frameFromImage = frameFromImage;
194-
exports.path1 = path1;
195-
exports.path2 = path2;
196180
/* canvasEl Not a pure module */
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
'use strict';
2+
3+
4+
var path = new Path2D("M24.85,10.126c2.018-4.783,6.628-8.125,11.99-8.125c7.223,0,12.425,6.179,13.079,13.543 c0,0,0.353,1.828-0.424,5.119c-1.058,4.482-3.545,8.464-6.898,11.503L24.85,48L7.402,32.165c-3.353-3.038-5.84-7.021-6.898-11.503 c-0.777-3.291-0.424-5.119-0.424-5.119C0.734,8.179,5.936,2,13.159,2C18.522,2,22.832,5.343,24.85,10.126z");
5+
6+
path.moveTo(1, 1);
7+
8+
path.lineTo(1, 2);
9+
10+
path.rect(1, 2, 10, 10);
11+
12+
path.bezierCurveTo(1, 2, 2, 2, 4, 4);
13+
14+
var canvasEl = document.createElement("canvas");
15+
16+
var ctx = canvasEl.getContext("2d");
17+
18+
ctx.fill(path);
19+
20+
exports.path = path;
21+
exports.canvasEl = canvasEl;
22+
exports.ctx = ctx;
23+
/* path Not a pure module */

tests/Webapi/Canvas/Webapi__Canvas__Canvas2d__test.res

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -123,19 +123,3 @@ ctx->strokeText("hi", ~x=1., ~y=0., ())
123123
ctx->fillRect(~x=1., ~y=0., ~w=10., ~h=10.)
124124
ctx->strokeRect(~x=1., ~y=0., ~w=10., ~h=10.)
125125
ctx->clearRect(~x=1., ~y=0., ~w=10., ~h=10.)
126-
127-
let path1 = Path2d.make()
128-
let path2 = Path2d.make(
129-
~d="M24.85,10.126c2.018-4.783,6.628-8.125,11.99-8.125c7.223" ++
130-
",0,12.425,6.179,13.079,13.543 c0,0,0.353,1.828-0.424,5.119c-1.058,4.482" ++
131-
"-3.545,8.464-6.898,11.503L24.85,48L7.402,32.165c-3.353-3.038-5.84-7.021" ++
132-
"-6.898-11.503 c-0.777-3.291-0.424-5.119-0.424-5.119C0.734,8.179,5.936,2" ++ ",13.159,2C18.522,2,22.832,5.343,24.85,10.126z",
133-
(),
134-
)
135-
136-
path1->Path2d.rect(~x=1., ~y=2., ~w=10., ~h=10.)
137-
path2->Path2d.bezierCurveTo(~cp1x=1., ~cp1y=2., ~cp2x=2., ~cp2y=2., ~x=4., ~y=4.)
138-
139-
ctx->beginPath
140-
ctx->strokePath2d(path1)
141-
ctx->fillPath2d(path2)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
open Webapi.Canvas
2+
open Webapi.Canvas.Canvas2d
3+
open Webapi.Dom
4+
5+
let path = Path2d.make(
6+
~d="M24.85,10.126c2.018-4.783,6.628-8.125,11.99-8.125c7.223" ++
7+
",0,12.425,6.179,13.079,13.543 c0,0,0.353,1.828-0.424,5.119c-1.058,4.482" ++
8+
"-3.545,8.464-6.898,11.503L24.85,48L7.402,32.165c-3.353-3.038-5.84-7.021" ++
9+
"-6.898-11.503 c-0.777-3.291-0.424-5.119-0.424-5.119C0.734,8.179,5.936,2" ++ ",13.159,2C18.522,2,22.832,5.343,24.85,10.126z",
10+
(),
11+
)
12+
13+
path->Path2d.moveTo(~x=1., ~y=1.)
14+
path->Path2d.lineTo(~x=1., ~y=2.)
15+
path->Path2d.rect(~x=1., ~y=2., ~w=10., ~h=10.)
16+
path->Path2d.bezierCurveTo(~cp1x=1., ~cp1y=2., ~cp2x=2., ~cp2y=2., ~x=4., ~y=4.)
17+
18+
19+
let canvasEl: Dom.element = document->Document.createElement("canvas")
20+
let ctx = canvasEl->CanvasElement.getContext2d
21+
22+
ctx->fillPath2d(path)

0 commit comments

Comments
 (0)