Tutorial by Examples: c

The C++14 standard is often referred to as a bugfix for C++11. It contains only a limited list of changes of which most are extensions to the new features in C++11. Below you can find an overview of the changes as they have been grouped on the isocpp FAQ with links to more detailed documentation. L...
Assume you want to delegate to a class but you do not want to provide the delegated-to class in the constructor parameter. Instead, you want to construct it privately, making the constructor caller unaware of it. At first this might seem impossible because class delegation allows to delegate only to...
Gson does not support inheritance out of the box. Let's say we have the following class hierarchy: public class BaseClass { int a; public int getInt() { return a; } } public class DerivedClass1 extends BaseClass { int b; @Override public int getI...
Struct defines new classes with the specified attributes and accessor methods. Person = Struct.new :first_name, :last_name You can then instantiate objects and use them: person = Person.new 'John', 'Doe' # => #<struct Person first_name="John", last_name="Doe"> p...
Person = Struct.new :name do def greet(someone) "Hello #{someone}! I am #{name}!" end end Person.new('Alice').greet 'Bob' # => "Hello Bob! I am Alice!"
The first thing to do is to add the service to AndroidManifest.xml, inside the <application> tag: <application ...> ... <service android:name=".RecordingService" <!--"enabled" tag specifies Whether or not the service can ...
List comprehensions can introduce local bindings for variables to hold some interim values: [(x,y) | x <- [1..4], let y=x*x+1, even y] -- [(1,2),(3,10)] Same effect can be achieved with a trick, [(x,y) | x <- [1..4], y <- [x*x+1], even y] -- [(1,2),(3,10)] The let in list compr...
// circle objects: { x:, y:, radius: } // return true if the 2 circles are colliding // c1 and c2 are circles as defined above function CirclesColliding(c1,c2){ var dx=c2.x-c1.x; var dy=c2.y-c1.y; var rSum=c1.radius+c2.radius; return(dx*dx+dy*dy<=rSum*rSum); }
// rectangle objects { x:, y:, width:, height: } // return true if the 2 rectangles are colliding // r1 and r2 are rectangles as defined above function RectsColliding(r1,r2){ return !( r1.x>r2.x+r2.width || r1.x+r1.width<r2.x || r1.y>r2.y+r2.height || ...
// rectangle object: { x:, y:, width:, height: } // circle object: { x:, y:, radius: } // return true if the rectangle and circle are colliding function RectCircleColliding(rect,circle){ var dx=Math.abs(circle.x-(rect.x+rect.width/2)); var dy=Math.abs(circle.y-(rect.y+rect.height/2));...
The function in this example returns true if two line segments are intersecting and false if not. The example is designed for performance and uses closure to hold working variables // point object: {x:, y:} // p0 & p1 form one segment, p2 & p3 form the second segment // Retur...
// [x0,y0] to [x1,y1] define a line segment // [cx,cy] is circle centerpoint, cr is circle radius function isCircleSegmentColliding(x0,y0,x1,y1,cx,cy,cr){ // calc delta distance: source point to line start var dx=cx-x0; var dy=cy-y0; // calc delta distance: line start to e...
// var rect={x:,y:,width:,height:}; // var line={x1:,y1:,x2:,y2:}; // Get interseting point of line segment & rectangle (if any) function lineRectCollide(line,rect){ // p=line startpoint, p2=line endpoint var p={x:line.x1,y:line.y1}; var p2={x:line.x2,y:line.y2}; // to...
Use the Separating Axis Theorem to determine if 2 convex polygons are intersecting THE POLYGONS MUST BE CONVEX Attribution: Markus Jarderot @ How to check intersection between 2 rotated rectangles? // polygon objects are an array of vertices forming the polygon // var polygon1=[{x:100,y:100}...
Tests all polygon sides for intersections to determine if 2 polygons are colliding. // polygon objects are an array of vertices forming the polygon // var polygon1=[{x:100,y:100},{x:150,y:150},{x:50,y:150},...]; // The polygons can be both concave and convex // return true if the 2 polygons ...
Tests if the [x,y] point is inside a closed arc. var arc={ cx:150, cy:150, innerRadius:75, outerRadius:100, startAngle:0, endAngle:Math.PI } function isPointInArc(x,y,arc){ var dx=x-arc.cx; var dy=y-arc.cy; var dxy=dx*dx+dy*dy; var rrOuter=arc.outerRadiu...
Tests if an [x,y] point is inside a circle. // circle objects: {cx:,cy:,radius:,startAngle:,endAngle:} // var circle={ // cx:150, cy:150, // centerpoint // radius:100, // } // Return true if the x,y point is inside the circle function isPointInCircle(x,y,circle){ var dx=x-circ...
Tests if an [x,y] point is inside a rectangle. // rectangle objects: {x:, y:, width:, height: } // var rect={x:10, y:15, width:25, height:20} // Return true if the x,y point is inside the rectangle function isPointInRectangle(x,y,rect){ return(x>rect.x && x<rect.x+rect.width...
Let us first create a simple .proto file person.proto package Protocol; message Person { required string firstName = 1; required string lastName = 2; optional int32 age = 3; } After saving we can now create the Haskell files which we can use in our project by running ...
Here the steps required to create a Firebase project and to connect it with an Android app. Add Firebase to your app Create a Firebase project in the Firebase console and click Create New Project. Click Add Firebase to your Android app and follow the setup steps. When prompted, enter...

Page 426 of 826