forked from bits-and-electrons/bloch-sphere-simulator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reformat code (bits-and-electrons#35)
- Loading branch information
Showing
12 changed files
with
159 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { | ||
Float | ||
} from "./float.js"; | ||
|
||
|
||
class Complex { | ||
constructor(real, img) { | ||
this.real = Float.round(real); | ||
this.img = Float.round(img); | ||
} | ||
|
||
toString() { | ||
if (this.img < 0) { | ||
return this.real.toString() + " - i * " + Float.abs(this.img).toString(); | ||
} | ||
else { | ||
return this.real.toString() + " + i * " + Float.abs(this.img).toString(); | ||
} | ||
} | ||
} | ||
|
||
|
||
export { | ||
Complex | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { | ||
Complex | ||
} from "./complex.js"; | ||
|
||
|
||
test("complex-test1", () => { | ||
expect( | ||
new Complex(2, 3).toString() | ||
).toBe("+2.0000 + i * 3.0000"); | ||
}); | ||
|
||
test("complex-test2", () => { | ||
expect( | ||
new Complex(3, -4).toString() | ||
).toBe("+3.0000 - i * 4.0000"); | ||
}); | ||
|
||
test("complex-test3", () => { | ||
expect( | ||
new Complex(-6, -7).toString() | ||
).toBe("-6.0000 - i * 7.0000"); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { | ||
PRECISION | ||
} from "./../constants.js"; | ||
|
||
|
||
class Float { | ||
// returns floating point number with given precision | ||
// adds sign as prefix for both positive and negative numbers | ||
static round(num, precision) { | ||
if (precision == null) { | ||
precision = PRECISION; | ||
} | ||
|
||
if (typeof num === "string") { | ||
num = parseFloat(num); | ||
} | ||
|
||
let result = parseFloat(num.toFixed(precision)).toFixed(precision); | ||
|
||
if (result >= 0) { | ||
result = "+" + result; | ||
} | ||
|
||
return result; | ||
} | ||
|
||
// returns absolute value of number with given precision | ||
// removes sign from prefix for both positive and negative numbers | ||
static abs(num, precision) { | ||
if (precision == null) { | ||
precision = PRECISION; | ||
} | ||
|
||
if (typeof num === "string") { | ||
num = parseFloat(num); | ||
} | ||
|
||
if (num < 0) { | ||
num *= -1; | ||
} | ||
|
||
let result = parseFloat(num.toFixed(precision)).toFixed(precision); | ||
|
||
return result; | ||
} | ||
} | ||
|
||
|
||
export { | ||
Float | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { | ||
Float | ||
} from "./float.js"; | ||
|
||
|
||
test("float-test1", () => { | ||
expect( | ||
Float.round("2.423451", 4) | ||
).toBe("+2.4235"); | ||
|
||
expect( | ||
Float.abs("2.423451", 4) | ||
).toBe("2.4235"); | ||
}); | ||
|
||
test("float-test2", () => { | ||
expect( | ||
Float.round("2.42", 4) | ||
).toBe("+2.4200"); | ||
|
||
expect( | ||
Float.abs("-2.423451", 4) | ||
).toBe("2.4235"); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import * as THREE from './../libs/three/three.module.js'; | ||
|
||
import { | ||
Float | ||
} from "./float.js"; | ||
|
||
|
||
class Vector3Helpers { | ||
static angleBetweenVectors(vector1, vector2, planeNormal) { | ||
let angle = THREE.Math.radToDeg(vector1.angleTo(vector2)); | ||
let crossProduct = new THREE.Vector3(); | ||
|
||
crossProduct.crossVectors(vector1, vector2); | ||
if (Float.round(crossProduct.dot(planeNormal)) < 0) { | ||
angle *= -1; | ||
} | ||
|
||
return angle; | ||
} | ||
} | ||
|
||
|
||
export { | ||
Vector3Helpers | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import { | ||
Complex | ||
} from "../mathutils.js"; | ||
} from "../math/complex.js"; | ||
|
||
import { | ||
BlochSphereState | ||
|