Svitlana Moiseyenkohttp://svitlanamoiseyenko.com
Developer BlogTue, 17 Jan 2017 22:08:29 +0000en-UShourly1https://wordpress.org/?v=4.7.12http://svitlanamoiseyenko.com/wp-content/uploads/2016/07/cropped-svetka@2x-32x32.pngSvitlana Moiseyenkohttp://svitlanamoiseyenko.com
3232Storing of floating point numbers in memoryhttp://svitlanamoiseyenko.com/2017/01/17/storing-of-floating-point-numbers-in-memory/
http://svitlanamoiseyenko.com/2017/01/17/storing-of-floating-point-numbers-in-memory/#respondTue, 17 Jan 2017 22:07:21 +0000http://svitlanamoiseyenko.com/?p=1825In one of my previous article I mentioned about storing float point number.
So today, I am going to dive in the deeper details and share with you how exactly computer does it.1. Floating point numbers. Why we need them?2. Details about number representation.3. How the converting process happens?4. Final Result.

Floating point numbers. Why we need them?

Since computer memory is limited, you cannot store numbers with infinite precision, no matter whether you use binary fractions or decimal ones: at some point you have to cut off. Float point numbers is one of the possible way to represent real number so that to keep a trade-off between range and precision.

What does this mean?
It means that each float number, according to standard IEEE754, can be represented in next form:

Details about number representation.

However, we will consider only one of them namely Single precision which allows us to store digits with accuracy of 7-8 decimal numbers (from to in range).
A little more how the single precision floating point number is organized.

It occupies 32 bits(4 bytes) and provides (1 bit for sign, 8 bits for exponent and 23 for mantissa).

How the converting process happens?

I take some double(let it be 5.125) and will make conversion step by step, to show the whole number transition from decimal to binary format.

Now take a look at 5.125 and define next points:Sign = 0 (means positive number)Mantissa = 125 (actually this is the fraction)Exponent = 2 (power) – you will see later how can we get thisBase will be = 2(binary representation)
So eventually we will be able to see the number in exponential form and to understand how the computer will store it in binary format.

Step1 (conversion of the fractional part)

Since in normalized binary mantissa integer part always equals to 1, so that we will put only fraction part into mantissa.
Consider our 5.125 and take the fractional part = 0.125.

Now we need to convert it into a binary fraction:

Multiply the fraction by 2

Get rid of integer part

Check if new fraction = zero
If NO – re-multiply new fraction by 2 (Note: you can repeat until the precision limit is reached 23 fraction digits). If YES – finish.

After following schema above we got the next: – here is terminate
So 0.125 fraction can be represented in as 0,001
Therefore

Step2 (de-normalize number)

It means that we need to represent the number in exponential form. You can read more details here.
In general, you need to shift coma that the number will have such form:

So firstly, we need to make left or right shifting, depends on what we already have.
In our case we have 101.001, so that would be shifted to the right by 2 digits and become . Screen below:Step3 (find the offset-bite)
Actually, we need to make next:

Offset-bite = 127 + 2 = 129
After converting this to binary we will get 10000001

Final Result.

So what we exactly have? Our number 5.125 looks in exponential form like
this and represented in binary like this:

I hope it was helpful information for you. Feel free to correct me. Will appreciate.

]]>http://svitlanamoiseyenko.com/2017/01/17/storing-of-floating-point-numbers-in-memory/feed/0Writing filters for MacOS using kernelhttp://svitlanamoiseyenko.com/2016/12/21/writing-filters-for-macos-using-kernel/
http://svitlanamoiseyenko.com/2016/12/21/writing-filters-for-macos-using-kernel/#respondWed, 21 Dec 2016 02:15:10 +0000http://svitlanamoiseyenko.com/?p=1779I’ve been really interested in possibility of writing my own filters without using special libraries. When I started to search solution I found Apple doc which was rather helpful for me.
And this is about using of kernel language.
So let’s start from:1. Create MacOS project.2. Implement filters.3. Configuring of views and apply filters.

Create MacOS project.

It should be MacOS (Objective-C) project or you can download the sample

Implement filters.

Now let’s create 3 files and put it in NoiseFilterNoiseFilter.h
Put here just a declaration of methods

]]>http://svitlanamoiseyenko.com/2016/12/21/writing-filters-for-macos-using-kernel/feed/0Creating 360 view for web using Unity3d and 360 VR Player Starter Kithttp://svitlanamoiseyenko.com/2016/12/11/creating-360-view-for-web-using-unity3d-and-360-vr-player-starter-kit/
http://svitlanamoiseyenko.com/2016/12/11/creating-360-view-for-web-using-unity3d-and-360-vr-player-starter-kit/#respondSun, 11 Dec 2016 23:25:08 +0000http://svitlanamoiseyenko.com/?p=1744Hi, I would like to share how to create 360 scene in Unity and build the project using WebGL.
The main problem I encountered was that I could not rotate the camera around after building the project for web. Therefore I found 360 VR Player Starter Kit plugin which helped me to solve the problem. It’s not free but worth your attention.

Project preparation.

Now, open the Main scene. Here you can see a lot of objects in hierarchy.
To put all in a nutshell, we need only camera object. So just remove everything except this one.

Wait, concerning sphere, you can use already created sphere (which is laying on scene) or create your own. I would suggest you to create the new one, because the current one is low-poly model and you can get squashed image ultimately.

Creating a sphere.

So I removed all of the objects from scene except camera and started with creating new one.
I am using Maya and will provide some hints how to do it fast.

So please create sphere and increase the number of subdivisions.
Then you need to invert sphere to turn it inside out, it’s a trick for future 360 panorama view.
To invert all faces we need to choose menu Select → Face. After selecting of all the sphere by mouse please click on menu Normals → Reverse
Export sphere as .obj file

Import model into Unity and make further configurations.

To proceed we need to import model from Maya into the Unity. Just drag saved object file to the Unity assets.
Now you need to create material. Let’s call it 360
Don’t forgot to change the new material shader. Select material → Inspector → change to Unlit/Texture.
Drag your 360 panorama texture to the Texture folder in Unity assets.
Be sure that width/height ratio is about 2/1.
Add texture to the 360 material.
If it is needed you can mirror sides by setting of tiling -1; 1, it could make the final view more natural.

Put the camera inside the sphere
Launch and check that everything is fine and you are able to rotate the camera inside the sphere.

Build WebGL project.

Build project with WebGL. The result will be html file with assets that you can easily upload to your site or test locally.

You can download sources here. Feel free to left some comments and ideas. Thanks!

]]>http://svitlanamoiseyenko.com/2016/12/11/creating-360-view-for-web-using-unity3d-and-360-vr-player-starter-kit/feed/0Specific computation of floating point valueshttp://svitlanamoiseyenko.com/2016/12/03/specific-computation-of-floating-point-values/
http://svitlanamoiseyenko.com/2016/12/03/specific-computation-of-floating-point-values/#commentsSat, 03 Dec 2016 00:14:00 +0000http://svitlanamoiseyenko.com/?p=1716Hi all! My professor wrote on the board simple numbers and asked the class to calculate it at home.

When I came home I open my laptop and starting to write. After finishing I realized that sum1 and sum2 are different.

We all know the Math rule by permutation sum is not changed so(a + b) + c = a + (b + c), and it seems to be that it is not TRUE in programming.
It is really confused me, so I decided to understand why it happens and calculate step by step.

(a + b) + c = 1 seems pretty clear

a + (b + c) = 0 . Looks like a magic …

Why -1e+30 + 1.0 = -1e+30 ?
The answer is a simple. Computer allocate the memory depends on what type we use. In our case we are working with double. It means that 64 bit memory block will be allocated for each number (the range of numbers is 1.7у-38<|x|<3.4e38), 17 figures accuracy. Then computer try to perform -1e+30 + 1.0 and it’s just get rid of the 1 due to the lack of bit space.
That’s explains our differ results.

Such errors related with binary representation of floating point numbers in memory. If you want to exclude them you need to use BigDecimal. But be careful do not use BigDecimal(s) without need because it’s just a wasting of memory.

Additionally, you can always see the sign, mantissa and exponent by using this code or get more info using this documentation

Configure Camera.

Before we start with camera configuration we need to remove a camera which was created by default. Then put [CameraRig] from SteamVR to Hierarchy.
And remove or disable left and right hands. They are not essential for now.
After this select Camera(ears) and drag [CameraRig] to Vrcam property.
And one more thing is extending of our horizon line, because some things can disappear due to the limit of the eye view. To be more clear I highlighted with red circle on the screen below.

Configure Simulator.

From _ImmerseumSDK choose [VRSimulator] and put to Hierarchy also. This allows us to test application in Unity like we are using HTC Vive.
Now let’s move to the configurations of the simulator. Select VRSimulator → HMD Simulator script → CameraRig property and move here [CameraRig] object.

Configure environment.

Create new GameObject and call it SunPivot. Then take DirectionLight and put it inside of the new created object. Put SunPivot somewhere in the center of terrain. As you can guess the SunPivot will be the center point of rotation. Now just move DirectionLight by axis X, where your horizon line will be.
I demonstrated on the next screen how it should looks eventually.
Additionally, it would be good to add one more DirectionalLight and call it just AdditonalLight, this will help to see smth when the dark will come.

And one more thing, you also need to check Skybox configuring.
Open Window → Lighting. I left default skybox as it is and put the DirectionLight to the property Sun, you can see in the screen below. Also it is better to uncheck property Auto to avoid backing of scene every time when you make changes. Please review the following screen.

Preparing for animation.

Before working with animation we need to create new folder in Assets. Let’s call it Animations. Here you can store all animations with their controllers.
Then follow next steps:

1. Choose the SunPivot
2. Then open Window → Animation
3. Click button Create and save to the Animations folder with name SunAnimation and it’s controller, which will be called SunPivot as your selected object in Hierarchy.

4. If the Animator wasn’t added to the SunPivot do it manually. Be sure that the controller is also appointed.

Working with animation.

Now we are ready to work with animation.
Select the SunPivot and in the window Animation you can see:

Final result.

]]>http://svitlanamoiseyenko.com/2016/10/11/sunsetsunrise-for-vr-using-animation-only/feed/0DidReceiveRemoteNotification is not called on iOS 10http://svitlanamoiseyenko.com/2016/10/11/didreceiveremotenotification-is-not-called-on-ios-10/
http://svitlanamoiseyenko.com/2016/10/11/didreceiveremotenotification-is-not-called-on-ios-10/#respondTue, 11 Oct 2016 13:09:52 +0000http://svitlanamoiseyenko.com/?p=1619Hi all! Just faced with the issue that Push Notifications stopped work on iOS 10.
So I would like to write the article what has been changed in new version and how to fix it.
After debugging, I revealed that actually in iOS10 didReceiveRemoteNotification isn’t called anymore.

So there were some changes for new version and we need to make corrections in our code.
Follow next steps and do not forget about checking for iOS 10 version.Step1 – Add framework

The difference between “continuous” and “contiguous”.

Sometimes people think that “continuous” and “contiguous” are the same.However, there is a slight difference between them.

Contiguous means elements are touching or adjacent to. Means each element has its own cell and border.
Whereas continuous means uninterrupted and ceaseless.

Probably both seems synonymous but it would be correct to use “contiguous memory” in programming terms.

So what does it mean “Contiguous memory block”?

It means that elements in contiguous chunk of memory are laid out end-to-end, with no gaps and no padding between them. There is a possibility of padding inside each element, but not between them. It’s depicted in the following images.

Data structures that are held in contiguous memory

The bright example of data structures which use contiguous chunk of memory are Arrays and Queue. We may also say about the String which can conform to contiguous memory. But do not hurry. We can definitely say that String uses contiguous memory in such languages like C++, Python2, Go and others but not in Swift. I would recommend to read this article by Mike Ash. He explained it really nice.

Computing Time

The computing time of the methods of these data structures are different. It explains by the requirements of shifting all elements after removing or inserting them from/in the middle of array.

For example it will be the constant time O(1) for methods like:
Array:

popLast() //if array is not bridget
removeLast()

Queue:

dequeue()
enqueue()

linear timeO(n) in methods for array like
Array:

removeAtIndex(index)
insert(newElement, atIndex: index)

We can also notice the logarithmic time O(log n) in case you perform
Queue:

enqueue(priority)

Btw, you can always check the complexity time using Playground/Xcode. Press and hold ALT and click on some method or property.

Several words about Contiguous Memory Allocation

Contiguous Memory Allocation is one of the various approaches of memory allocation. It based on dividing all available memory into equal sized partitions, and to assign each process to their own partition.
This confine 2 things:

the number of simultaneous processes
the maximum size of each process

There is the rule – only one process can be stored in one section. The OS keeps fresh table, like a map, which contains all of the statuses of each piece of memory. So when the system gets a new process it’s already know all available places where the new task can be stored.
Here is visual representation of Contiguous Memory Allocation

I hope this topic was interesting for you. Feel free to contact me and provide more ideas for writing.

]]>http://svitlanamoiseyenko.com/2016/09/13/explain-contiguous-memory-using-swift-examples/feed/0O(log n) and how fast it ishttp://svitlanamoiseyenko.com/2016/08/30/olog-n-and-how-fast-it-is/
http://svitlanamoiseyenko.com/2016/08/30/olog-n-and-how-fast-it-is/#commentsTue, 30 Aug 2016 07:21:27 +0000http://svitlanamoiseyenko.com/?p=1526I was inspired by watching one of the Harvard CS50 and Stanford lectures. I want to share two interesting facts which I studied recently.1. Search problem solution.2. Logarithmic function with small/big problem sizes.

Search problem solution.

Have you ever thought how computers solve our tasks?
Let’s imagine that we want to find the word “mission” in the vocabulary with about 1000 pages and what we are going to do? It’s easy, just typing the word in the search and Viola! But how does it happen? It is supposed that our application has some algorithm and use it in some way.

Let’s review some of them and their computational time:
1.The first one is when we turn page by page through the vocabulary until we find the word. It will take O(n) (linear time) to find the appropriate word, not so much complexity though. You can see the block scheme of what we are going to do.
2. Ok let’s try to do it faster, go by twos. Also it would be good not to miss something in a process of searching. The computation time of this algorithm will be about O(n/2).
3. The third way. We can divide book by a half, and after that we will divide a half which can contain the searching word again. We will do so while we find the proper word. And this approach will take O(log n).

Now we already have 3 algorithms and therefore, we need to understand which one is faster.

The best way to figure it out is to calculate how the function is growing. In mathematical sense growing means the derivative of function. For example, the derivative of the position of a moving object with respect to time is the object’s velocity: this measures how quickly the position of the object changes when time is advanced.

Ok, go back to our vocabulary and increase the number of pages to 2000 and let’s think… How many more steps these functions need to compute?

To compute 1000 pages with the linear method O(n) we need maximum 1000 iteration. So for 2000 pages the number of steps will be increased ×2.

The second method will grow a bit slower due to its computational time O(n/2).

You can easily understand the difference just looking on these 3 functions on the graph. And it seems we have a winner O(log n).FYI for vocabulary with 4bln pages, the logarithmic function needs just 32 iterations to find the required word. And now you can image the power of this function.

Logarithmic function with small/big problem sizes.

The interesting thing is that not always the logarithmic function is beneficial. Let’s compare the following functions: 1/2×n^2 and 6n × log n
The first graph displays that logarithmic function is growing slowly than quadratic one.

However, let’s take a look more precisely and you can notice that this amazing result happens mostly for big digits. If we decrease n, you will see that the logarithmic function growing faster than quadratic function when we have the small input data.

Therefore, when you are working with small problems it would be profitable not to use algorithms which have the logarithmic computational time.

Wow, we know a little bit more! This topic is really interesting for me and I would glad to see your comments here. If you have some propositions or request please contact me.

Create a new iOS project

A good starting point is to create new iOS project. Just run Xcode and create new one. But before we proceed it would be better to install required libraries using cocoapods as dependency manager.

I’m sure you’re familiar with this dance already, however if you haven’t experience with Pods before please check official site and tutorials:

Let’s add ‘Firebase/Database’ library to the Podfile it would be enough for now.pod 'Firebase/Database'
Btw, if you want to get more info about Firebase libs check this link

Create new project in the Firebase console

Now let’s turn to Google Firebase. To create a new project just go here and don’t forget to choose “Add Firebase to your iOS app”.

The important thing here is to get the GoogleService.plist configuration file for your iOS project.

After downloading the file, keep it somewhere, we will need it soon. If you missed this step, you can download .plist from project settings at any time.

Connect to the Firebase DB

Now we need to go back our iOS project and connect to Firebase by putting on GoogleService.plist to the project Resources folder.
After this, check if you made a connection to the new database in AppDelegateFIRApp.configure().
Otherwise, you will get an error: Terminating app due to uncaught exception 'MissingDatabaseURL', reason: 'Failed to get FIRDatabase instance: FIRApp object has no databaseURL in its FirebaseOptions object.

And of course, please do not forget to put import Firebase.

Create first collections

Firebase based on NoSQL paradigm and if I’m not mistaken it uses MongoDB behind the scene, which requires quite a bit of providence. The more important thing you need to remember is how you are going to manipulate with data. The best way is to use nested data poorly and to focus on flatten data.

Pay attention that you haven’t an opportunity to see the db scheme at once. Usually Firebase creates collections dynamically as soon as first value appears.

On the off-chance, I provided several ways to come over this:
– Import already prepared json if you have such
– Add each collection and data manually
– Create collections dynamically

Ok, let’s start from dynamically creation of collections. Maybe it seems a bit scary, but It’s actually pretty simple. So, to work with our DB in the iOS app we need the basic building block that contains 4 classes(listed below) and enum called PostKeys:FIRManager – DB configurationPost – DataModelPostsService – To store all queriesObservePostManager – Interlayer for PostsService

I guess it would be better to show you simple “NoUML” scheme. Notice, the basic building block is circled with orange and the enum is colored by yellow:

The enum PostKeys plays a significant role. It reflects the Post’s collection structure.

For updating of object you can use directly the ref – reference of this object in DB, that’s why we defined this value var ref: FIRDatabaseReference? in DataModel class. In my opinion, it is really cool fancy tool.

So, let’s update our object. Just imagine that we created post which is not published yet and we are going to publish it using the following code:

And the last one is delete. Nothing special just use the ref as we did before.

class func removePost(post: Post) {
post.ref?.removeValue()
}

Create Observers and data sync

Now I am going to describe a really cool feature – observers. Observer is probably the most common scheduler operator you’ll use. Observers allow us to track DataModel changes without making special queries, which we used to write before. Let’s quickly investigate observeEventType it might prove its usefulness.

As you can see we created the query for getting post list, however, the key-words are observeEventType and Value.ObserveEventType – means that we are going to track itValue – means that we observe all value changes in what we try to observe (creating, removing, updating and so on…)

Sometimes we don’t need to observe child nodes and of course we can skip it. Decide yourself which ones you want to emit and which ones to skip.

Working with DateTime types

Additionally I would like to show you one of the possible ways to store DateTime values:

Last but not the least – rules

We will consider the rules in the following articles in details, but the only cryptic thing here that we need to change is default security rules.
Replace them to this one { "rules": { ".read": true, ".write": true } }
Because, as soon as you try to execute any db query, you will get an error:[FirebaseDatabase] setValue: or removeValue: at /post/POST_ID failed: permission_denied

Firebase is very simple and powerful service. And of course, there are a lot of things that I’ve not mentioned, but I hope my article will help to go through the basics.

You can read more about firebase at codelabs , guidelines and quickstart tutorials. Also if you have some questions, do not hesitate to ask me link or put your comments, I will be happy to help you.

]]>http://svitlanamoiseyenko.com/2016/08/23/firebase-as-baas-for-ios-app-part-1/feed/0Highly precised cubes or walls and how to create them in Unity3D.http://svitlanamoiseyenko.com/2016/08/12/highly-precised-cubes-walls-and-how-to-create-them-in-unity3d/
http://svitlanamoiseyenko.com/2016/08/12/highly-precised-cubes-walls-and-how-to-create-them-in-unity3d/#respondFri, 12 Aug 2016 14:04:32 +0000http://svitlanamoiseyenko.com/?p=1277You could ask me why we need this?
Just imagine you have a task where you need to create meshes with high precision. It could be anything: houses, walls, windows, doors, pictures, office facilities – in general everything… So how I did this?

What I am going to say firstly that it‘s very helpful to use following assets Mesh Maker and zzRuler.

Please pay attention that zzRuler is free asset but Mesh Maker isn’t. You can trust me that Mesh Maker is a good investment. It helped me a lot in everyday dev.

Step 2 – put rulers into your scene.

In folder zzRuler you can find two ruler prefabs: horizontal and vertical. I highlighted them on the screenshot below.

Currently, we need both of them. Moreover, we need 1 vertical and 2 horizontal rulers to measure height (y), width (x) and deep (z). Just drag them on Hierarchy Panel.

It should look like this to measure all at once.

Step 3 – create the wall

Put a cube on your scene, it will be our future wall. Please resize by using the ruler 1 x 1 x 1.

Then check the scale values in Inspector.
Don’t worry, if they don’t fit into the rulers’ one. Use Mesh Maker to reset the scale to 1:1:1.
To do this you should go Window → MeshMaker → Mesh Editor. Click the button Lock and save the mesh, let’s call it “wall”. Then just click the button Normalize and all scales will be reset to the 1:1:1.

Now your object is ready to be resized.

Step 4 – resize to appropriate sizes

Since now we have the scale 1m:1m:1m, we need to change wall’s scale to the appropriate size in meters 8m ✕ 4m ✕ 0.3m. Below you can see the result.

Step 5 – measure and resize Boxes

All of these steps you should repeat with boxes.
This is my final result with highly precise boxes and wall yay!