1 /* Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 * Use of this source code is governed by a BSD-style license that can be
3 * found in the LICENSE file.
7 base
.requireRawScript('../third_party/gl-matrix/src/gl-matrix/common.js');
8 base
.requireRawScript('../third_party/gl-matrix/src/gl-matrix/mat2d.js');
9 base
.requireRawScript('../third_party/gl-matrix/src/gl-matrix/vec2.js');
11 base
.exportTo('base', function() {
12 var tmp_vec2
= vec2
.create();
13 var tmp_mat2d
= mat2d
.create();
15 vec2
.createXY = function(x
, y
) {
16 var v
= vec2
.create();
21 vec2
.asPoint = function(v
) {
26 mat2d
.translateInplace = function(inout
, v
) {
27 mat2d
.translate(tmp_mat2d
, inout
, v
);
28 mat2d
.copy(inout
, tmp_mat2d
);
31 mat2d
.translateInplaceXY = function(inout
, x
, y
) {
32 vec2
.set(tmp_vec2
, x
, y
);
33 mat2d
.translateInplace(inout
, tmp_vec2
);
36 mat2d
.scaleInplace = function(inout
, v
) {
37 mat2d
.scale(tmp_mat2d
, inout
, v
);
38 mat2d
.copy(inout
, tmp_mat2d
);
41 mat2d
.scaleInplaceXY = function(inout
, x
, y
) {
42 vec2
.set(tmp_vec2
, x
, y
);
43 mat2d
.scaleInplace(inout
, tmp_vec2
);
46 mat2d
.rotateInplace = function(inout
, rad
) {
47 mat2d
.rotate(tmp_mat2d
, inout
, rad
);
48 mat2d
.copy(inout
, tmp_mat2d
);
51 function signPt(p1
, p2
, p3
)
53 return (p1
.x
- p3
.x
) * (p2
.y
- p3
.y
) - (p2
.x
- p3
.x
) * (p1
.y
- p3
.y
);
56 function pointInTriangle2Pt(pt
, p1
, p2
, p3
)
58 var b1
= signPt(pt
, p1
, p2
) < 0.0;
59 var b2
= signPt(pt
, p2
, p3
) < 0.0;
60 var b3
= signPt(pt
, p3
, p1
) < 0.0;
61 return ((b1
== b2
) && (b2
== b3
));
64 function pointInQuad2Pt(pt
, q
)
66 return pointInTriangle2Pt(pt
, q
.p1
, q
.p2
, q
.p3
) ||
67 pointInTriangle2Pt(pt
, q
.p1
, q
.p3
, q
.p4
);
71 pointInTriangle2Pt
: pointInTriangle2Pt
,
72 pointInQuad2Pt
: pointInQuad2Pt