--- layout: post title: Enhancing OData support for streams date: 2010-10-18 17:45:53.000000000 +08:00 categories: - OData protocol - OData tutorials tags: [] status: publish type: post published: true author: OData.org Archive ---
OData has good support for streams via the ATOM concept of Media Link Entries (MLE) and Media Resources (MR).
 And the way that you access or learn about a Media Resource is via the associated Media Link Entry, which is just a special type of Entry which links to a Media Resource and includes additional metadata about it.
For example if you wanted to use OData to share Videos, you could model the metadata for the Video as an MLE and create a feed for these MLEs, then the actual video itself would become a Media Resource linked to from the MLE.
So using something like this to retrieve a particular MLE:
GET ~/Service/Videos(123123)
Might return something like this:
<entry m:etag="UVWXYZ">
<id>http://server/Service/Videos(123)</id>
<title>OData Named Resource Streams</title>
<summary>A short video about Named Resource Streams...<summary>
<updated>2010-08-21T08:27:16Z</updated>
<author>
<name />
</author>
<link m:etag="ABCDEF" rel="edit-media" title="Title" href="Videos(123)/$value" />
<content src="... uri to a picture to represent the video ..." />
<m:properties xmlns:m=" http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices">
<d:Id>123</d:Id>
<d:Synopsis> A short video about Named Resource Streams...</d:Synopsis>
<d:Name>OData Named Resource Streams </d:Name>
</m:properties>
</entry>
In this example the actual video (or Media Resource) can be found in the 'edit-media' link's href.
So far OData is just using standard ATOM support for media-resource.
But what happens though if you need multiple versions of that video?
For example High and Low bandwidth versions.
Today you could model this with multiple MLEs, but doing so implies you have different metadata for each stream, if note you end up with copies of the same metadata for each version of the stream. Clearly this is not desirable when you have multiple versions of essentially the same video, image or document.
It turns out that this is a very common scenario, common enough that we thought it needed to be supported without forcing people to use multiple MLEs.
Ideally you should be able to have something like this:
<entry m:etag="UVWXYZ">
<id>http://server/Service/Videos(123)</id>
<title>OData Named Resource Streams</title>
<summary>A short video about Named Resource Streams...<summary>
<updated>2010-08-21T08:27:16Z</updated>
<author>
<name />
</author>
<link m:etag="ABCDEF" rel="edit-media" title="Title" href="Videos(123)/$value" />
<link
rel=" http://schemas.microsoft.com/ado/2007/08/dataservices/edit-media/ HighBandwidth"
title="HighBandwidth"
href="Videos(123)/ HighBandwidth/$value" />
<link
rel=" http://schemas.microsoft.com/ado/2007/08/dataservices/edit-media/ LowBandwidth"
title="LowBandwidth"
href="Videos(123)/LowBandwidth/$value" />
<content src="... uri to a picture to represent the video ..." />
<m:properties xmlns:m=" http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices">
<d:Id>123</d:Id>
<d:Synopsis> A short video about Named Resource Streams...</d:Synopsis>
<d:Name>OData Named Resource Streams </d:Name>
</m:properties>
</entry>
This says there is some default representation of the video that can be downloaded from Videos(123)/$value (i.e. the standard Media Resource), and there are also High and LowBandwidth streams too.
Note: In the above example the URI's for the Named Resource Streams simply use the URI conventions, i.e. the uri that identifies the Named Stream property with $value appended. However the clients should be payload driven here, so a server should be able to return any uri they want.
To achieve this the metadata would need to look like this:
<EntityType Name="Video" m:HasStream="true">
<Key>
<PropertyRef Name="ID" />
</Key>
<Property Name="ID" Type="Edm.Int32" Nullable="false" />
<Property Name="Name" Type="Edm.String" Nullable="true" />
<Property Name="Synopsis" Type="Edm.String" Nullable="true" />
<Property Name="HighBandwidth" Type="Edm.Stream" />
<Property Name="LowBandwidth" Type="Edm.Stream" />
</EntityType>
Notice the extra streams are just extra properties on the item of type Edm.Stream. Here Edm.Stream is simply a new built-in complex type, with some explicit structure (MimeType) and an implicit stream.
I think this is a natural next step for OData's stream support.
What do you think?
Alex


Gdynia is one of the largest Polish yacht harbours as well as being a large and busy commercial port with ferries, container ships and a cruise ship terminal. The yacht harbour is in the southern part of the harbour with direct access to the Bay of Gdansk.
Position 54° 31'N, 18° 33'25"E (marina).
If clearance is required, moor at the Harbour Master's quay on arrival. He will arrange for Customs and Immigration clearance. Return to this quay for clearance on departure. The yacht may be searched.
This is a large container and cruise ship port on the western side of the Gulf of Gdansk. It is also home to the Polish Navy.
The yacht basin is at the southern breakwater entrance. South of this lies an attractive beach area with many pavement cafes. It is an active sailing centre and many regattas are held here.
It is advisable to call the marina in advance to request a berth.
Yachts must monitor VHF channel 12, but do not have to report their presence.


Welcome to EBDM’s documentation!¶
Requirements¶
Before getting started, make sure that you have the following libraries already installed
import pandas as pd
import math
Note
EBDM requires Python 3.x
Quick Install¶
In your source file, import the library and start using the functions step-by-step as mentioned in the below section
import EBDM as ebd
For accessing modules, use
ebd.<module_name>


Camden Trees
Council owned trees in the London borough of Camden.
Data from
Open Data Camden
, code on
GitHub
.


|
Scientific Fortran Tools (SciFT)
1.2
|
Data Types | |
| type | mathparser |
Public Member Functions | |
| subroutine, public | mathparser_test () |
| Test method. More... | |
Public Attributes | |
| integer, dimension(:), allocatable | ipos |
Private Member Functions | |
| subroutine | initdefault (this) |
| Constructor. More... | |
| subroutine | destroy (this) |
| Destructor. More... | |
| subroutine | parsefunction (this, funcStr, var) |
| Parse ith function string funcStr and compile it into bytecode. More... | |
| real(8) function | evaluatefunction (this, val) |
| Evaluate bytecode of ith function for the values passed in array Val(:) More... | |
| subroutine | checksyntax (this, func, funcStr, var) |
| Check syntax of function string, returns 0 if syntax is ok. More... | |
| character(len(error_message)) function | errormessage (this) |
| Return error message. More... | |
| subroutine | parseerrmsg (j, funcStr, msg) |
| Print error message and terminate program. More... | |
| integer function | operatorindex (c) |
| Return operator index. More... | |
| integer function | mathfunctionindex (str) |
| Return index of math function beginnig at 1st position of string str. More... | |
| integer function | variableindex (str, var, ibegin, inext) |
| Return index of variable at begin of string str (returns 0 if no variable found) More... | |
| subroutine | removespaces (str) |
| Remove Spaces from string, remember positions of characters in old string. More... | |
| subroutine | replace (ca, cb, str) |
| Replace ALL appearances of character set ca in string str by character set cb. More... | |
| subroutine | compile (this, f, var) |
| Compile i-th function string F into bytecode. More... | |
| recursive subroutine | compilesubstr (this, f, b, e, var) |
| Compile function string f into bytecode. More... | |
| subroutine | addcompiledbyte (this, b) |
| Add compiled byte to bytecode. More... | |
| integer function | mathitemindex (this, f, var) |
| Return math item index, if item is real number, enter it into Comp-structure. More... | |
| logical function | completelyenclosed (f, b, e) |
| Check if function substring F(b:e) is completely enclosed by a pair of parenthesis. More... | |
| logical function | isbinaryoperator (j, str) |
| Check if operator str(j:j) in string str is binary operator Special cases already covered elsewhere:( that is corrected in v1.1 ) operator character str(j:j) is first character of string (j=1) More... | |
| real(8) function | strtoreal (str, ibegin, inext, error) |
| Get real number from string - Format: [blanks][+|-][nnn][.nnn][e|E|d|D[+|-]nnn]. More... | |
| subroutine | tolowercase (str, lcStr) |
| Transform upper case letters in str into lower case letters. More... | |
Private Attributes | |
| real(8), parameter | zero = 0.0_8 |
| integer, parameter | c_immed = 1 |
| integer, parameter | c_neg = 2 |
| integer, parameter | c_add = 3 |
| integer, parameter | c_sub = 4 |
| integer, parameter | c_mul = 5 |
| integer, parameter | c_div = 6 |
| integer, parameter | c_pow = 7 |
| integer, parameter | c_abs = 8 |
| integer, parameter | c_exp = 9 |
| integer, parameter | c_log10 = 10 |
| integer, parameter | c_log = 11 |
| integer, parameter | c_sqrt = 12 |
| integer, parameter | c_sinh = 13 |
| integer, parameter | c_cosh = 14 |
| integer, parameter | c_tanh = 15 |
| integer, parameter | c_sin = 16 |
| integer, parameter | c_cos = 17 |
| integer, parameter | c_tan = 18 |
| integer, parameter | c_asin = 19 |
| integer, parameter | c_acos = 20 |
| integer, parameter | c_atan = 21 |
| integer, parameter | c_sgn = 22 |
| integer, parameter | c_ustep = 23 |
| integer, parameter | c_ubox = 24 |
| integer, parameter | c_varbegin = 25 |
| character(1), dimension(c_add:c_pow), parameter | str_operators = [ '+', '-', '*', '/', '^' ] |
| character(6), dimension(c_abs:c_ubox), parameter | str_functions = [ 'abs ', 'exp ', 'log10 ', 'log ', 'sqrt ', 'sinh ', 'cosh ', 'tanh ', 'sin ', 'cos ', 'tan ', 'asin ', 'acos ', 'atan ', 'sgn ', 'ustep ', 'ubox ' ] |
| character(*), dimension(4), parameter | error_message = [ 'Division by zero', 'Argument of SQRT negative', 'Argument of LOG negative', 'Argument of ASIN or ACOS illegal' ] |
Definition at line 64 of file MathParser.f90.
|
private |
Add compiled byte to bytecode.
Definition at line 705 of file MathParser.f90.
|
private |
Check syntax of function string, returns 0 if syntax is ok.
| func | Function string without spaces |
| funcStr | Original function string |
| var | Array with variable names |
Definition at line 318 of file MathParser.f90.
|
private |
Compile i-th function string F into bytecode.
| i | Function identifier |
| f | Function string |
| var | Array with variable names |
Definition at line 568 of file MathParser.f90.
|
private |
Compile function string f into bytecode.
| f | Function substring |
| b | Begin position substring |
| e | End position substring |
| var | Array with variable names |
Definition at line 613 of file MathParser.f90.
|
private |
Check if function substring F(b:e) is completely enclosed by a pair of parenthesis.
Definition at line 738 of file MathParser.f90.
|
private |
Destructor.
Definition at line 156 of file MathParser.f90.
|
private |
Return error message.
Definition at line 404 of file MathParser.f90.
|
private |
Evaluate bytecode of ith function for the values passed in array Val(:)
| val | Variable values |
Definition at line 202 of file MathParser.f90.
|
private |
Constructor.
Definition at line 145 of file MathParser.f90.
|
private |
Check if operator str(j:j) in string str is binary operator Special cases already covered elsewhere:( that is corrected in v1.1 ) operator character str(j:j) is first character of string (j=1)
| j | Position of Operator |
| str | String |
Definition at line 770 of file MathParser.f90.
|
private |
Return index of math function beginnig at 1st position of string str.
Definition at line 462 of file MathParser.f90.
|
private |
Return math item index, if item is real number, enter it into Comp-structure.
Definition at line 716 of file MathParser.f90.
| subroutine, public mathparser::mathparser_test | ( | ) |
Test method.
Definition at line 932 of file MathParser.f90.
|
private |
Return operator index.
Definition at line 444 of file MathParser.f90.
|
private |
Print error message and terminate program.
Definition at line 418 of file MathParser.f90.
|
private |
Parse ith function string funcStr and compile it into bytecode.
| funcStr | Function string |
| var | Array with variable names |
Definition at line 180 of file MathParser.f90.
|
private |
Remove Spaces from string, remember positions of characters in old string.
Definition at line 525 of file MathParser.f90.
|
private |
Replace ALL appearances of character set ca in string str by character set cb.
Definition at line 548 of file MathParser.f90.
|
private |
Get real number from string - Format: [blanks][+|-][nnn][.nnn][e|E|d|D[+|-]nnn].
| str | String to transform |
| ibegin | Start position of real number (OPTIONAL) |
| 1st | character after real number (OUTPUT,OPTIONAL) |
| error | Error flag (OPTIONAL) |
Definition at line 822 of file MathParser.f90.
|
private |
Transform upper case letters in str into lower case letters.
Definition at line 913 of file MathParser.f90.
|
private |
Return index of variable at begin of string str (returns 0 if no variable found)
| str | String |
| var | Array with variable names |
| n | Index of variable |
| ibegin | Start position of variable name |
| inext | Position of character after name |
Definition at line 490 of file MathParser.f90.
|
private |
Definition at line 81 of file MathParser.f90.
|
private |
Definition at line 93 of file MathParser.f90.
|
private |
Definition at line 75 of file MathParser.f90.
|
private |
Definition at line 92 of file MathParser.f90.
|
private |
Definition at line 94 of file MathParser.f90.
|
private |
Definition at line 90 of file MathParser.f90.
|
private |
Definition at line 87 of file MathParser.f90.
|
private |
Definition at line 78 of file MathParser.f90.
|
private |
Definition at line 82 of file MathParser.f90.
|
private |
Definition at line 73 of file MathParser.f90.
|
private |
Definition at line 84 of file MathParser.f90.
|
private |
Definition at line 83 of file MathParser.f90.
|
private |
Definition at line 77 of file MathParser.f90.
|
private |
Definition at line 74 of file MathParser.f90.
|
private |
Definition at line 79 of file MathParser.f90.
|
private |
Definition at line 95 of file MathParser.f90.
|
private |
Definition at line 89 of file MathParser.f90.
|
private |
Definition at line 86 of file MathParser.f90.
|
private |
Definition at line 85 of file MathParser.f90.
|
private |
Definition at line 76 of file MathParser.f90.
|
private |
Definition at line 91 of file MathParser.f90.
|
private |
Definition at line 88 of file MathParser.f90.
|
private |
Definition at line 97 of file MathParser.f90.
|
private |
Definition at line 96 of file MathParser.f90.
|
private |
Definition at line 99 of file MathParser.f90.
|
private |
Definition at line 109 of file MathParser.f90.
| integer, dimension(:), allocatable mathparser::ipos |
Definition at line 138 of file MathParser.f90.
|
private |
Definition at line 104 of file MathParser.f90.
|
private |
Definition at line 101 of file MathParser.f90.
|
private |
Definition at line 71 of file MathParser.f90.


public class OdometryPoseProvider extends java.lang.Object implements PoseProvider, MoveListener
A PoseProvider keeps track of the robot Pose
.
It does this using odometry (dead reckoning)
data contained in a Move
, which is supplied by a MoveProvider
. When the PoseProivder is constructed, it registers
as listener with its MoveProvider,
| Modifier and Type | Field and Description |
|---|---|
private float |
angle0 |
(package private) boolean |
current |
private float |
distance0 |
private float |
heading |
(package private) MoveProvider |
mp |
private float |
x |
private float |
y |
| Constructor and Description |
|---|
OdometryPoseProvider(MoveProvider mp)
Allocates a new OdometryPoseProivder and registers it with the MovePovider as a listener.
|
| Modifier and Type | Method and Description |
|---|---|
void |
fetchSample(float[] sample,
int offset) |
Pose |
getPose()
returns a new pose that represents the current location and heading of the robot.
|
void |
moveStarted(Move move,
MoveProvider mp)
called by a MoveProvider when movement starts
|
void |
moveStopped(Move move,
MoveProvider mp)
called by a MoveProvider when movement ends
|
private float |
normalize(float angle) |
int |
sampleSize() |
private void |
setHeading(float heading) |
void |
setPose(Pose aPose) |
private void |
setPosition(Point p) |
private void |
updatePose(Move event) |
private float x
private float y
private float heading
private float angle0
private float distance0
MoveProvider mp
boolean current
public OdometryPoseProvider(MoveProvider mp)
public Pose getPose()
getPose
in interface PoseProvider
public void moveStarted(Move move, MoveProvider mp)
moveStarted
in interface MoveListener
move
- - the event that just startedmp
- the MoveProvider that called this methodpublic void setPose(Pose aPose)
setPose
in interface PoseProvider
public void moveStopped(Move move, MoveProvider mp)
moveStopped
in interface MoveListener
move
- - the event that just startedmp
- private void updatePose(Move event)
private float normalize(float angle)
private void setPosition(Point p)
private void setHeading(float heading)
public int sampleSize()
public void fetchSample(float[] sample, int offset)


Mixture of logistic regressions parameters (H)estimation with (U)spectral methods. The main methods take d-dimensional inputs and a vector of binary outputs, and return parameters according to the GLMs mixture model (General Linear Model). For more details see chapter 3 in the PhD thesis of Mor-Absa Loum: <http://www.theses.fr/s156435>, available here <https://www.math.u-psud.fr/~loum/IMG/pdf/these.compressed-2.pdf>.
| Version: | 0.2-0 |
| Depends: | R (≥ 3.0.0) |
| Imports: | MASS, jointDiag, methods, pracma |
| Suggests: | devtools, flexmix, parallel, testthat, roxygen2, tensor, nloptr |
| Published: | 2018-06-14 |
| Author: | Benjamin Auder [aut,cre], Mor-Absa Loum [aut] |
| Maintainer: | Benjamin Auder <Benjamin.Auder at u-psud.fr> |
| License: | MIT + file LICENSE |
| NeedsCompilation: | yes |
| CRAN checks: | morpheus results |
| Reference manual: | morpheus.pdf |
| Package source: | morpheus_0.2-0.tar.gz |
| Windows binaries: | r-devel: morpheus_0.2-0.zip, r-release: morpheus_0.2-0.zip, r-oldrel: morpheus_0.2-0.zip |
| OS X binaries: | r-release: morpheus_0.2-0.tgz, r-oldrel: morpheus_0.2-0.tgz |
Please use the canonical form https://CRAN.R-project.org/package=morpheus to link to this page.


Their bodies are in a permanent, self-enforced state of rest; never opening their eyes, and using psychic energy to move
A Sloth Imp expelling psychic energy into small orbs, as it floats.
The Slothful imps are in a permanent state of rest and rarely move on their own. They lack motivation and are actually closely related to Wrathful and Lustful imps. They are very hard on themselves for being unable to contribute to the other imps, their mind so plagued with self-doubt and lack of purpose, they lay there, thinking of all the things they want to do, but can’t due to their vice. Other imps cannot communicate with them easily and view them as being lazy, further driving the barely functioning imps into a state of aware vegetation. They have a lot of potential that they cannot tap into without support from another imp and are good at mundane labor that does not acquire ambition. They’re bodies are soft, fluffy and limber due to their lack of movement, lack of self-care and low muscle density. Higher functioning sloth imps are strongly telepathic and can move their limbs with their minds/telepathy, because of their, their more aware of subtle changes in the environment, through their bodies, with their mind reacting quicker than their body can.
These fruits are packed with a dreamy, smooth flavor that helps the Sloth Imp use what little energy they have to enjoy them.
The Sloth Imp's wool is one of the softest, prised materials in Impla. They are used to make high-quality materials like pillows and cloth for wrapping wounds. Some Sloth Imps and taken away from their village in the dead of night for this wool. Wrath Imps have stepped in to oversee their safty.


Reservation ID:
Type:
Individual
Team
Senior Project
Date:
January
February
March
April
May
June
July
August
September
October
November
December
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
Start Time:
1
2
3
4
5
6
7
8
9
10
11
12
AM
PM
End Time:
1
2
3
4
5
6
7
8
9
10
11
12
AM
PM
Room:
1
2
3
4
5
6
1
2
3
4
5


In 2012, Dota 2 began as an official title for the World Cyber Games annual event at World Cyber Games 2012. ... Beginning in September 2013, the Association for Chinese eSports began a league, called the WPC ACE Dota 2 League, which had the largest third-party prize pool in Dota 2 eSports history at the time.
CrossFire is an online tactical first-person shooter for Microsoft Windows developed by Smilegate. The game was released in China by Tencent Games, with the company also acting as the exclusive agent service company. The tests for its software bugs were started publicly on April 2008.
Rules of Survival (RoS) is a free-to-play, multiplayer online battle royale game developed and published by NetEase Games. It claims to have more than 150 million players registered worldwide. As of May 30, 2018, the game was released on Steam. Unlike the free non-Steam version, however, the game was released with a price tag, offering "special gifts" with the purchase. The game was later taken down from Steam by June 13, 2018, and reinstated by June 28, 2018.
Tekken (Japanese: 鉄拳, "Iron Fist") is a fighting video game franchise created, developed, and published by Namco (later Bandai Namco Entertainment). ... The premise of each game in the main series documents the events of the King of Iron Fist Tournament, hosted by the Mishima Zaibatsu.
Mobile Legends: Bang Bang. Mobile Legends: Bang Bang is a multiplayer online battle arena (MOBA) mobile game developed and published by Moonton.
The NBA 2K series is a series of basketball simulation video games developed and released annually since 1999. ... The series was originally published by Sega, under the label Sega Sports, and is now published by 2K Sports. All of the games in the franchise have been developed by Visual Concepts.


Project Build a recipe app which allows users to import recipes through a public API (Spoonacular) or through OCR technology (rtesseract). The recipes can be saved and viewed through the mobile device which has the capability of reading the recipes to you! Saved recipes are searchable by name or ingredient.
Description Developed at a hackathon with a team consisting of:
2 Back End Devs
2 Front End Devs
1 iOS Dev
Project Build an employee tracking app which allowed managers to track where their employees spend time in the office through the use of iBeacon technology.
Role Back End Engineer
Tech ruby on rails, postgres, activerecord, bcrypt, heroku, minitest


About Me
I graduated from a program called Year Up where I did 6 months of technical training in IT. Once I completed my training, I earned the opportunity to Intern at facebook on the GMS App Op’s team as Marketing Intern. I worked with the internal fb teams, and was responsible for launching email campaigns for them. Currently I’m at Vaco onsite at Google as content analyst on the Google Search Ads Team. I’m there for a project that consist of analyzing advertisements and making proper updates to the ads to make sure only quality ads get produced. This results in our users having a positive experience with our ads.
I have a passion for learning new platforms and tools, which is what drove me to attend the Berkeley Extension Program, where I am learning Full Stack Programming. At the end of the program I will have acquired the skills and knowledge to become a web developer.
During my free time I enjoy trying out new restaurants, reading self help books and poetry, my latest obsession is Audible. I also enjoy going on short hikes and walks with my 5 year old daughter.


FitnessEvaluator()
Provides a way to evaluate the fitness of a program.
This is done by using the FitnessContext that is register with the Environment.
TData - The type of the program being evaluated.
TData


Creative - Competitive - Academic - Practical
Supporting a well-spent life, a bright career and entrepreneurship


“We stand for top quality templates.”
Feature Products
Latest Products
modern design
some content which shows the winter products of this city which has specialised in the manufacturing of luxury clothing
modern design
some content which shows the winter products of this city which has specialised in the manufacturing of luxury clothing
modern design
some content which shows the winter products of this city which has specialised in the manufacturing of luxury clothing


class Vector {
/**
* A 2D vector class that provides a wide range of vector operations.
* @summary View file: {@link https://github.com/GorillaBus/ddw/blob/master/src/class/BodyManager.js https://github.com/GorillaBus/ddw/blob/master/src/class/Shape.js}.
* @constructor
* @param {Object} settings - Json object with construction options.
* @param {Float} [settings.x=0] - Initial X vector component.
* @param {Float} [settings.y=0] - Initial Y vector component.
* @param {Float} [settings.length=0] - Initial vector magnitude or length.
* @param {Float} [settings.angle=0] - Initial vector angle in radians.
*/
constructor(settings) {
settings = settings || {};
settings.x = settings.x || 0;
settings.y = settings.y || 0;
settings.length = settings.length || 0;
settings.angle = settings.angle || 0;
this.x = settings.x;
this.y = settings.y;
if (settings.length) {
this.setLength(settings.length);
}
if (settings.angle) {
this.setAngle(settings.angle);
}
}
/**
* Sets the X component of the vector.
* @method
* @param {Float} magnitude - Vector magnitude over the X axis.
*/
setX(magnitude) {
this.x = magnitude;
}
/**
* Gets the X component of the vector.
* @method
* @returns {Float} Vector magnitude over the X axis.
*/
getX() {
return this.x;
}
/**
* Sets the Y component of the vector.
* @method
* @param {Float} magnitude - Vector magnitude over the Y axis.
*/
setY(magnitude) {
this.y = magnitude;
}
/**
* Gets the Y component of the vector.
* @method
* @returns {Float} Vector magnitude over the Y axis.
*/
getY() {
return this.y;
}
/**
* Sets the vector angle.
* @method
* @param {Float} angle - Angle in radians.
*/
setAngle(angle) {
let length = this.getLength();
this.x = Math.cos(angle) * length;
this.y = Math.sin(angle) * length;
}
/**
* Gets the current vector's angle.
* @method
* @returns {Float} The vector's angle in radians.
*/
getAngle() {
return Math.atan2(this.getY(), this.getX());
}
/**
* Sets the magnitude of the vector on it's current direction.
* @method
* @param {Float} length - The desired length for the vector.
*/
setLength(length) {
let angle = this.getAngle();
this.x = Math.cos(angle) * length;
this.y = Math.sin(angle) * length;
}
/**
* Gets the current length of the vector.
* @method
* @returns {Float} The current vector's length.
*/
getLength() {
return Math.sqrt(this.x * this.x + this.y * this.y);
}
/**
* Tells if the vector has a length different than 0.
* @method
* @returns {Boolean} True when the vector's length is different than 0, false either.
*/
hasLength() {
return this.x !== 0 || this.y !== 0;
}
/**
* Rotates the vector by a given angle in radians.
* @method
* @param {Float} angle - The rotation angle in radians.
*/
rotateBy(angle) {
const x = this.getX();
const y = this.getY();
this.x = x * Math.cos(angle) - y * Math.sin(angle);
this.y = x * Math.sin(angle) + y * Math.cos(angle);
}
/**
* Adds a given vector to the current vector, returning a new instance.
* @method
* @param {Vector} vector - A vector object.
* @returns {Vector} The resulting vector object.
*/
add(vector) {
return new Vector({ x: this.x + vector.getX(), y: this.y + vector.getY() });
}
/**
* Substracts a vector to the current vector, returning a new instance.
* @method
* @param {Vector} vector - A vector object.
* @returns {Vector} The resulting vector object.
*/
substract(vector) {
return new Vector({ x: this.x - vector.getX(), y: this.y - vector.getY() });
}
/**
* Muliplies the current vector by a given vector
* @method
* @param {Vector} vector - A vector object.
* @returns {Vector} The resulting vector object.
*/
multiply(value) {
return new Vector({ x: this.x * value, y: this.y * value });
}
/**
* Divides the current vector by a given vector.
* @method
* @param {Vector} vector - A vector object.
* @returns {Vector} The resulting vector object.
*/
divide(value) {
return new Vector({ x: this.x / value, y: this.y / value });
}
/**
* Adds a given vector to the current vector instance.
* @method
* @param {Vector} vector - A vector object.
*/
addTo(vector) {
this.x += vector.getX();
this.y += vector.getY();
}
/**
* Substracts a given vector from the current vector instance.
* @method
* @param {Vector} vector - A vector object.
*/
substractFrom(vector) {
this.x -= vector.getX();
this.y -= vector.getY();
}
/**
* Multiplies the current vector instance by a given vector.
* @method
* @param {Vector} vector - A vector object.
*/
multiplyBy(value) {
this.x *= value;
this.y *= value;
}
/**
* Divides the current vector instance by a given vector.
* @method
* @param {Vector} vector - A vector object.
*/
divideBy(value) {
this.x /= value;
this.y /= value;
}
/**
* Computes the dot product between the current instance and a given vector. Sometimes used to determine the relative position between the two vectors:
 <0 means B is behind
 =0 means B is in front
 >0 means B is at left/rights used to find the position of vector A with respect to vector B:

* @method
* @param {Vector} vector - A vector object.
* @returns {Float} The dot product between the two vectors.
*/
dot(vector) {
return this.x * vector.x + this.y * vector.y;
}
/**
* Computes the cross product between the current instance and a given vector.
* @method
* @param {Vector} vector - A vector object.
* @returns {Float} The cross product between the two vectors.
*/
cross(vector) {
return (this.x * vector.y) - (this.y * vector.x);
}
/**
* Computes the perpendicular dot product (or outer product) between two vectors to find the intersection point between the two given vectors.
* @method
* @param {Vector} vector - A vector object.
* @returns {Vector} A vector object representing the intersection point between the two vectors.
*/
perpDot(vector) {
const v3 = this.substract(vector);
const t = v3.cross(vector) / this.cross(vector);
return new Vector({
x: this.getX() + vector.getX() * t,
y: this.getY() + vector.getY() * t
});
}
/**
* Computes the perpendicular vector from the defined from the current Vector instance to the given Vector.
* @method
* @param {Vector} vector - A vector object.
* @returns {Array} A an array of Vector objects (left and right)
*/
perpTo(vector) {
const fromTarget = this.substract(vector);
fromTarget.normalize();
const perpLeft = new ddw.Vector({
x: fromTarget.getY(),
y: -fromTarget.getX(),
length: 1
});
const perpRight = new ddw.Vector({
x: -fromTarget.getY(),
y: fromTarget.getX(),
length: 1
});
return [ perpLeft, perpRight ];
}
/**
* Computes the vector projection of the current instance along the given vector.
* @method
* @param {Vector} vector - A vector object.
* @returns {Vector} A new vector instance representing the computed projection.
*/
project(v) {
const d = vector.dot(vector);
if (d > 0) {
const dp = this.dot(vector);
const factor = dp / d;
const rx = vector.copy();
rx.multiplyBy(factor);
return rx;
}
return new Vector();
}
/**
* Computes the angle (in radians) formed between the current instance and a given vector.
* @method
* @param {Vector} vector - A vector object.
* @returns {Float} Angle in radians.
*/
angleBetween(vector) {
let v1 = this.copy();
let v2 = vector.copy();
v1.normalize();
v2.normalize();
let dot = v1.dot(v2);
let theta = Math.acos(dot);
if (isNaN(theta)) {
console.warn("Theta is 'NaN' on Vector.angleBetween()")
}
return theta;
}
/**
* Returns the direction of the current vector's with respect to a given vector. The result is interpreted as:
 =0 in front
 -1 to the right
 =1 to the left
* @method
* @param {Vector} vector - A vector object.
* @returns {Int} One integer of [-1, 0, 1] interpreted as "right", "in front", "left".
*/
angleDirection(vector) {
let crossProduct = this.cross(vector);
if (crossProduct > 0.0) {
return 1;
} else if (crossProduct < 0.0) {
return -1;
} else {
return 0;
}
}
/**
* Returns the angular difference betwee the current vector and a given vector
* @method
* @param {Vector} vector - A vector object.
* @returns {Float} Angle in radians.
*/
angleDifference(vector) {
let theta = this.angleBetween(vector);
let dir = this.angleDirection(vector);
return theta * dir;
}
/**
* Creates a copy of the current instance.
* @method
* @returns {Vector} A copy of the current instance.
*/
copy() {
return new Vector({
x: this.getX(),
y: this.getY()
});
}
/**
* Normalized the current vector instance converting it's magnitude to a value between 0 and 1.
* @method
*/
normalize() {
var length = this.getLength();
if (length != 0) {
this.divideBy(length);
}
}
/**
* Computes the distance between the current instance and a given vector.
* @method
* @param {Vector} vector - A vector object.
* @returns {Float} The distance between the two vector.
*/
dist(vector) {
let d = vector.substract(this);
return d.getLength();
}
/**
* Truncates the current instance's magnitude by a maximum value.
* @method
* @param {Float} max - The maximum magnitud for the vector's length.
*/
limit(max) {
if (this.getLength() > max) {
this.setLength(max);
}
}
/**
* Resets the current instance's x and y components to 0.
* @method
*/
reset() {
this.x = 0;
this.y = 0;
}
};
module.exports = Vector;