remove largely unused debug class

This commit is contained in:
Stewart Allen 2021-07-04 21:05:46 -04:00
commit 6337cae736
15 changed files with 30 additions and 281 deletions

View file

@ -1,219 +0,0 @@
/** Copyright 2014-2019 Stewart Allen -- All Rights Reserved */
"use strict";
(function() {
if (self.base.debug) return;
const base = self.base,
flags = {},
stash = [],
debug_colors = [0xff0000, 0x00ff00, 0x0000ff, 0x00ffff, 0xff00ff, 0xffff00];
let size = 20,
enabled = false,
next_debug_color = 0;
/** ******************************************************************
* Debug Functions
******************************************************************* */
function log(o) {
console.log(o);
if (enabled) {
stash.push(o);
while (stash.length > size) stash.shift();
}
}
function enable(history) {
enabled = true;
if (history) size = Math.abs(history);
}
function disable() {
enabled = false;
}
function on() {
return enabled;
}
function history() {
return stash;
}
function last() {
return stash[stash.length-1];
}
function trace(msg) {
if (msg && typeof msg != 'string') msg = JSON.stringify(msg);
log(new Error(msg).stack);
}
function view() {
return base.debug.view;
}
function setView(view) {
base.debug.view = view;
}
function get(f) {
return flags[f];
}
function set(f, value) {
if (Array.isArray(f)) {
for (let i=0; i<f.length; i++) flags[f[i]] = (value || 1);
} else {
flags[f] = (value || 1);
}
}
function clear(f) {
if (Array.isArray(f)) {
for (let i = 0; i < f.length; i++) delete flags[f[i]];
} else {
delete flags[f];
}
}
function test(isSet, isNotSet) {
let i;
if (isNotSet) {
if (Array.isArray(isNotSet)) {
for (i=0; i<isNotSet.length; i++) {
if (flags[isNotSet[i]]) return null;
}
} else {
if (flags[isNotSet]) return null;
}
}
if (isSet) {
if (Array.isArray(isSet)) {
for (i=0; i<isSet.length; i++) {
if (!flags[isSet[i]]) return null;
}
} else {
if (!flags[isSet]) return null;
}
}
return view() || true;
}
function nextDebugColor() {
return debug_colors[next_debug_color++ % debug_colors.length];
}
/**
* render point array as discrete points
*
* @param {Point[]} points
* @param {number} [color]
* @param {number} [opacity]
* @param {number} [size]
* @returns {THREE.PointCloud}
*/
function points(points, color, opacity, size) {
view().points(points, color, size);
}
/**
*
* @param {Point[]} points
* @param {number} color
* @returns {THREE.Line}
*/
function lines(points, color) {
view().lines(points, color);
}
/**
*
* @param {Polygon} poly
* @param {number} color
* @param {boolean} [recurse]
* @returns {THREE.Object}
*/
function polygon(poly, color, recurse) {
return poly.render(view(), color, recurse);
}
/**
* debug polygon
*
* @param {Polygon} poly
* @param {number} [z]
* @param {Layer} [v]
* @param {boolean} [deep]
* @param {boolean} [creep]
*/
function xray(poly, z, v, deep, creep) {
let colors = [
0xaa0000,
0x0,
0xaaaa00,
0x444444,
0x00ff00,
0x888888,
0x00aaaa,
0x0,
0x0000aa,
0x444444,
0xaa00aa,
0x888888
],
cidx = 0,
point,
next,
layer = v || view();
if (typeof(z) === 'number') poly.setZ(z);
poly.forEachPoint(function(next) {
if (!point) return next = point;
if (creep) next.z = (z = z + 0.1);
layer.lines([point.clone(), next.clone()], colors[cidx++ % colors.length]);
point = next;
});
layer.lines([poly.last().clone(), poly.first().clone()], 0xffffff);
layer.points(poly.points, 0x000000, 0.1);
layer.points([poly.first()], 0xffffff, 0.4);
layer.points([poly.last()], 0x555555, 0.45);
if (deep && poly.inner) {
poly.inner.forEach(function(p) { xray(p, z, v, false, creep) });
}
}
/** ******************************************************************
* Connect to base
******************************************************************* */
base.debug = {
on : on,
enable : enable,
disable : disable,
history : history,
last : last,
get : get,
set : set,
clear : clear,
log : log,
trace : trace,
test : test,
view : null,
setView : setView,
color : nextDebugColor,
xray : xray,
points : points,
lines : lines,
polygon : polygon,
slice : null, // todo temp
};
})();

View file

@ -13,20 +13,14 @@
ROUND = UTIL.round;
class Point {
constructor(x,y,z,key,CP) {
if (CP) {
console.trace({x,y,z,key,CP});
throw "deprecated point constructor"
} else {
this.x = x;
this.y = y;
this.z = z || 0;
if (key) {
this._key = key;
}
constructor(x,y,z,key) {
this.x = x;
this.y = y;
this.z = z || 0;
if (key) {
this._key = key;
}
this.poly = null; // parent polygon
this.pos = 0; // position in group
}
get key() {
@ -710,11 +704,10 @@
* @param {number} y
* @param {number} z
* @param {String} [key]
* @param {Object} [CP] clipper point
* @returns {Point}
*/
function newPoint(x, y, z, key, CP) {
return new Point(x, y, z, key, CP);
function newPoint(x, y, z, key) {
return new Point(x, y, z, key);
}
})();

View file

@ -4,9 +4,8 @@
(function() {
const BASE = self.base,
DBUG = BASE.debug,
CONF = BASE.config;
const BASE = self.base;
const CONF = BASE.config;
BASE.verticesToPoints = verticesToPoints;
BASE.pointsToVertices = pointsToVertices;
@ -104,7 +103,7 @@
// if (passes) console.trace({passes, threshold, precision, maxpass});
if (passes) DBUG.log({
if (passes) console.log({
before: array.length / 3,
after: parr.length,
unique: unique,

View file

@ -9,7 +9,6 @@
const BASE = self.base,
CONF = BASE.config,
UTIL = BASE.util,
DBUG = BASE.debug,
KEYS = BASE.key,
SQRT = Math.sqrt,
POLY = function() { return BASE.polygons },

View file

@ -745,9 +745,7 @@
while (i < polygons.length) {
let polygon = polygons[i++],
pp = polygon.points,
pl = pp.length,
dbug = BASE.debug,
debug = false;
pl = pp.length;;
for (let j = 0; j < pl; j++) {
let j2 = (j + 1) % pl,
ip = UTIL.intersectRayLine(start, slope, pp[j], pp[j2]);
@ -760,13 +758,9 @@
if (ip.isNear(pp[j], merge_dist)) {
ip.pos = j;
ip.mod = pl;
if (debug) dbug.points([ip], 0x0000ff, 0.5, 1.0);
} else if (ip.isNear(pp[j2], merge_dist)) {
ip.pos = j2;
ip.mod = pl;
if (debug) dbug.points([ip], 0x00ffff, 0.5, 0.85);
} else {
if (debug) dbug.points([ip], 0xff00ff, 0.5, 0.5);
}
}
}
@ -788,7 +782,7 @@
* was added later. see below for what else can happen.
*/
if (line.length < 2) {
dbug.log("sliceInt: line common ep fail: "+line.length);
console.log("sliceInt: line common ep fail: "+line.length);
} else
if (line.length > 2) {
p1.del = true;
@ -804,11 +798,9 @@
del = true;
p1.del = true;
p2.del = true;
if (debug) dbug.points([p1, p2], 0xffffff, 0.2, 1);
} else {
del = true;
p1.del = true;
if (debug) dbug.points([p1], 0xffff00, 0.2, 0.85);
}
}
return p1.dist - p2.dist; // sort on 'a' dist from ray origin
@ -839,7 +831,6 @@
// p1.del = true;
// p2.del = true;
// del = true;
// if (debug) dbug.points([p1, p2], 0xfff000, 0.2, 2);
//}
// check cull co-linear with group edge
if (same && p1.mod && p2.mod) {
@ -848,7 +839,6 @@
p1.del = true;
p2.del = true;
del = true;
if (debug) dbug.points([p1, p2], 0xffffff, 0.2, 1.85);
}
}
}