<commit_before>var mouse        = require('mouse-position')()
var triangle     = require('a-big-triangle')
var throttle     = require('frame-debounce')
var fit          = require('canvas-fit')
var getContext   = require('gl-context')
var compare      = require('gl-compare')
var createAxes   = require('gl-axes')
var createFBO    = require('gl-fbo')
var glm          = require('gl-matrix')
var createBuffer = require('gl-buffer')
var createVAO    = require('gl-vao')
var createShader = require('glslify')
var fs           = require('fs')
var now          = require('right-now')
var mat4         = glm.mat4

var container  = document.getElementById('container')
var canvas     = container.appendChild(document.createElement('canvas'))
var readme     = fs.readFileSync(__dirname + '/README.md', 'utf8')
var gl         = getContext(canvas, render)
var comparison = compare(gl, actual, expected)
var verifyFBO  = createFBO(gl, [512,512])

var testVectors = [
  [0,1],
  [1,0],
  [-1,0],
  [0,-1],
  [0.25,0.3],
  [-1,-1],
  [1,2],
  [0.4,8]
]

//Draw 3 arrows, format = 
//  weights
//  offset
var buffer = []
for(var i=0; i<3; ++i) {
  var x = [1e-6,1e-6,1e-6]
  x[i] = 1
  buffer.push(1e-6,1e-6,1e-6,1e-6)
  buffer.push(x[0],x[1],x[2],1e-6)
  buffer.push(x[0],x[1],x[2],1e-6)
  buffer.push(x[0],x[1],x[2], 0.1)
  buffer.push(x[0],x[1],x[2],1e-6)
  buffer.push(x[0],x[1],x[2], -0.1)
}
var vao = createVAO(gl, [{
  "buffer": createBuffer(gl, buffer),
  "size": 4
}])

comparison.mode = 'slide'
comparison.amount = 0.5

require('../common')({
    description: readme
  , dirname: process.env.dirname
  , compare: comparison
  , canvas: canvas
  , test: verify
})

window.addEventListener('resize', fit(canvas), false)

var actualShader = createShader({
    frag: 'void main() { gl_FragColor = vec4(1, 1, 1, 1); }'
  , vert: '\
precision mediump float;\
attribute vec4 vertexData;\
uniform vec2 aVector;\
uniform vec2 bVector;\n\
#pragma glslify: func = require(' + process.env.file_vectors_glsl + ')\n\
void main() {\
  vec2 base = vertexData.x * aVector +\
              vertexData.y * bVector +\
              vertexData.z * func(aVector, bVector);\
  float baseLen = length(base);\
  float offsetScale = vertexData.w;\
  vec2 headShift = offsetScale * normalize(vec2(-base.y, base.x)) - abs(offsetScale) * normalize(base);\
  gl_Position = vec4(base + headShift, 0.0, 1.0);\
}'
  , inline: true
})(gl)

var expectedShader = createShader({
    frag: './shaders/fragment.glsl'
  , vert: './shaders/vertex.glsl'
})(gl)

var verifyShader = createShader({
    frag: [
  'precision highp float;',
  '#pragma glslify: actualFunc=require(' + process.env.file_vectors_glsl + ')',
  '#pragma glslify: expectedFunc=require(./shaders/expected.glsl)',
  'uniform vec2 bVector;',
  'varying vec2 aVector;',
  'void main() {',
    'vec2 actual = actualFunc(aVector, bVector);',
    'vec2 expected = expectedFunc(aVector, bVector);',
    'if(distance(actual, expected) > 0.01) {',
      'gl_FragColor = vec4(1,1,1,1);',
    '} else {',
      'gl_FragColor = vec4(0,0,0,0);',
    '}',
  '}'].join('\n')
  , vert: [
  'attribute vec2 position;',
  'varying vec2 aVector;',
  'void main() {',
    'gl_Position = vec4(position,0,1);',
    'aVector = position;',
  '}'].join('\n')
  , inline: true
})(gl)

var aVector = [0,0]
var bVector = [0,0]

function render() {

  var theta = 0.0001 * now()
  aVector[0] = 0.5 * Math.cos(theta)
  aVector[1] = 0.5 * Math.sin(theta)

  bVector[0] = 2.0 * (mouse.x / canvas.width) - 1.0
  bVector[1] = 1.0 - 2.0 * (mouse.y / canvas.height)
<commit_msg>Fix degenerate case area where A is pointing almost in opposite direction to B<commit_after>var mouse        = require('mouse-position')()
var triangle     = require('a-big-triangle')
var throttle     = require('frame-debounce')
var fit          = require('canvas-fit')
var getContext   = require('gl-context')
var compare      = require('gl-compare')
var createAxes   = require('gl-axes')
var createFBO    = require('gl-fbo')
var glm          = require('gl-matrix')
var createBuffer = require('gl-buffer')
var createVAO    = require('gl-vao')
var createShader = require('glslify')
var fs           = require('fs')
var now          = require('right-now')
var mat4         = glm.mat4

var container  = document.getElementById('container')
var canvas     = container.appendChild(document.createElement('canvas'))
var readme     = fs.readFileSync(__dirname + '/README.md', 'utf8')
var gl         = getContext(canvas, render)
var comparison = compare(gl, actual, expected)
var verifyFBO  = createFBO(gl, [512,512])

var testVectors = [
  [0,1],
  [1,0],
  [-1,0],
  [0,-1],
  [0.25,0.3],
  [-1,-1],
  [1,2],
  [0.4,8]
]

//Draw 3 arrows, format = 
//  weights
//  offset
var buffer = []
for(var i=0; i<3; ++i) {
  var x = [1e-6,1e-6,1e-6]
  x[i] = 1
  buffer.push(1e-6,1e-6,1e-6,1e-6)
  buffer.push(x[0],x[1],x[2],1e-6)
  buffer.push(x[0],x[1],x[2],1e-6)
  buffer.push(x[0],x[1],x[2], 0.1)
  buffer.push(x[0],x[1],x[2],1e-6)
  buffer.push(x[0],x[1],x[2], -0.1)
}
var vao = createVAO(gl, [{
  "buffer": createBuffer(gl, buffer),
  "size": 4
}])

comparison.mode = 'slide'
comparison.amount = 0.5

require('../common')({
    description: readme
  , dirname: process.env.dirname
  , compare: comparison
  , canvas: canvas
  , test: verify
})

window.addEventListener('resize', fit(canvas), false)

var actualShader = createShader({
    frag: 'void main() { gl_FragColor = vec4(1, 1, 1, 1); }'
  , vert: '\
precision mediump float;\
attribute vec4 vertexData;\
uniform vec2 aVector;\
uniform vec2 bVector;\n\
#pragma glslify: func = require(' + process.env.file_vectors_glsl + ')\n\
void main() {\
  vec2 base = vertexData.x * aVector +\
              vertexData.y * bVector +\
              vertexData.z * func(aVector, bVector);\
  float baseLen = length(base);\
  float offsetScale = vertexData.w;\
  vec2 headShift = offsetScale * normalize(vec2(-base.y, base.x)) - abs(offsetScale) * normalize(base);\
  gl_Position = vec4(base + headShift, 0.0, 1.0);\
}'
  , inline: true
})(gl)

var expectedShader = createShader({
    frag: './shaders/fragment.glsl'
  , vert: './shaders/vertex.glsl'
})(gl)

var verifyShader = createShader({
    frag: [
  'precision highp float;',
  '#pragma glslify: actualFunc=require(' + process.env.file_vectors_glsl + ')',
  '#pragma glslify: expectedFunc=require(./shaders/expected.glsl)',
  'uniform vec2 bVector;',
  'varying vec2 aVector;',
  'void main() {',
    'vec2 actual = actualFunc(aVector, bVector);',
    'vec2 expected = expectedFunc(aVector, bVector);',
    'if(distance(actual, expected) > 0.01 && distance(normalize(aVector), -normalize(bVector))>0.01) {',
      'gl_FragColor = vec4(1,1,1,1);',
    '} else {',
      'gl_FragColor = vec4(0,0,0,0);',
    '}',
  '}'].join('\n')
  , vert: [
  'attribute vec2 position;',
  'varying vec2 aVector;',
  'void main() {',
    'gl_Position = vec4(position,0,1);',
    'aVector = position;',
  '}'].join('\n')
  , inline: true
})(gl)

var aVector = [0,0]
var bVector = [0,0]

function render() {

  var theta = 0.0001 * now()
  aVector[0] = 0.5 * Math.cos(theta)
  aVector[1] = 0.5 * Math.sin(theta)

  bVector[0] = 2.0 * (mouse.x / canvas.width) - 1.0
  bVector[1] = 1.0 - 2.0 * (mouse.y / canvas.height)

{'fraction_non_alphanumeric': 0.19076498966230185, 'fraction_numerical': 0.03845623707787733, 'mean_word_length': 3.437920489296636, 'pattern_counts': {'":': 4, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6318220', 'n_tokens_mistral': 2864, 'n_tokens_neox': 2757, 'n_words': 583}