How to append click event to handsontable row/column header? - events

I'm trying to implement some features like excel to click row/column header to select entire row/column, I think I should append a click event to all row/column header, so I tried add code below in core.js, but it was never been trigged:
this.click = function() {
alert("Clicked!");
};
So where should I begin with?
Thanks for any help.

Implemented by myself based on Handsontable 0.9.9:
From 5e2e8f51374741432d34624eb86edce6a802bf80 Mon Sep 17 00:00:00 2001
From: Xinfeng Li <xinfli#gmail.com>
Date: Wed, 17 Jul 2013 12:04:21 +0800
Subject: [PATCH 1/1] Implement select entire row/column when click on
row/column header.
---
src/3rdparty/walkontable/src/event.js | 5 ++++
src/3rdparty/walkontable/src/settings.js | 3 +-
src/pluginHooks.js | 3 ++
src/tableView.js | 50 ++++++++++++++++++++++++++++++++
4 files changed, 60 insertions(+), 1 deletion(-)
diff --git a/src/3rdparty/walkontable/src/event.js b/src/3rdparty/walkontable/src/event.js
index e150fef..a4cbb09 100644
--- a/src/3rdparty/walkontable/src/event.js
+++ b/src/3rdparty/walkontable/src/event.js
## -17,6 +17,11 ## function WalkontableEvent(instance) {
that.instance.getSetting('onCellMouseDown', event, cell.coords, cell.TD);
}
}
+ else if (cell.TD && cell.TD.nodeName === 'TH') {
+ if (that.instance.hasSetting('onHeaderMouseDown')) {
+ that.instance.getSetting('onHeaderMouseDown', event, cell.coords, cell.TD);
+ }
+ }
else if (that.wtDom.hasClass(event.target, 'corner')) {
that.instance.getSetting('onCellCornerMouseDown', event, event.target);
}
diff --git a/src/3rdparty/walkontable/src/settings.js b/src/3rdparty/walkontable/src/settings.js
index 35eb736..b16e4cf 100644
--- a/src/3rdparty/walkontable/src/settings.js
+++ b/src/3rdparty/walkontable/src/settings.js
## -41,8 +41,9 ## function WalkontableSettings(instance, settings) {
//callbacks
onCellMouseDown: null,
+ onHeaderMouseDown: null,
onCellMouseOver: null,
-// onCellMouseOut: null,
+ //onCellMouseOut: null,
onCellDblClick: null,
onCellCornerMouseDown: null,
onCellCornerDblClick: null,
diff --git a/src/pluginHooks.js b/src/pluginHooks.js
index afcc7e2..ececdd1 100644
--- a/src/pluginHooks.js
+++ b/src/pluginHooks.js
## -37,6 +37,9 ## Handsontable.PluginHookClass = (function () {
afterSelectionEndByProp : [],
afterCopyLimit : [],
+ // Customer plugin after row/column header clicked.
+ afterHeaderClick : [],
+
// Modifiers
modifyCol : []
}
diff --git a/src/tableView.js b/src/tableView.js
index 39512c0..ded6b74 100644
--- a/src/tableView.js
+++ b/src/tableView.js
## -242,6 +242,56 ## Handsontable.TableView = function (instance) {
that.settings.afterOnCellMouseDown.call(instance, event, coords, TD);
}
},
+ onHeaderMouseDown: function (event, coords, TD) {
+ var row = coords[0];
+ var col = coords[1];
+ var rangeRowStart, rangeColStart, rangeRowEnd, rangeColEnd;
+
+ //console.log("Clicked on header[row = " + row + ", col = " + col + "], TD.innerHTML.length: " + TD.innerHTML.length);
+ if ((row == 0) && (col == -1) && (TD.innerHTML.length == 0)) {
+ // Click on left upper corner
+ // Since the row and col is same when click on left upper corner and row heder of first row,
+ // The length of current TD.innerHTML must be checked.
+ rangeRowStart = 0;
+ rangeColStart = 0;
+ rangeRowEnd = instance.countRows() - 1;
+ rangeColEnd = instance.countCols() - 1;
+ }
+ else if (row == 0) {
+ if (col >= 0) {
+ // Click on column header
+ rangeRowStart = 0;
+ rangeColStart = col;
+ rangeRowEnd = instance.countRows() - 1;
+ rangeColEnd = col;
+ } else {
+ // Click on row header of first row
+ rangeRowStart = row;
+ rangeColStart = 0;
+ rangeRowEnd = row;
+ rangeColEnd = instance.countCols() - 1;
+ }
+ }
+ else if (col == -1) {
+ // Click on row header
+ rangeRowStart = row;
+ rangeColStart = 0;
+ rangeRowEnd = row;
+ rangeColEnd = instance.countCols() - 1;
+ }
+
+ if ((rangeRowStart != undefined) && (rangeColStart != undefined) && (rangeRowEnd != undefined) && (rangeColEnd != undefined)) {
+ //console.log("Select from [" + rangeRowStart + ", " + rangeColStart + "] to [" + rangeRowEnd + ", " + rangeColEnd + "]");
+ instance.selectCell(rangeRowStart, rangeColStart, rangeRowEnd, rangeColEnd);
+ }
+
+ if (!that.settings.fragmentSelection) {
+ event.preventDefault(); //disable text selection in Chrome
+ clearTextSelection();
+ }
+
+ instance.PluginHooks.run('afterHeaderClick', event, coords, TD);
+ },
/*onCellMouseOut: function (/*event, coords, TD* /) {
if (isMouseDown && that.settings.fragmentSelection === 'single') {
clearTextSelection(); //otherwise text selection blinks during multiple cells selection
--
1.8.1.msysgit.1

Related

How to add Alert on buy sell arrow

How to add Alert on Buy_Signal & Sell_Signal arrow, I added below code but getting wrong signals. Can anyone help me out with it. Thanks
if (((TriggerCandle > 0) && (time[rates_total - 1] > LastAlertTime)) || (TriggerCandle == 0))
{
string Text;
// Up Arrow Alert
if ((Buy_Signal[rates_total - 1 - TriggerCandle] > 0) && ((TriggerCandle > 0) || ((TriggerCandle == 0) && (LastAlertDirection != 1))))
{
Text = AlertText + "Alpha Buy: " + Symbol() + " - " + EnumToString(Period()) + " - Up.";
if (EnableNativeAlerts) Alert(Text);
if (EnableEmailAlerts) SendMail(AlertEmailSubject + "Alpha Buy", Text);
if (EnableSoundAlerts) PlaySound(SoundFileName);
if (EnablePushAlerts) SendNotification(Text);
LastAlertTime = time[rates_total - 1];
LastAlertDirection = 1;
}
// Down Arrow Alert
if ((Sell_Signal[rates_total - 1 - TriggerCandle] > 0) && ((TriggerCandle > 0) || ((TriggerCandle == 0) && (LastAlertDirection != -1))))
{
Text = AlertText + "Alpha Sell: " + Symbol() + " - " + EnumToString(Period()) + " - Down.";
if (EnableNativeAlerts) Alert(Text);
if (EnableEmailAlerts) SendMail(AlertEmailSubject + "Alpha Sell", Text);
if (EnableSoundAlerts) PlaySound(SoundFileName);
if (EnablePushAlerts) SendNotification(Text);
LastAlertTime = time[rates_total - 1];
LastAlertDirection = -1;
}
}
//--- return value of prev_calculated for next call
return(rates_total);
}

When creating an angle, how do I control the attributes of the automatically created points?

I'm working with a polygon and attempting to create angles with labels but when angles are created, so are the points used to define them. This would be fine but I can't control the labels on the automatically created points (and I don't know what they are called or how to find out).
var points = [
[0, 0],
[0, 5],
[3, 0]
];
for (k = 0; k < showAngle.length; k++) {
if (showAngle[k] == 1) {
var angle = board.create('angle', [points[k], points[((k + 1) % points.length)], points[((k + 2) % points.length)]],{fixed:true});
} else if (showAngle[k] == 2) {
var angle = board.create('angle', [points[k], points[((k + 1) % points.length)], points[((k + 2) % points.length)]], {
fixed: false,
name: function() {
return ((180/Math.PI)*JXG.Math.Geometry.rad(points[k], points[((k + 1) % points.length)], points[((k + 2) % points.length)])).toFixed(1) + '°';
}
});
}
}
https://jsfiddle.net/jscottuq/acyrLxfh/12/ contains what I've got so far.
The arrays showLen and showAngle are setting what labels are shown for each side/angle (0 - no label, 1 - name , 2 - measurement).
These will be set when the jsxgraph is created.
At the time being, the possibility to control the style of the newly created points of an angle is missing. We will add this soon.
However, a solution would be to use the already existing points which are hidden in this example. For this it would be helpful to kee a list of these points, e.g. jxg_points:
var jxg_points = [];
for (i = 0; i < points.length; i++) {
var rise = points[(i + 1) % points.length][1] - points[i][1];
var run = points[(i + 1) % points.length][0] - points[i][0];
var point = board.create('point', [points[i][0], points[i][1]], {
fixed: true,
visible:false
});
jxg_points.push(point); // Store the point
points[i].pop();
len[i] = Math.round((Math.sqrt(rise * rise + run * run) + Number.EPSILON) * 100) / 100;
}
Then the points can be reused for the angles without creating new points:
for (k = 0; k < showAngle.length; k++) {
if (showAngle[k] == 1) {
angle = board.create('angle', [
jxg_points[k],
jxg_points[((k + 1) % jxg_points.length)],
jxg_points[((k + 2) % jxg_points.length)]
],{fixed:true});
} else if (showAngle[k] == 2) {
var angle = board.create('angle', [
jxg_points[k],
jxg_points[((k + 1) % jxg_points.length)],
jxg_points[((k + 2) % jxg_points.length)]], {
fixed: false,
name: function() {
return ((180/Math.PI)*JXG.Math.Geometry.rad(points[k], points[((k + 1) % points.length)], points[((k + 2) % points.length)])).toFixed(1) + '°';
}
});
}
}
See it live at https://jsfiddle.net/d8an0epy/.

Qt 5.13 Oracle OCI Result cannot bind to return a SYS_REFCURSOR

I recently built Qt 5.13 statically, along with qsqloci plugin and it came out pretty well. One of the issues I have been working around is how to return a SYS_REFCURSOR object from Oracle base to a QSqlResult or something similar. I found a patch https://bugreports.qt.io/browse/QTBUG-166
I have tried the exact same thing, but somehow, it managed to print out:
ORA-01008: not all variables bound
Unable to execute statement.
I have a crystal clear connection to database and I can execute other statements, as well, not a problem. The only problem is how to return a SYS_REFCURSOR.
Thank you.
Q_DECLARE_METATYPE(QOCIResult *)
QOCIResult *p_cursor = reinterpret_cast<QOCIResult*>(db.driver()->createResult());
QSqlQuery content_query(db);
content_query.prepare("begin ispovedi.get_ord_kategorii_list(:p_cursor); end;");
content_query.addBindValue(qVariantFromValue(p_cursor), QSql::Out);
if (content_query.exec())
{
p_cursor->exec();
}
else
{
qCritical("%s.", qPrintable(content_query.lastError().text()));
}
I try to migrate the patch https://bugreports.qt.io/browse/QTBUG-166 to Qt 5.7 yesterday, and it seems to work, here is my patch:
--- qsql_oci.cpp.orig Thu Aug 29 05:18:48 2019
+++ qsql_oci.cpp Thu Aug 29 11:53:44 2019
## -82,6 +82,9 ##
//#define QOCI_DEBUG
+Q_DECLARE_METATYPE(QSqlResult *)
+
+
Q_DECLARE_OPAQUE_POINTER(OCIEnv*);
Q_DECLARE_METATYPE(OCIEnv*)
Q_DECLARE_OPAQUE_POINTER(OCIStmt*);
## -206,6 +209,8 ##
QVariant lastInsertId() const Q_DECL_OVERRIDE;
bool execBatch(bool arrayBind = false) Q_DECL_OVERRIDE;
void virtual_hook(int id, void *data) Q_DECL_OVERRIDE;
+ bool isCursor;
+ bool internal_prepare();
};
class QOCIResultPrivate: public QSqlCachedResultPrivate
## -389,6 +394,18 ##
const_cast<OCIRowid **>(&rptr->id),
-1,
SQLT_RDD, indPtr, 0, 0, 0, 0, OCI_DEFAULT);
+ } else if (val.canConvert<QSqlResult *>() && isOutValue(pos)) {
+ QOCIResult *res = (QOCIResult *)qvariant_cast<QSqlResult *>(val);
+
+ if (res->internal_prepare()) {
+ r = OCIBindByPos(sql, hbnd, err,
+ pos + 1,
+ const_cast<OCIStmt **>(&res->d_func()->sql),
+ (sb4)0,
+ SQLT_RSET, indPtr, 0, 0, 0, 0, OCI_DEFAULT);
+
+ res->isCursor = true;
+ }
} else {
qWarning("Unknown bind variable");
r = OCI_ERROR;
## -1833,6 +1850,7 ##
QOCIResult::QOCIResult(const QOCIDriver *db)
: QSqlCachedResult(*new QOCIResultPrivate(this, db))
{
+ isCursor = false;
}
QOCIResult::~QOCIResult()
## -1931,13 +1949,15 ##
return rowCount;
}
-bool QOCIResult::prepare(const QString& query)
-{
+bool QOCIResult::internal_prepare() {
Q_D(QOCIResult);
int r = 0;
- QSqlResult::prepare(query);
+ QString noStr;
+ QSqlResult::prepare(noStr);
- delete d->cols;
+ if (d->cols)
+ delete d->cols;
+
d->cols = 0;
QSqlCachedResult::cleanup();
## -1946,20 +1966,36 ##
if (r != OCI_SUCCESS)
qOraWarning("QOCIResult::prepare: unable to free statement handle:", d->err);
}
- if (query.isEmpty())
- return false;
+
r = OCIHandleAlloc(d->env,
reinterpret_cast<void **>(&d->sql),
OCI_HTYPE_STMT,
0,
0);
+
if (r != OCI_SUCCESS) {
qOraWarning("QOCIResult::prepare: unable to alloc statement:", d->err);
setLastError(qMakeError(QCoreApplication::translate("QOCIResult",
"Unable to alloc statement"), QSqlError::StatementError, d->err));
return false;
}
+
d->setStatementAttributes();
+
+ return true;
+}
+
+bool QOCIResult::prepare(const QString& query)
+{
+ Q_D(QOCIResult);
+
+ if (query.isEmpty())
+ return false;
+
+ if (!internal_prepare())
+ return false;
+
+ int r = 0;
const OraText *txt = reinterpret_cast<const OraText *>(query.utf16());
const int len = query.length() * sizeof(QChar);
r = OCIStmtPrepare(d->sql,
## -2020,23 +2056,26 ##
return false;
}
- // execute
- r = OCIStmtExecute(d->svc,
- d->sql,
- d->err,
- iters,
- 0,
- 0,
- 0,
- mode);
- if (r != OCI_SUCCESS && r != OCI_SUCCESS_WITH_INFO) {
- qOraWarning("QOCIResult::exec: unable to execute statement:", d->err);
- setLastError(qMakeError(QCoreApplication::translate("QOCIResult",
- "Unable to execute statement"), QSqlError::StatementError, d->err));
-#ifdef QOCI_DEBUG
- qDebug() << "lastQuery()" << lastQuery();
-#endif
- return false;
+ if (!isCursor)
+ {
+ // execute
+ r = OCIStmtExecute(d->svc,
+ d->sql,
+ d->err,
+ iters,
+ 0,
+ 0,
+ 0,
+ mode);
+ if (r != OCI_SUCCESS && r != OCI_SUCCESS_WITH_INFO) {
+ qOraWarning("QOCIResult::exec: unable to execute statement:", d->err);
+ setLastError(qMakeError(QCoreApplication::translate("QOCIResult",
+ "Unable to execute statement"), QSqlError::StatementError, d->err));
+ #ifdef QOCI_DEBUG
+ qDebug() << "lastQuery()" << lastQuery();
+ #endif
+ return false;
+ }
}
if (stmtType == OCI_STMT_SELECT) {
Modify your code as follows and have a try:
Q_DECLARE_METATYPE(QSqlResult *)
QSqlResult *p_cursor = db.driver()->createResult();
QSqlQuery content_query(db);
content_query.prepare("begin ispovedi.get_ord_kategorii_list(:p_cursor); end;");
content_query.addBindValue(qVariantFromValue(p_cursor), QSql::Out);
if (content_query.exec())
{
QSqlQuery result_query(p_cursor);
result_query.exec();
}
else
{
qCritical("%s.", qPrintable(content_query.lastError().text()));
}

Get attribute or elements from page by script in nightwatch

I need a check that class elements was ui-state-active.
class="ui-state-default ui-state-active" href="#">15</a>
I am trying to using all methods and don't undestand how to write a code:
.perform(function () {
var arrAttr = [];
var arrCssProp = [];
var arrValue= [];
for (i = 1; i < 8; i++) {
for (j = 1; j < 7; j++) {
browser.useXpath();
browser.getCssProperty('//*[#id="ui-datepicker-div"]/table/tbody/tr[' + i + ']/td[' + j + ']', '.ui-state-default', function (result) {
arrCssProp[j, i] = result.value;
});
browser.getAttribute('//*[#id="ui-datepicker-div"]/table/tbody/tr[' + i + ']/td[' + j + ']', '.ui-state-default', function (result) {
arrAttr[j, i] = result.value;
});
browser.getValue('//*[#id="ui-datepicker-div"]/table/tbody/tr[' + i + ']/td[' + j + ']', '.ui-state-default', function (result) {
arrValue[j, i] = result.value;
});
browser.useCss();
writeLogLine('arrAttr:' + i + "|" + j + ' :' + arrAttr);
console.log('arrAttr:' + i + "|" + j + ' :' + arrAttr);
writeLogLine('arrCssProp:' + i + "|" + j + ' :' + arrCssProp);
console.log('arrCssProp:' + i + "|" + j + ' :' + arrCssProp);
writeLogLine('arrValue:' + i + "|" + j + ' :' + arrValue);
console.log('arrValue:' + i + "|" + j + ' :' + arrValue);
}
}
})
To get the attribute of class, you can write similar code
browser.getAttribute(pageObject.getElement('#ui'), "class", function (result) {
if (result.value.indexOf("ui-state-active")!=-1) {
console.log('class name:' + result.value);
}
else { console.log('class name:' + result.value); }});
You can use any locator strategy. To use CSS strategy based on class name, use .ui-state-default along with tagname.
Hope this helps.
Like in Rohit's example, if you want to use an attribute value, all the commands that rely on it need to be inside the callback. Doing arrCssProp[j, i] = result.value; won't work, since that value will disappear as soon as you exit the callback.
For more info, check out https://github.com/nightwatchjs/nightwatch/wiki/Understanding-the-Command-Queue

Algorithm - Given a set of pixels with coordinates, how to find all the contiguous lines in an efficient way?

I am working on an extrusion function to create a mesh given a 2D texture and the thickness of it.
Example:
I have achieved finding the outline of the texture by simply looking for the pixels either near the edge or near transparent ones. It works great even for concave (donut-shaped) shapes but now I am left with an array of outline pixels.
Here is the result:
The problem is that the values, by being ordered from top-left to bottom-right, they are not suitable for building an actual 3D outline.
My current idea is the following:
Step 1.
From index [0], look at the right-hand side for the nearest contiguous point different from the starting point.
If found, move it into another array.
If nothing, look at the bottom. Continue until the starting point has been reached.
Step2.
Pick another pixel, if any, from the pixels remained in the array.
Repeat from Step1.
This, in my head, would work but it seems quite inefficient. Researching, I found about the Moore-Neighbor tracing algorithm but I couldn't find anywhere an example where it worked with convex shapes.
Any thoughts?
At the end, I managed to find my own answer, so here I want to share it:
After finding the outline of a given image (using the alpha value of each pixel), the pixels will be ordered in rows, good for drawing them but bad for constructing a mesh.
So, the next step is to find contiguous lines. This is done by checking first if there are any neighbors to the found pixel giving priority to the ones top/left/right/bottom (otherwise it will skip the corners).
Keep going until no pixels are left in the original array.
Here is the actual implementation (for Babylon.js but the idea works with any other engine):
Playground: https://www.babylonjs-playground.com/#9GPMUY#11
var GetTextureOutline = function (data, keepOutline, keepOtherPixels) {
var not_outline = [];
var pixels_list = [];
for (var j = 0; j < data.length; j = j + 4) {
var alpha = data[j + 3];
var current_alpha_index = j + 3;
// Not Invisible
if (alpha != 0) {
var top_alpha = data[current_alpha_index - (canvasWidth * 4)];
var bottom_alpha = data[current_alpha_index + (canvasWidth * 4)];
var left_alpha = data[current_alpha_index - 4];
var right_alpha = data[current_alpha_index + 4];
if ((top_alpha === undefined || top_alpha == 0) ||
(bottom_alpha === undefined || bottom_alpha == 0) ||
(left_alpha === undefined || left_alpha == 0) ||
(right_alpha === undefined || right_alpha == 0)) {
pixels_list.push({
x: (j / 4) % canvasWidth,
y: parseInt((j / 4) / canvasWidth),
color: new BABYLON.Color3(data[j] / 255, data[j + 1] / 255, data[j + 2] / 255),
alpha: data[j + 3] / 255
});
if (!keepOutline) {
data[j] = 255;
data[j + 1] = 0;
data[j + 2] = 255;
}
} else if (!keepOtherPixels) {
not_outline.push(j);
}
}
}
// Remove not-outline pixels
for (var i = 0; i < not_outline.length; i++) {
if (!keepOtherPixels) {
data[not_outline[i]] = 0;
data[not_outline[i] + 1] = 0;
data[not_outline[i] + 2] = 0;
data[not_outline[i] + 3] = 0;
}
}
return pixels_list;
}
var ExtractLinesFromPixelsList = function (pixelsList, sortPixels) {
if (sortPixels) {
// Sort pixelsList
function sortY(a, b) {
if (a.y == b.y) return a.x - b.x;
return a.y - b.y;
}
pixelsList.sort(sortY);
}
var lines = [];
var line = [];
var pixelAdded = true;
var skipDiagonals = true;
line.push(pixelsList[0]);
pixelsList.splice(0, 1);
var countPixels = 0;
while (pixelsList.length != 0) {
if (!pixelAdded && !skipDiagonals) {
lines.push(line);
line = [];
line.push(pixelsList[0]);
pixelsList.splice(0, 1);
} else if (!pixelAdded) {
skipDiagonals = false;
}
pixelAdded = false;
for (var i = 0; i < pixelsList.length; i++) {
if ((skipDiagonals && (
line[line.length - 1].x + 1 == pixelsList[i].x && line[line.length - 1].y == pixelsList[i].y ||
line[line.length - 1].x - 1 == pixelsList[i].x && line[line.length - 1].y == pixelsList[i].y ||
line[line.length - 1].x == pixelsList[i].x && line[line.length - 1].y + 1 == pixelsList[i].y ||
line[line.length - 1].x == pixelsList[i].x && line[line.length - 1].y - 1 == pixelsList[i].y)) || (!skipDiagonals && (
line[line.length - 1].x + 1 == pixelsList[i].x && line[line.length - 1].y + 1 == pixelsList[i].y ||
line[line.length - 1].x + 1 == pixelsList[i].x && line[line.length - 1].y - 1 == pixelsList[i].y ||
line[line.length - 1].x - 1 == pixelsList[i].x && line[line.length - 1].y + 1 == pixelsList[i].y ||
line[line.length - 1].x - 1 == pixelsList[i].x && line[line.length - 1].y - 1 == pixelsList[i].y
))) {
line.push(pixelsList[i]);
pixelsList.splice(i, 1);
i--;
pixelAdded = true;
skipDiagonals = true;
}
}
}
lines.push(line);
return lines;
}
Algorithm Looping over pixels, we only check each pixel once, skipping empty cells, and store it in a list as there won't be duplicates.
isEmpty implementation depends on how transparency works in your case, if a certain color is considered transparent, below is a case where we have an alpha channel.
threshold is the alpha level that represent the least-visibility for a cell to be considered non-empty.
isBorder will check if any of Moore neighbors is empty, in that case it is a border cell, otherwise it's not because it is surrounded by filled cells.
isEmpty(x,y): image[x,y].alpha <= threshold
isBorder(x,y)
: if isEmpty(x , y-1): return true
: if isEmpty(x , y+1): return true
: if isEmpty(x-1, y ): return true
: if isEmpty(x+1, y ): return true
: if isEmpty(x-1, y-1): return true
: if isEmpty(x-1, y+1): return true
: if isEmpty(x+1, y-1): return true
: if isEmpty(x+1, y+1): return true
: otherwise: return false
getBorderCellList()
: l = empty-list
: for x in 0..image.width
: : for y in 0..image.height
: : : if !isEmpty(x,y)
: : : : if isBorder(x,y)
: : : : : l.add(x,y)
: return l
Optimization You could optimize this by having a pre-computed boolean e[image.width][image.height] where e[x,y] = 1 if image[x,y]is not-empty, then use it directly to check, like isBorder(x,y): e[x-1,y] | e[x+1,y] | .. | e[x+1,y+1].
init()
: for x in 0..image.width
: : for y in 0..image.height
: : : e[x,y] = isEmpty(x,y)
isEmpty(x,y): image[x,y].alpha <= threshold
isBorder(x,y): e[x-1,y] | e[x+1,y] | .. | e[x+1,y+1]
getBorderCellList()
: l = empty-list
: for x in 0..image.width
: : for y in 0..image.height
: : : if not e[x,y]
: : : : if isBorder(x,y)
: : : : : l.add(x,y)
: return l

Resources