local solution = {} function solution.removeEveryThird(str) local iters = math.ceil(#str/3) local result = "" local iter = 1 for i=1, iters do result = result..str:sub(iter, iter+2) iter = iter + 4 end return result end return solution
function removeEveryThird(str) {// Remove the third character from every work in the string// using a zero based indexreturn 'heloword';}- local solution = {}
- function solution.removeEveryThird(str)
- local iters = math.ceil(#str/3)
- local result = ""
- local iter = 1
- for i=1, iters do
- result = result..str:sub(iter, iter+2)
- iter = iter + 4
- end
- return result
- end
- return solution
local solution = require 'solution' describe("removeEveryThird", function() local function testing(str, expect) local actual = solution.removeEveryThird(str) assert.are.same(expect, actual) end it("basic tests", function() testing("hello world", "helo wrld") end) end)
const chai = require("chai");const assert = chai.assert;- local solution = require 'solution'
describe("Solution", function() {it("This test passes", function() {assert.strictEqual(removeEveryThird('hello world'), 'heloword');});it("This test fails (fix code - not test)", function() {assert.strictEqual(removeEveryThird('how you doing'), 'howyoudoin');});it("This test fails (fix code - not test)", function() {assert.strictEqual(removeEveryThird('abc'), 'abc');});it("This test fails (fix code - not test)", function() {assert.strictEqual(removeEveryThird('1234 56789 10112314'), '123 5679 1012314');});});- describe("removeEveryThird", function()
- local function testing(str, expect)
- local actual = solution.removeEveryThird(str)
- assert.are.same(expect, actual)
- end
- it("basic tests", function()
- testing("hello world", "helo wrld")
- end)
- end)
local solution = {} function solution.getOutput(num) local result=""..(num%3==0 and "Fizz" or "")..(num%5==0 and "Buzz" or "") return result == "" and tostring(num) or result end return solution
public class FizzBuzz{public string GetOutput(int number){if ((number % 3 == 0) && (number % 5 == 0))return "FizzBuzz";- local solution = {}
else if (number % 3 == 0)return "Fizz";- function solution.getOutput(num)
- local result=""..(num%3==0 and "Fizz" or "")..(num%5==0 and "Buzz" or "")
- return result == "" and tostring(num) or result
- end
else if (number % 5 == 0)return "Buzz";else return number.ToString();}}- return solution
local solution = require 'solution' describe("FizzBuzz", function() local function testing(num, expect) local actual = solution.getOutput(num) assert.are.same(expect, actual) end it("basic tests", function() testing(3, "Fizz") testing(5, "Buzz") testing(15, "FizzBuzz") end) end)
namespace Solution {using NUnit.Framework;[TestFixture]public class SolutionTest{[Test]public void GetOutput_InputIsDivisibleBy3_ReturnFizz(){var fizzbuzz = new FizzBuzz();var result = fizzbuzz.GetOutput(3);Assert.That(result, Is.EqualTo("Fizz"));}[Test]public void GetOutput_InputIsDivisibleBy5_ReturnBuzz(){var fizzbuzz = new FizzBuzz();var result = fizzbuzz.GetOutput(5);Assert.That(result, Is.EqualTo("Buzz"));}[Test]public void GetOutput_InputIsDivisibleBy5And3_ReturnFizzBuzz(){var fizzbuzz = new FizzBuzz();var result = fizzbuzz.GetOutput(15);Assert.That(result, Is.EqualTo("FizzBuzz"));}}}- local solution = require 'solution'
- describe("FizzBuzz", function()
- local function testing(num, expect)
- local actual = solution.getOutput(num)
- assert.are.same(expect, actual)
- end
- it("basic tests", function()
- testing(3, "Fizz")
- testing(5, "Buzz")
- testing(15, "FizzBuzz")
- end)
- end)
local solution = {} function solution.riddle(str) return #str-1 end return solution
def riddle(word):return len(word) - 1- local solution = {}
- function solution.riddle(str)
- return #str-1
- end
- return solution
local solution = require 'solution' describe("riddle", function() local function testing(str, expect) local actual = solution.riddle(str) assert.are.same(expect, actual) end it("basic tests", function() testing("Two?", 3) testing("Ten?", 3) testing("Three?", 5) end) end)
test.assert_equals(riddle("Two?"), 3)test.assert_equals(riddle("Ten?"), 3)test.assert_equals(riddle("Three?"), 5)- local solution = require 'solution'
- describe("riddle", function()
- local function testing(str, expect)
- local actual = solution.riddle(str)
- assert.are.same(expect, actual)
- end
- it("basic tests", function()
- testing("Two?", 3)
- testing("Ten?", 3)
- testing("Three?", 5)
- end)
- end)
#!/usr/bin/lua local solution = {} function solution.sort_values(arr) table.sort(arr, function(a, b) return a < b end) return arr end return solution
from __future__ import annotationsfrom collections import Counter- #!/usr/bin/lua
def sort_values(vals:list[int]) -> list[int]:#Given an array of size N containing only 0s, 1s, and 2s;#sort the array in ascending order.assert set(vals) <= {0,1,2}return counting_sort(vals)# O(n+k) instead of n log(n)- local solution = {}
def counting_sort(vals:list[T]) -> list[T]:res = []c = Counter(vals)for k,amt in sorted(c.items()):res += [k]*amtreturn res- function solution.sort_values(arr)
- table.sort(arr, function(a, b) return a < b end)
- return arr
- end
- return solution
local solution = require 'solution' describe("sort_values", function() local function testing(arr, expect) local actual = solution.sort_values(arr) assert.are.same(expect, actual) end it("basic tests", function() testing({0, 0, 2, 0, 1, 1, 2, 0}, {0, 0, 0, 0, 1, 1, 2, 2}) testing({2, 0, 1, 2}, {0, 1, 2, 2}) end) end)
test.assert_equals(sort_values( [0,0,2,0,1,1,2,0]), [0,0,0,0,1,1,2,2] )test.assert_equals(sort_values([2, 0, 1, 2]), [0, 1, 2, 2])- local solution = require 'solution'
- describe("sort_values", function()
- local function testing(arr, expect)
- local actual = solution.sort_values(arr)
- assert.are.same(expect, actual)
- end
- it("basic tests", function()
- testing({0, 0, 2, 0, 1, 1, 2, 0},
- {0, 0, 0, 0, 1, 1, 2, 2})
- testing({2, 0, 1, 2},
- {0, 1, 2, 2})
- end)
- end)
float scalar_product(Vector3D a, Vector3D b) { return (a.get_x()*b.get_x() + a.get_y()*b.get_y() + a.get_z()*b.get_z()); } bool intersec(Segment a, Segment b) { Segment seg; float t1 = 0, t2 = 0, t = 0; t1+= scalar_product(a.start-b.start, b.end-b.start)*scalar_product(b.end-b.start, a.end-a.start); t1-= scalar_product(a.start-b.start, a.end-a.start)*scalar_product(b.end-b.start, b.end-b.start); t2+= scalar_product(a.end-a.start, a.end-a.start)*scalar_product(b.end-b.start, b.end-b.start); t2-= scalar_product(a.end-a.start, b.end-b.start)*scalar_product(b.end-b.start, a.end-a.start); t = t1/t2; float u1 = 0, u2 = 0; u1+= (scalar_product(a.start-b.start, b.end-b.start)); u1+= t*scalar_product(a.end-a.start, b.end-b.start); u2 = scalar_product(b.end-b.start, b.end-b.start); seg.end = a.start + (a.end - a.start)*t; seg.start = b.start + (b.end - b.start)*u1/u2; Vector3D tmp = seg.end - seg.start; Vector3D close_point = (seg.end + seg.start) / 2; try { if (t2 == 0 || u2 == 0) throw std::string("error"); if (scalar_product(close_point - a.start, a.end - a.start) < 0 || scalar_product(close_point - a.end, a.start - a.end) < 0) throw std::string("error"); if (scalar_product(close_point - b.start, b.end - b.start) < 0 || scalar_product(close_point - b.end, b.start - b.end) < 0) throw std::string("error"); if ((scalar_product(tmp, tmp) - 0.001) > 0) throw std::string("error"); } catch(const std::string& ex) { return false; } return true; }
- float scalar_product(Vector3D a, Vector3D b)
- {
- return (a.get_x()*b.get_x() + a.get_y()*b.get_y() + a.get_z()*b.get_z());
- }
- bool intersec(Segment a, Segment b)
- {
- Segment seg;
- float t1 = 0, t2 = 0, t = 0;
- t1+= scalar_product(a.start-b.start, b.end-b.start)*scalar_product(b.end-b.start, a.end-a.start);
- t1-= scalar_product(a.start-b.start, a.end-a.start)*scalar_product(b.end-b.start, b.end-b.start);
- t2+= scalar_product(a.end-a.start, a.end-a.start)*scalar_product(b.end-b.start, b.end-b.start);
- t2-= scalar_product(a.end-a.start, b.end-b.start)*scalar_product(b.end-b.start, a.end-a.start);
- t = t1/t2;
- float u1 = 0, u2 = 0;
- u1+= (scalar_product(a.start-b.start, b.end-b.start));
- u1+= t*scalar_product(a.end-a.start, b.end-b.start);
- u2 = scalar_product(b.end-b.start, b.end-b.start);
- seg.end = a.start + (a.end - a.start)*t;
- seg.start = b.start + (b.end - b.start)*u1/u2;
- Vector3D tmp = seg.end - seg.start;
- Vector3D close_point = (seg.end + seg.start) / 2;
- try
- {
- if (t2 == 0 || u2 == 0)
throw std::string("input segments are the same");- throw std::string("error");
- if (scalar_product(close_point - a.start, a.end - a.start) < 0 ||
- scalar_product(close_point - a.end, a.start - a.end) < 0)
throw std::string("point outside first segment bound");- throw std::string("error");
- if (scalar_product(close_point - b.start, b.end - b.start) < 0 ||
- scalar_product(close_point - b.end, b.start - b.end) < 0)
throw std::string("point outside second segment boundaries");- throw std::string("error");
- if ((scalar_product(tmp, tmp) - 0.001) > 0)
throw std::string("no intersection point");- throw std::string("error");
- }
- catch(const std::string& ex)
- {
std::cerr << ex << '\n';exit(1);}if ((scalar_product(tmp, tmp) - 0.001) < 0)return true;return false;- return false;
- }
- return true;
- }
Describe(segment_intersec) { It(intersec_test) { Assert::That(intersec(Segment(Vector3D(1, 0, 0), Vector3D(-1, 0, 0)), Segment(Vector3D(0, 1, 1), Vector3D(0, -1, -1))), IsTrue()); } It(dont_intersec_test) { Assert::That(intersec(Segment(Vector3D(3, 0, 1), Vector3D(3, 4, 1)), Segment(Vector3D(0, 5, 1), Vector3D(5, 5, 1))), IsFalse()); } It(collinear_test) { Assert::That(intersec(Segment(Vector3D(0, 0, 0), Vector3D(2, 0, 0)), Segment(Vector3D(1, 0, 0), Vector3D(3, 0, 0))), IsFalse()); } };
- Describe(segment_intersec)
- {
It(simple_test)- It(intersec_test)
- {
- Assert::That(intersec(Segment(Vector3D(1, 0, 0), Vector3D(-1, 0, 0)), Segment(Vector3D(0, 1, 1), Vector3D(0, -1, -1))), IsTrue());
- }
- It(dont_intersec_test)
- {
- Assert::That(intersec(Segment(Vector3D(3, 0, 1), Vector3D(3, 4, 1)), Segment(Vector3D(0, 5, 1), Vector3D(5, 5, 1))), IsFalse());
- }
- It(collinear_test)
- {
- Assert::That(intersec(Segment(Vector3D(0, 0, 0), Vector3D(2, 0, 0)), Segment(Vector3D(1, 0, 0), Vector3D(3, 0, 0))), IsFalse());
- }
- };
float scalar_product(Vector3D a, Vector3D b) { return (a.get_x()*b.get_x() + a.get_y()*b.get_y() + a.get_z()*b.get_z()); } bool intersec(Segment a, Segment b) { Segment seg; float t1 = 0, t2 = 0, t = 0; t1+= scalar_product(a.start-b.start, b.end-b.start)*scalar_product(b.end-b.start, a.end-a.start); t1-= scalar_product(a.start-b.start, a.end-a.start)*scalar_product(b.end-b.start, b.end-b.start); t2+= scalar_product(a.end-a.start, a.end-a.start)*scalar_product(b.end-b.start, b.end-b.start); t2-= scalar_product(a.end-a.start, b.end-b.start)*scalar_product(b.end-b.start, a.end-a.start); t = t1/t2; float u1 = 0, u2 = 0; u1+= (scalar_product(a.start-b.start, b.end-b.start)); u1+= t*scalar_product(a.end-a.start, b.end-b.start); u2 = scalar_product(b.end-b.start, b.end-b.start); seg.end = a.start + (a.end - a.start)*t; seg.start = b.start + (b.end - b.start)*u1/u2; Vector3D tmp = seg.end - seg.start; Vector3D close_point = (seg.end + seg.start) / 2; try { if (t2 == 0 || u2 == 0) throw std::string("input segments are the same"); if (scalar_product(close_point - a.start, a.end - a.start) < 0 || scalar_product(close_point - a.end, a.start - a.end) < 0) throw std::string("point outside first segment bound"); if (scalar_product(close_point - b.start, b.end - b.start) < 0 || scalar_product(close_point - b.end, b.start - b.end) < 0) throw std::string("point outside second segment boundaries"); if ((scalar_product(tmp, tmp) - 0.001) > 0) throw std::string("no intersection point"); } catch(const std::string& ex) { std::cerr << ex << '\n'; return false; } return true; }
- float scalar_product(Vector3D a, Vector3D b)
- {
- return (a.get_x()*b.get_x() + a.get_y()*b.get_y() + a.get_z()*b.get_z());
- }
- bool intersec(Segment a, Segment b)
- {
- Segment seg;
- float t1 = 0, t2 = 0, t = 0;
- t1+= scalar_product(a.start-b.start, b.end-b.start)*scalar_product(b.end-b.start, a.end-a.start);
- t1-= scalar_product(a.start-b.start, a.end-a.start)*scalar_product(b.end-b.start, b.end-b.start);
- t2+= scalar_product(a.end-a.start, a.end-a.start)*scalar_product(b.end-b.start, b.end-b.start);
- t2-= scalar_product(a.end-a.start, b.end-b.start)*scalar_product(b.end-b.start, a.end-a.start);
- t = t1/t2;
- float u1 = 0, u2 = 0;
- u1+= (scalar_product(a.start-b.start, b.end-b.start));
- u1+= t*scalar_product(a.end-a.start, b.end-b.start);
- u2 = scalar_product(b.end-b.start, b.end-b.start);
- seg.end = a.start + (a.end - a.start)*t;
- seg.start = b.start + (b.end - b.start)*u1/u2;
- Vector3D tmp = seg.end - seg.start;
- Vector3D close_point = (seg.end + seg.start) / 2;
- try
- {
- if (t2 == 0 || u2 == 0)
- throw std::string("input segments are the same");
- if (scalar_product(close_point - a.start, a.end - a.start) < 0 ||
- scalar_product(close_point - a.end, a.start - a.end) < 0)
- throw std::string("point outside first segment bound");
- if (scalar_product(close_point - b.start, b.end - b.start) < 0 ||
- scalar_product(close_point - b.end, b.start - b.end) < 0)
- throw std::string("point outside second segment boundaries");
- if ((scalar_product(tmp, tmp) - 0.001) > 0)
- throw std::string("no intersection point");
- }
- catch(const std::string& ex)
- {
- std::cerr << ex << '\n';
exit(1);- return false;
- }
if ((scalar_product(tmp, tmp) - 0.001) < 0)return true;return false;- return true;
- }
Describe(segment_intersec) { It(simple_test) { Assert::That(intersec(Segment(Vector3D(1, 0, 0), Vector3D(-1, 0, 0)), Segment(Vector3D(0, 1, 1), Vector3D(0, -1, -1))), IsTrue()); Assert::That(intersec(Segment(Vector3D(1, 0, 0), Vector3D(-1, 0, 0)), Segment(Vector3D(0, 1, 1), Vector3D(0, 1, -1))), IsFalse()); } };
- Describe(segment_intersec)
- {
- It(simple_test)
- {
- Assert::That(intersec(Segment(Vector3D(1, 0, 0), Vector3D(-1, 0, 0)), Segment(Vector3D(0, 1, 1), Vector3D(0, -1, -1))), IsTrue());
- Assert::That(intersec(Segment(Vector3D(1, 0, 0), Vector3D(-1, 0, 0)), Segment(Vector3D(0, 1, 1), Vector3D(0, 1, -1))), IsFalse());
- }
- };
There is a vector class consisting of 3 coordinates:
class Vector3D
{
private:
float x;
float y;
float z;
public:
Vector3D();
Vector3D(float x, float y, float z);
Vector3D(const Vector3D &v);
float get_x();
float get_y();
float get_z();
void set_x(float x);
void set_y(float y);
void set_z(float z);
};
And a segment class consisting of 2 vectors:
class Segment
{
public:
Vector3D start;
Vector3D end;
Segment();
Segment(Vector3D start, Vector3D end);
};
The task is to write a function that finds the intersection of two segments and return true || false value, if it exists. And return 'error' msg in other way.
float scalar_product(Vector3D a, Vector3D b) { return (a.get_x()*b.get_x() + a.get_y()*b.get_y() + a.get_z()*b.get_z()); } bool intersec(Segment a, Segment b) { Segment seg; float t1 = 0, t2 = 0, t = 0; t1+= scalar_product(a.start-b.start, b.end-b.start)*scalar_product(b.end-b.start, a.end-a.start); t1-= scalar_product(a.start-b.start, a.end-a.start)*scalar_product(b.end-b.start, b.end-b.start); t2+= scalar_product(a.end-a.start, a.end-a.start)*scalar_product(b.end-b.start, b.end-b.start); t2-= scalar_product(a.end-a.start, b.end-b.start)*scalar_product(b.end-b.start, a.end-a.start); t = t1/t2; float u1 = 0, u2 = 0; u1+= (scalar_product(a.start-b.start, b.end-b.start)); u1+= t*scalar_product(a.end-a.start, b.end-b.start); u2 = scalar_product(b.end-b.start, b.end-b.start); seg.end = a.start + (a.end - a.start)*t; seg.start = b.start + (b.end - b.start)*u1/u2; Vector3D tmp = seg.end - seg.start; Vector3D close_point = (seg.end + seg.start) / 2; try { if (t2 == 0 || u2 == 0) throw std::string("input segments are the same"); if (scalar_product(close_point - a.start, a.end - a.start) < 0 || scalar_product(close_point - a.end, a.start - a.end) < 0) throw std::string("point outside first segment bound"); if (scalar_product(close_point - b.start, b.end - b.start) < 0 || scalar_product(close_point - b.end, b.start - b.end) < 0) throw std::string("point outside second segment boundaries"); if ((scalar_product(tmp, tmp) - 0.001) > 0) throw std::string("no intersection point"); } catch(const std::string& ex) { std::cerr << ex << '\n'; exit(1); } if ((scalar_product(tmp, tmp) - 0.001) < 0) return true; return false; }
- float scalar_product(Vector3D a, Vector3D b)
- {
- return (a.get_x()*b.get_x() + a.get_y()*b.get_y() + a.get_z()*b.get_z());
- }
Vector3D intersec(Segment a, Segment b)- bool intersec(Segment a, Segment b)
- {
- Segment seg;
- float t1 = 0, t2 = 0, t = 0;
- t1+= scalar_product(a.start-b.start, b.end-b.start)*scalar_product(b.end-b.start, a.end-a.start);
- t1-= scalar_product(a.start-b.start, a.end-a.start)*scalar_product(b.end-b.start, b.end-b.start);
- t2+= scalar_product(a.end-a.start, a.end-a.start)*scalar_product(b.end-b.start, b.end-b.start);
- t2-= scalar_product(a.end-a.start, b.end-b.start)*scalar_product(b.end-b.start, a.end-a.start);
- t = t1/t2;
- float u1 = 0, u2 = 0;
- u1+= (scalar_product(a.start-b.start, b.end-b.start));
- u1+= t*scalar_product(a.end-a.start, b.end-b.start);
- u2 = scalar_product(b.end-b.start, b.end-b.start);
- seg.end = a.start + (a.end - a.start)*t;
- seg.start = b.start + (b.end - b.start)*u1/u2;
- Vector3D tmp = seg.end - seg.start;
- Vector3D close_point = (seg.end + seg.start) / 2;
- try
- {
- if (t2 == 0 || u2 == 0)
- throw std::string("input segments are the same");
- if (scalar_product(close_point - a.start, a.end - a.start) < 0 ||
- scalar_product(close_point - a.end, a.start - a.end) < 0)
- throw std::string("point outside first segment bound");
- if (scalar_product(close_point - b.start, b.end - b.start) < 0 ||
- scalar_product(close_point - b.end, b.start - b.end) < 0)
- throw std::string("point outside second segment boundaries");
- if ((scalar_product(tmp, tmp) - 0.001) > 0)
- throw std::string("no intersection point");
- }
- catch(const std::string& ex)
- {
- std::cerr << ex << '\n';
- exit(1);
- }
return close_point;- if ((scalar_product(tmp, tmp) - 0.001) < 0)
- return true;
- return false;
- }
Describe(segment_intersec) { It(simple_test) { Assert::That(intersec(Segment(Vector3D(1, 0, 0), Vector3D(-1, 0, 0)), Segment(Vector3D(0, 1, 1), Vector3D(0, -1, -1))), IsTrue()); } };
Vector3D::Vector3D(){}Vector3D::Vector3D(float x, float y, float z):x(x), y(y), z(z){}Vector3D::Vector3D(const Vector3D &v): x(v.x), y(v.y), z(v.z){}const float Vector3D::get_x(){return x;}const float Vector3D::get_y(){return y;}const float Vector3D::get_z(){return z;}void Vector3D::set_x(float x){this->x = x;}void Vector3D::set_y(float y){this->y = y;}void Vector3D::set_z(float z){this->z = z;}Vector3D& Vector3D::operator=(const Vector3D &v)- Describe(segment_intersec)
- {
x = v.x;y = v.y;z = v.z;return *this;}Vector3D Vector3D::operator+(const Vector3D &v){return Vector3D(x+v.x, y+v.y, z+v.z);}Vector3D Vector3D::operator-(const Vector3D &v){return Vector3D(x-v.x, y-v.y, z-v.z);}Vector3D Vector3D::operator*(const float &value){return Vector3D(x*value, y*value, z*value);}Vector3D Vector3D::operator/(const float &value){return Vector3D(x/value, y/value, z/value);}Segment::Segment(){};Segment::Segment(Vector3D start, Vector3D end): start(start), end(end){}Describe(any_group_name_you_want){It(should_do_something)- It(simple_test)
- {
Assert::That("some value", Equals("another value"));- Assert::That(intersec(Segment(Vector3D(1, 0, 0), Vector3D(-1, 0, 0)), Segment(Vector3D(0, 1, 1), Vector3D(0, -1, -1))), IsTrue());
- }
- };
There is a vector class consisting of 3 coordinates and a segment class consisting of 2 vectors. The task is to write a function that finds the intersection of two segments, if it exists.
The idea of solving the problem is to find the minimum distance between the segments, and if it is less than a certain specified value, then we can assume that the segments intersect.
float scalar_product(Vector3D a, Vector3D b)
{
return (a.get_x()*b.get_x() + a.get_y()*b.get_y() + a.get_z()*b.get_z());
}
Vector3D intersec(Segment a, Segment b)
{
Segment seg;
float t1 = 0, t2 = 0, t = 0;
t1+= scalar_product(a.start-b.start, b.end-b.start)*scalar_product(b.end-b.start, a.end-a.start);
t1-= scalar_product(a.start-b.start, a.end-a.start)*scalar_product(b.end-b.start, b.end-b.start);
t2+= scalar_product(a.end-a.start, a.end-a.start)*scalar_product(b.end-b.start, b.end-b.start);
t2-= scalar_product(a.end-a.start, b.end-b.start)*scalar_product(b.end-b.start, a.end-a.start);
t = t1/t2;
float u1 = 0, u2 = 0;
u1+= (scalar_product(a.start-b.start, b.end-b.start));
u1+= t*scalar_product(a.end-a.start, b.end-b.start);
u2 = scalar_product(b.end-b.start, b.end-b.start);
seg.end = a.start + (a.end - a.start)*t;
seg.start = b.start + (b.end - b.start)*u1/u2;
Vector3D tmp = seg.end - seg.start;
Vector3D close_point = (seg.end + seg.start) / 2;
try
{
if (scalar_product(close_point - a.start, a.end - a.start) < 0 ||
scalar_product(close_point - a.end, a.start - a.end) < 0)
throw std::string("point outside first segment bound");
if (scalar_product(close_point - b.start, b.end - b.start) < 0 ||
scalar_product(close_point - b.end, b.start - b.end) < 0)
throw std::string("point outside second segment boundaries");
if ((scalar_product(tmp, tmp) - 0.001) > 0)
throw std::string("no intersection point");
}
catch(const std::string& ex)
{
std::cerr << ex << '\n';
exit(1);
}
return close_point;
}
Vector3D::Vector3D(){}
Vector3D::Vector3D(float x, float y, float z):x(x), y(y), z(z){}
Vector3D::Vector3D(const Vector3D &v): x(v.x), y(v.y), z(v.z){}
const float Vector3D::get_x(){return x;}
const float Vector3D::get_y(){return y;}
const float Vector3D::get_z(){return z;}
void Vector3D::set_x(float x){this->x = x;}
void Vector3D::set_y(float y){this->y = y;}
void Vector3D::set_z(float z){this->z = z;}
Vector3D& Vector3D::operator=(const Vector3D &v)
{
x = v.x;
y = v.y;
z = v.z;
return *this;
}
Vector3D Vector3D::operator+(const Vector3D &v)
{
return Vector3D(x+v.x, y+v.y, z+v.z);
}
Vector3D Vector3D::operator-(const Vector3D &v)
{
return Vector3D(x-v.x, y-v.y, z-v.z);
}
Vector3D Vector3D::operator*(const float &value)
{
return Vector3D(x*value, y*value, z*value);
}
Vector3D Vector3D::operator/(const float &value)
{
return Vector3D(x/value, y/value, z/value);
}
Segment::Segment(){};
Segment::Segment(Vector3D start, Vector3D end): start(start), end(end){}
Describe(any_group_name_you_want)
{
It(should_do_something)
{
Assert::That("some value", Equals("another value"));
}
};