Get coordinate with NaN at x axis - rxjs

i got the following block of code to generate a new enemy each 1.5.
each new enemy is added to an array using scan operator
i did the replace suggested.
i did a small change to be able to replicate
const enemies$ = rxjs.from([0,1])
.pipe(
rxjs.scan( (enemyArray) => {
const enemy = {
x: Math.floor(Math.random() * 100),
y: -30
}
console.log(enemy)
enemyArray.push(enemy);
console.log(enemyArray); //debug.
return enemyArray;
}, [])
);
enemies$.subscribe(
(enemies) => console.log(enemies)
);
The result in the console is the following for the first element (enemy)
{x: 312, y: -30}
But when the enemy is added to enemyArray , the following results are shown in the console
(1)[{...}]
0: {x: NaN, y: 515}
1: {x: NaN, y: 65}
length: 2
[[Prototype]]: Array(0)

parseInt() takes a string as the first argument, so it should be
parseInt(String(Math.random() * 100), 10)

Related

How to check orientation based on css `transform: rotate(270deg)` in Cypress?

I need to check the orientation of a div with Cypress.
This is the test:
cy
.get('data-test="vertical"')
.should('have.css', 'transform', 'translate(-100%, 0) rotate(270deg)')
The div behaviour is standard in a scenario, or it's rotated with css transform: translate(-100%, 0) rotate(270deg); in the other scenario.
I need a way to check the orientation, but transform is difficult to check, because for example in Cypress test what happens is:
when I expect transform: rotateX(180deg) I actually receive transform: matrix3d(1, 0, 0, 0, 0, -1, 1.22465e-16, 0, 0, -1.22465e-16, -1, 0, 0, 0, 0, 1).
I need to find a smart way to detect the orientation. Suggestions? Tips?
Issue is solved like this, with the creation of a command:
const getTransformRotationAngle = (cssTransformMatrix, absoluteValue) => {
const cssTransformMatrixIndexes = cssTransformMatrix
.split('(')[1]
.split(')')[0]
.split(',')
const cssTransformScale = Math.sqrt(
cssTransformMatrixIndexes[0] * cssTransformMatrixIndexes[0] +
cssTransformMatrixIndexes[1] * cssTransformMatrixIndexes[1]
)
const cssTransformSin = cssTransformMatrixIndexes[1] / cssTransformScale
const cssTransformAngle = Math.round(
Math.asin(cssTransformSin) * (180 / Math.PI)
)
return absoluteValue ? Math.abs(cssTransformAngle) : cssTransformAngle
}
Cypress.Commands.add('getTransformRotationAngle', getTransformRotationAngle)
and its use in the test:
cy
.get('data-test="vertical"')
.invoke('css', 'transform')
.then(cssTransform => {
cy.getTransformRotationAngle(cssTransform, true).should(
'eq',
90 || 270
)
})

Drag and drop an element

With protractor and firefox, I want to drag and drop an element with this:
const plot0 = element(by.id('AnalyseErrors'));
browser.actions().dragAndDrop(plot0, {x: 70, y: 70}).mouseDown().mouseMove({x: 10, y: 10})
.mouseMove({x: 10, y: 10})
.mouseMove({x: 10, y: 10})
.mouseMove({x: 10, y: 10})
.mouseMove({x: 10, y: 10})
.perform();
I also try
browser.actions().dragAndDrop(plot0, {x: 70, y: 70}).perform();
I even try:
const element0 = element(by.id('AnalyseErrors')).getWebElement(); // This is the element to move
const element1 = element(by.css('body > app-root > div > ng-component > div > div.editor-container')).getWebElement(); // This is the content zone to drop the element
browser.actions()
.dragAndDrop(element0, element1).
perform();
The element is located on a side bar, i have to select him and, with the mouse , dragg and drop to a content zone.
Unfortaly doesn't work.
- Failed: POST /session/875dc0ad-4d29-4bff-9efc-98e4d05379f4/moveto did not match a known command
Do you know why?

googlevr/vrview Read position form onGetPosition and set its value for next init

I'm wondering if it is possible (I hope it is) to set init camera rotation read from onGetPosition?
My onGetPosition function look like this:
function onGetPosition() {
console.log({
Yaw: worldRenderer.camera.rotation.y * 180 / Math.PI,
Pitch: worldRenderer.camera.rotation.x * 180 / Math.PI,
x: worldRenderer.camera.rotation.x,
y: worldRenderer.camera.rotation.y,
z: worldRenderer.camera.rotation.z
});
...
}
https://github.com/googlevr/vrview/blob/4e8e57eaddd8e69c8e032a6b5844d4e96af02156/src/embed/main.js#L357
I use this image as a texture:
Initial view, with default_yaw set to 0 degrees looks like this:
In this position onGetPosition returns:
{Yaw: 0, Pitch: -0, x: -0, y: 0, z: -0}
Then I rotate the scene to see this position (about 90 deg to the left):
onGetPosition returns:
{Yaw: 75.66036892219512, Pitch: -42.97581864568984, x: -0.7500695341072581, y: 1.3205225509658982, z: 0.7343037709331535}
I thought that if I set camera rotation inside setDefaultYaw_ function I would see last view so I did this:
WorldRenderer.prototype.setDefaultYaw_ = function(angleRad) {
...
this.camera.setRotationFromEuler(new THREE.Euler(-0.7500695341072581, 1.3205225509658982, 0.7343037709331535, 'XYZ'));
};
https://github.com/googlevr/vrview/blob/2dd890d147f702b9c561694bda5c86575c2a3d44/src/embed/world-renderer.js#L235
Unfortunately nothing happened I still see the view from second image on init.
How can I solve it?

Animate on bézier with ScrollMagic: Initial state = first bézier point

See a jsfiddle here
I am tweening along a bézier path with 3 points.
// bezier data
var bezierData = {
curviness: 1,
autoRotate: false,
values: [
{x: 0, y: 0, rotation:"40_cw"}, /* <-- The desired state of the object before any animation has happened */
{x: 20, y: 0, rotation:"0_ccw"},
{x: 40, y:0, rotation:"-20_ccw"}
]
};
// build tween
var tween = new TimelineMax()
.add(TweenMax.to("#testobj", 1, {css:{bezier: bezierData}, ease:Power1.easeInOut}));
// create scene
var scene = new ScrollMagic.Scene({
triggerElement: "#testobj",
duration: 100,
offset: 10
})
.setTween(tween)
.addTo(ctrl)
.addIndicators();
What I want: The initial state of my object (i.e. before any animation has happened) should be the first bézier point, {x: 0, y: 0, rotation:"40_cw"}.
What's happening: The initial state is the object's default style, i.e. the equivalent of {x: 0, y: 0, rotation:"0"}. Note how in the jsfiddle the green square starts out upright while I want it to start rotated 40° clock-wise.
Tahir Ahmed's answer works!
perhaps you can use .set() before doing the .to() tween? something like this.

Query Mongoid for all circle areas that include a given point

Let say I have two classes:
class Cirle
include Mongoid::Document
field :lat, type: Float
field :lon, type: Float
field :radius, type: Integer
end
class Point
include Mongoid::Document
field :lat, type: Float
field :lon, type: Float
end
How can I find all Circles that include a given Point?
I'm not familiar with Mongoid, but perhaps the following will help. Suppose:
circles = [
{ x: 1, y: 2, radius: 3 },
{ x: 3, y: 1, radius: 2 },
{ x: 2, y: 2, radius: 4 },
]
and
point = { x: 4.5, y: 1 }
then the circles containing point are obtained with the help of Math::hypot:
circles.select { |c|
Math.hypot((c[:x]-point[:x]).abs, (c[:y]-point[:y]).abs) <= c[:radius] }
#=> [{ x: 3, y: 1, radius: 2 }, { x: 2, y: 2, radius: 4 }]
Edit: to improve efficiency as #Drenmi suggests:
x, y = point.values_at(:x, :y)
circles.select do |c|
d0, d1, r = (c[:x]-x).abs, (c[:y]-y).abs, c[:radius]
d0*d0 + d1*d1 <= r*r
end

Resources