StackGenVis: Alignment of Data, Algorithms, and Models for Stacking Ensemble Learning Using Performance Metrics https://doi.org/10.1109/TVCG.2020.3030352
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
StackGenVis/frontend/node_modules/cdt2d/lib/triangulation.js

105 lines
2.1 KiB

4 years ago
'use strict'
var bsearch = require('binary-search-bounds')
module.exports = createTriangulation
function Triangulation(stars, edges) {
this.stars = stars
this.edges = edges
}
var proto = Triangulation.prototype
function removePair(list, j, k) {
for(var i=1, n=list.length; i<n; i+=2) {
if(list[i-1] === j && list[i] === k) {
list[i-1] = list[n-2]
list[i] = list[n-1]
list.length = n - 2
return
}
}
}
proto.isConstraint = (function() {
var e = [0,0]
function compareLex(a, b) {
return a[0] - b[0] || a[1] - b[1]
}
return function(i, j) {
e[0] = Math.min(i,j)
e[1] = Math.max(i,j)
return bsearch.eq(this.edges, e, compareLex) >= 0
}
})()
proto.removeTriangle = function(i, j, k) {
var stars = this.stars
removePair(stars[i], j, k)
removePair(stars[j], k, i)
removePair(stars[k], i, j)
}
proto.addTriangle = function(i, j, k) {
var stars = this.stars
stars[i].push(j, k)
stars[j].push(k, i)
stars[k].push(i, j)
}
proto.opposite = function(j, i) {
var list = this.stars[i]
for(var k=1, n=list.length; k<n; k+=2) {
if(list[k] === j) {
return list[k-1]
}
}
return -1
}
proto.flip = function(i, j) {
var a = this.opposite(i, j)
var b = this.opposite(j, i)
this.removeTriangle(i, j, a)
this.removeTriangle(j, i, b)
this.addTriangle(i, b, a)
this.addTriangle(j, a, b)
}
proto.edges = function() {
var stars = this.stars
var result = []
for(var i=0, n=stars.length; i<n; ++i) {
var list = stars[i]
for(var j=0, m=list.length; j<m; j+=2) {
result.push([list[j], list[j+1]])
}
}
return result
}
proto.cells = function() {
var stars = this.stars
var result = []
for(var i=0, n=stars.length; i<n; ++i) {
var list = stars[i]
for(var j=0, m=list.length; j<m; j+=2) {
var s = list[j]
var t = list[j+1]
if(i < Math.min(s, t)) {
result.push([i, s, t])
}
}
}
return result
}
function createTriangulation(numVerts, edges) {
var stars = new Array(numVerts)
for(var i=0; i<numVerts; ++i) {
stars[i] = []
}
return new Triangulation(stars, edges)
}