Get the values form NoUiSlider with two handles - nouislider

Documentation says to get the current value use slider.noUiSlider.get();. But in case of a slider with two handles (and thus two values), how do I get these two seperate values?

For a slider with two handles, the result of slider.noUiSlider.get() is [firstValue, secondValue]. All events provide this array as a parameter, as well as the handle index (0/1), allowing to map the two.
slider.noUiSlider.on('update', function(values, handle) {
// value for updated handle is in values[handle]
});

Related

Is it able to call multiple drawcalls of vkCmdDrawIndexed in one render pass containing one pipeline?

I have two meshes, containing same material template but with different paramters. I want to draw these two meshes one by one. For example, the pseudocode likes
BeginRenderPass
BindPipeline
for(auto& mesh : meshes)
{
BindVertexBuffers(mesh.vertexBuffer)
AddUniformBufferDescriptorSet(mesh.material)
UpdateDescriptorSets
BindIndexBuffer(mesh.indexBuffer)
DrawIndexed(mesh.indexCount, 1, 0, 0, 0)
}
vkCmdEndRenderPass
I bind vertex buffers of all mesh to same binding index, and use same descriptor set for all uniform object. There are some validation errors:
validation layer: Validation Error: [ UNASSIGNED-CoreValidation-DrawState-InvalidCommandBuffer-VkDescriptorSet ] Object 0: handle = 0x40b43c0000000049, type = VK_OBJECT_TYPE_DESCRIPTOR_SET; Object 1: handle = 0x1c40e53df48, type = VK_OBJECT_TYPE_COMMAND_BUFFER; | MessageID = 0xe8616bf2 | You are adding vkCmdBindVertexBuffers() to VkCommandBuffer 0x1c40e53df48[] that is invalid because bound VkDescriptorSet 0x40b43c0000000049[] was destroyed or updated.
How can I implement the above pseudocode ?
There is my finding(WRONG). ~~First, the conclusion is I can not implment mulitple draw calls like the above pseudocode.~~ Because, according to vkUpdateDescriptorSets , it will invalid the command buffer used to bind the descriptor sets, which will disenable record next call. Therefore, the validation error appears.
What I can implement to draw multiple meshes with seperate material parameters.
There are two ways:
Use push_constant in shader to config material parameters, and set the corresponding parameter values by vkCmdPushConstants before draw call.
Use uniform buffer array in shader, where each element is a set of material parameters. Add an additional input attribute named “material id” to index the corresponding uniform buffer. Then update the uniform buffer array in one call of vkUpdateDescriptorSets. The current command buffer still can record next draw call command.
The first way is inspired by Sascha_Willems, the second way is what I have successfully implemented.
Supplement(CORRECTION)
I also try to update and bind the corresponding descriptor set before each of two draw calls insider one render pass. Finally, it works. Note that two seperate descriptor sets with same layout bindings need to be created, but the graphics pipeline need to be decleared to contain only one descriptor set.

Exposing the current combo selection index for the CGridCellCombo class

For several years I have been using the CGridCellCombo class. It is designed to be used with the CGridCtrl.
Several years ago I did make a request in the comments section for an enhancement but I got no replies.
The basic concept of the CGridCellCombo is that it works with the text value of the cell. Thus, when you present the drop list it will have that value selected. Under normal circumstances this is fine.
But I have places where I am using the combo as a droplist. In some situations it is perfectly fine to continue to use the text value as the go-between.
But is some situations it would have been ideal to know the actual selected index of the combo. When I have a droplist and it is translated into 30 languages, and I need to know the index, I have no choice but to load the possible options for that translation and then examine the cell value and based on the value found in the array I know the index.
It works, but is not very elegant. I did spend a bit of time trying to keep track of the selected index by adding a variable to CInPlaceList and setting it but. I then added a wrapper method to the CGridCellCombo to return that value. But it didn't work.
I wondered if anyone here has a good understanding of the CGridCellCombo class and might be able to advise me in exposing the CComboCell::GetCurSel value.
I know that the CGridCtrl is very old but I am not away of another flexible grid control that is designed for MFC.
The value that is transfered back to the CGridCtrl is choosen in CInPlaceList::EndEdit. The internal message GVN_ENDLABELEDIT is used, and this message always use a text to set it into the grid.
The value is taken here via GetWindowText from the control. Feel free to overwrite this behaviour.
The handler CGridCtrl::OnEndInPlaceEdit again calls OnEndEditCell. All take a string send from GVN_ENDLABELEDIT.
When you want to make a difference between the internal value and the selected value you have to manage this via rewriting the Drawing and selecting. The value in the grid is the GetCurSel value and you have to show something different... There isn't much handling about this in the current code to change.
More information
The key is CInPlaceList::EndEdit(). There is a call to GetWindowText (CInPlaceList is derived from CComboBox), just get the index here. Also in CGridCellCombo::EndEdit you have access to the m_pEditWnd, that is the CInPlaceList object and derived from CComboBox, so you have access here too.
I have found this to be the simplest solution:
int CGridCellCombo::GetSelectedIndex()
{
int iSelectedIndex = CB_ERR;
CString strText = GetText();
for (int iOption = 0; iOption < m_Strings.GetSize(); iOption++)
{
if (strText.CollateNoCase(m_Strings[iOption]) == 0) // Match
{
iSelectedIndex = iOption;
break;
}
}
return iSelectedIndex;
}

How do I identify specific entity within a FlxGroup from FlxG.collide?

How do I make it so that when a bullet from the bullet group collides with an enemy from the enemy group, only the two hitting eachother will get affected?
I tried doing (In playstate):
if (FlxG.collide(bullet, enemy)){
bullet.kill();
enemy.kill();
}
But the only thing this succeeded in doing is killing the entire group. How do I only kill the ones affected?
In the Haxeflixel API docs:
collide(?ObjectOrGroup1:FlxBasic, ?ObjectOrGroup2:FlxBasic, ?NotifyCallback:Dynamic‑>Dynamic‑>Void):Bool
so I think you can use something like:
FlxG.collide(
groupBullets,
groupEnemies,
function (bullet:FlxObject, enemy:FlxObject):Void {
enemy.kill();
bullet.kill();
}
);
You want to pass in a notification callback:
https://github.com/HaxeFlixel/flixel/blob/24529ac96d4ad49a5f0c7e64799d0197cee9049e/flixel/FlxG.hx#L395
So something like this is what you want:
FlxG.collide(bulletGroup, enemyGroup, collideBulletEnemy));
function collideBulletEnemy(bullet:FlxObject, enemy:FlxObject):Void
{
bullet.kill();
enemy.kill();
}
Some more explanation:
The collide() function in flixel lets you pass in either an object or a group to either parameter, and tells you if those two things collide. In the case of two objects, you can directly follow that test up with logic operating on those two objects. But if one of the objects is a group, you don't know based on the test alone which things collided, so you need to rely on a callback you supply yourself to get that specific information.

Referencing external doc in CouchDB view

I am scraping an 90K record database using JSON-RPC and I am trying to put in some basic error checking. I want to start by scraping the database twice using two different settings and adding a prefix to the second scrape. This way I can check to ensure that the two settings are not producing different records (due to dropped updates, etc). I wanted to implement the comparison using a view which compares each document from the first scrape with it's twin produced by the second scrape and then emit the names of records with a difference between them.
However, I cannot quite figure out how to pull in another doc in the view, everything I have read only discusses external docs using the emit() function, which is too late to permit me to compare it. In the example below, the lookup() function would grab the referenced document.
Is this just not possible?
function(doc) {
if(doc._id.slice(0,1)!=='$' && doc._id.slice(0,1)!== "_"){
var otherDoc = lookup('$test" + doc._id);
if(otherDoc){
var keys = doc.value.keys();
var same = true;
keys.forEach(function(key) {
if ((key.slice(0,1) !== '_') && (key.slice(0,1) !=='$') && (key!=='expires')) {
if (!Object.equal(otherDoc[key], doc[key])) {
same = false;
}
}
});
if(!same){
emit(doc._id, 1);
}
}
}
}
Context
You are correct that this is not possible in CouchDB. The whole point of the map function is that it must be idempotent, otherwise you lose all the other nice benefits of a pre-calculated index.
This is why you cannot access external resources in the map function, whether they be other records or the clock. Any time you run a map you must always get the same result if you put the same record into it. Since there are no relationships between records in CouchDB, you cannot promise that this is possible.
Solution
However, you can still achieve your end goal, just be different means. Some possibilities...
Assuming there is some meaningful numeric value in each doc, you could use a view to take the sum of all those values and group them by which import you did ({key: <batch id>, value: <meaningful number>}). Then compare the two numbers in your client or the browser to see if they match.
A brute force approach would be to use a view to pair the docs that should match. Each doc is on a different row, but they're grouped by a common field. Then iterate through the entire index comparing the pairs. This would certainly be the quickest to code and doesn't depend on your application or data.
Implement a validation function to enforce a schema on your data. Just be warned that this will reduce your write throughput since each written record will be piped out of Erlang and into the JS engine. Also, this is only applicable if you're worried about properly formed records instead of their precise content, which might not be the case.
Instead of your different batch jobs creating different docs, have them place them into the same doc. The structure might look like this: { "_id": "something meaningful", "batch_one": { ..data.. }, "batch_two": { ..data.. } } Then your validation function could compare them or you could create a view that indexes all the docs that don't match. All depends on where in your pipeline you want to do the error checking and correction.
Personally I like the last option better, but only if you don't plan to use the database as is in production. Ie., you wouldn't want to carry around all that extra data in each record.
Hope that helps.
Cheers.

CouchDB emit with lookup key that is array, such that order of array elements are ignored

When indexing a couchdb view, you can emit an array as the key such as:
emit(["one", "two", "three"], doc);
I appreciate the fact that when searching the view, the order is important, but sometimes I would like the view to ignore it. I have thought of a couple of options.
1. By convention, just emit the contents in alphabetical order, and ensure that looking up uses the same convention.
2. Somehow hash in a manner that disregards the order, and emit/search based on that hash. (This is fairly easy, if you simply hash each one individually, "sum" the hashes, then mod.)
Note: I'm sure this may be covered somewhere in the authoritative guide, but I was unsuccessful in finding it.
It looks like the correct approach is to determine a conventional ordering on the keys, emit them in this ordering, and be sure to query with this ordering enforced. Otherwise we would need to emit all n(factorial) permutations of the keys (which could get bad if n is greater than 3)
CouchDB will always maintain the array keys in order. Have you considered emitting all sequence variations as part of the view? Something along the lines of:
function(doc) {
function computeAllKeyVariations(fromKey) {
// returns array of key arrays
}
var allKeys = computeAllKeyVariations(startingKey);
for (k in allKeys) {
emit(k, doc); // or emit(k, null)
}
}
Side note: You also have the option to use emit(['one','two','three'], null) instead of emitting the document. This will avoid having CouchDB store the full document in the view index (more than once). To get the same results as before just make use of &include_docs=true

Resources