Example #1
0
bool Clustering::operator>=(const Point& p1, const Point& p2){
    if (p1.getDims() != p2.getDims()){
        
        throw DimensionalityMismatchEx(p1.getDims(), p2.getDims());
        
        
    }

    bool bo = true;
    bool boEq= true;
    for ( int i = 0; i<p1.getDims(); i++){
        double temp = p1.getValue(i);
        if(temp < p2.getValue(i)){
            bo = false;
        }
        else if(temp == p2.getValue(i)){
            boEq = false;
        }
        
    }
    
    
    return (bo||boEq);
    
    
    
}
Example #2
0
 double Point::distanceTo(const Point & other) const{
     double dist = 0.0;
     for (int i = 0; i < __dim; ++i){
         dist = dist + ((__values[i]-other.getValue(i)) * (__values[i]-other.getValue(i)));
     }
     return sqrt(dist);
 }
Example #3
0
Point Point::getClosestImage (Point& other, Size& environment, vector<BorderType> borderTypes) {
	auto dimensions = other.getDimensions();

	auto image = Point(dimensions);

	for (size_t i = 0 ; i < dimensions ; i++) {
		double value = other.getValue(i);

		// If a wrap is possible, get the image's value
		if (borderTypes[i] == BorderType::WRAP) {
			// Compute the images' values deltas to this point's
			double c = getValue(i) - other.getValue(i);
			double l = c + environment[i];
			double r = c - environment[i];

			// Keep the smallest delta
			double delta = abs(l) < abs(r) ? l : r;
			delta = abs(c) < abs(delta) ? c : delta;

			// Update the image's value
			value = getValue(i) - delta;
		}

		image.setValue(i, value);
	}

	return image;
}
Example #4
0
	//computes the distance between this point and point p
	double Point::distanceTo(Point& p) {
		assert(dim == p.dim);
		double sum = 0;
		for (int i = 0; i < dim; i++) {
			sum += (values[i] - p.getValue(i + 1))*(values[i] - p.getValue(i + 1));
		}
		return sqrt(sum);
	}
        bool operator<(const Point &left, const Point &right){
                int temp = std::max(left.__dim, right.__dim);

                for(int i = 0; i < temp; i++){
                        if(left.getValue(i) != right.getValue(i))
                                return (left.getValue(i) < right.getValue(i));
                }
                return false;
        }
 //Friend Operators
 const Point operator+(const Point &lhs, const Point &rhs)  //Throws exception dim mismatch
 {
     if (lhs.dim != rhs.dim) {
         throw DimensionalityMismatchEx(lhs.dim, rhs.dim);
     }
     Point temp(rhs.getDims());
     for (int n = 0; n < rhs.getDims(); n++)
         temp.setValue(n, (lhs.getValue(n) + rhs.getValue(n)));
     return temp;
 }
    double Point::distanceTo(const Point &other) const{
        if(__dim != other.getDims())
            throw DimensionalityMismatchEx(__dim, other.getDims());

        double dist = 0.0;
        for (int i = 0; i < __dim; ++i){
            dist = dist + ((__values[i]-other.getValue(i)) * (__values[i]-other.getValue(i)));
        }

        return sqrt(dist);
    }
 bool operator==(const Point &lhs, const Point &rhs) {
     if (lhs.getDims() != rhs.getDims() || lhs._id != rhs._id) {
         return false;
     }
     for (int n = 0; n < lhs.getDims(); n++) {
         if (lhs.getValue(n) != rhs.getValue(n)) {
             return false;
         }
     }
     return true;
 }
Example #9
0
    bool operator<(const Point &p1, const Point &p2)
    {

        for (int i = 0; i < p1.__dim; i++)
        {
            if (p1.getValue(i) < p2.getValue(i))
                return true;
        }

        return false;       //all values are equal
    }
Example #10
0
 bool operator!=(const Point &lhs, const Point &rhs) {
     bool equals = false;
     if (lhs.getDims() == rhs.getDims())
         equals = false;
     for (int i = 0; i < lhs.getDims(); i++) {
         if (lhs.getValue(i) != rhs.getValue(i)) {
             equals = true;
             break;
         }
     }
     return equals;
 }
Example #11
0
	bool operator<(const Point &p1, const Point &p2)
	{
		if (p1.__dim != p2.__dim)
			throw DimensionalityMismatchEx(p1.__dim, p2.__dim);

		for (unsigned int i = 0; i < p1.__dim; i++)
		{
			if (p1.getValue(i) < p2.getValue(i))
				return true;
		}

		return false;       //all values are equal
	}
Example #12
0
 //Distance Function for two poins objects
 double Point::distanceTo(const Point & other) const
 {
     double total = 0;
     
     if (__dim != other.__dim)
         return false;
     
     for (int i = 0; i <__dim; ++i)
         
         total += ((other.getValue(i) - getValue(i)) * (other.getValue(i) - getValue(i)) );
     
     return sqrt(total);
     
 }
Example #13
0
 bool operator < (const Point & lhs, const Point & rhs)
 {
     int localdim = std::max(lhs.__dim, rhs.__dim);
     
     
     if (lhs.__dim == rhs.__dim )
         
         for ( int i =0; i < localdim; i++)
             
             if (lhs.getValue(i) < rhs.getValue(i))
                 return true;
     
     return false;
     
 }
Example #14
0
		bool operator==(const Point &arg_Point_left, const Point &arg_Point_right)
		{
			bool result = false;

			if (arg_Point_left.getId() == arg_Point_right.getId() &&
				arg_Point_left.getDims() == arg_Point_right.getDims())
			{
				result = true;
				for (int index = 0; result && index < arg_Point_left.getDims(); ++index)
					if (arg_Point_left.getValue(index) != arg_Point_right.getValue(index))
						result = false;
			}

			return result;
		}
Example #15
0
    bool operator<(const Point &lhs, const Point &rhs) {
        bool equals = false;

        assert(lhs.getDims() == rhs.getDims());

        for (int i = 0; i < lhs.getDims(); i++) {
            if (lhs.getValue(i) < rhs.getValue(i)) {
                equals = true;
            }
            else if (lhs.getValue(i) > rhs.getValue(i)) {
                equals = false;
                break;
            }
        }
        return equals;
    }
 //Big3
 Point::Point(const Point &p) {
     _id = p._id;
     dim = p.dim;
     values = new vector<double>(dim, 0);
     for (int n = 0; n < dim; n++)
         setValue(n, p.getValue(n));
 }
Example #17
0
 Point::Point(const Point &other) {
     __id = other.getId();
     __dim = other.getDims();
     __values = new double[other.getDims()];
     for (int i = 0; i < other.getDims(); i++) {
         __values[i] = other.getValue(i);
     }
 }
Example #18
0
// Ctor
//**********************************************************//
    Point::Point(const Point &point) {
        __id = point.__id;
        __dim = point.__dim;
        __values = new double[__dim];
        for (unsigned int i = 0; i < __dim; i++) {
            __values[i] = point.getValue(i);
        }
    }
Example #19
0
 bool operator ==( const Point & lhs, const Point & rhs)
 {
     if(lhs.__id != rhs.__id)
         return false;
     
     for (int i = 0; i < lhs.__dim; i++)
     {
         
         if  (lhs.getValue(i) != rhs.getValue(i))
             return false;
         
         
     }
     
     return true;
     
 }
Example #20
0
		bool operator<(const Point &arg_Point_left, const Point &arg_Point_right)
		{
			// Note: One Point is smaller than another iff, for a given
			// dimension position, the value of the first point is less than
			// the value of the second point, and all the values on the left,
			// if any, are all equal. The values on the right don't matter.
			// For example, Point (5.0, 5.0, 4.5, 10.1, 13.4, 151.3) is
			// smaller than (5.0, 5.0, 4.5, 10.1, 13.5, 15.9).
			// Note: Implement operator<, then use it to implement operator>
			// and operator>=. Finally, use operator> to implement operator<=.


			// IF EXACT SAME OBJECTS CAN'T HAVE ONE LESS THAN OTHER
			if (&arg_Point_left == &arg_Point_right)
				return false;

			bool result = false;
			bool isEqual = false;

			if (arg_Point_left.getDims() == arg_Point_right.getDims())
			{

///*DEBUG*/	std::cout << "\nDIM = " << arg_Point_left.getDims() << "\n";

				isEqual = true;
				for (int index = 0; isEqual && index < arg_Point_left.getDims(); ++index)
				{
///*DEBUG*/	std::cout << "arg_Point_left.getValue("<<index<<") = " << arg_Point_left.getValue(index) << "  <  arg_Point_right.getValue(index) = " << arg_Point_right.getValue(index) << "\n";
					if (arg_Point_left.getValue(index) == arg_Point_right.getValue(index))
					{
						// CONTINUE LOOP
						continue;
					}
					else if (arg_Point_left.getValue(index) < arg_Point_right.getValue(index))
					{
						isEqual = false;
						result = true;
					}
					// RESULT IS ALREADY FALSE; RETURN
					else isEqual = false;
				}
			}

			return result;
		}
Example #21
0
    double Point::distanceTo(const Point & other) const
    {
        if (__dim != other.__dim)
            throw DimensionalityMismatchEx(__dim,other.__dim);

        double total = 0;


        if (__dim != other.__dim)
            return false;

        for (unsigned int i = 0; i <__dim; ++i)

            total += ((other.getValue(i) - getValue(i)) * (other.getValue(i) - getValue(i)) );

        return sqrt(total);

    }
Example #22
0
double Point::getAngleTo (Point& other) {
	lock_guard<recursive_mutex> self_lock(value_m);
	lock_guard<recursive_mutex> other_lock(other.value_m);

	double x = other.getValue(0) - getValue(0);
	double y = other.getValue(1) - getValue(1);

	return atan2 (y, x);
}
Example #23
0
double Point::getDistanceTo (Point& other) {
	lock_guard<recursive_mutex> self_lock(value_m);
	lock_guard<recursive_mutex> other_lock(other.value_m);

	double x = other.getValue(0) - getValue(0);
	double y = other.getValue(1) - getValue(1);

	return sqrt (x * x + y * y);
}
Example #24
0
    Point &operator-=(Point & P1, const Point & P2){
        Point *newP = new Point(P2);

        for (int i = 0; i < P1.__dim; ++i){
            P1.__values[i] = P1.__values[i] - newP->getValue(i);
        }
        delete newP;
        return P1;
    }
Example #25
0
const Point Clustering::operator-(const Point& p1, const Point& p2){
    if (p1.getDims() != p2.getDims()){
        
        throw DimensionalityMismatchEx(p1.getDims(), p2.getDims());
        
        
    }

    Point pt(p1);
    for ( int i = 0; i<p1.getDims(); i++){
        double temp = p1.getValue(i);
        temp -= p2.getValue(i);
        pt.setValue(i,temp);
    }
    return pt;
    
    
}
Example #26
0
    double Point::distanceTo(const Point &rhs) const {

        double dist = 0;// holds resultant value of the equation below
        double sum = 0;
        int i = 0;
        for (; i < __dim; ++i)
            sum += (pow((this->getValue(i) - rhs.getValue(i)), 2.0));
        dist = sqrt(sum);
        return dist;
    }
Example #27
0
    double Point::distanceTo(const Point &a) const {

        // Calculates the distance from the object point to a given reference point, given dimension n

        double dimSum = 0;
        for (int i = 0; i < a.dim; i++) {
            dimSum += pow(a.getValue(i) - this->values[i], 2);
        }
        return sqrt(dimSum);
    }
Example #28
0
    bool operator < (const Point & lhs, const Point & rhs)
    {

        if (lhs.__dim != rhs.__dim)
            throw DimensionalityMismatchEx(lhs.__dim,rhs.__dim);


        int localdim = std::max(lhs.__dim, rhs.__dim);


        if (lhs.__dim == rhs.__dim )

            for ( int i =0; i < localdim; i++)

                if (lhs.getValue(i) < rhs.getValue(i))
                    return true;

        return false;

    }
Example #29
0
    double Point::distanceTo(const Point &p) const {
        if(__dim != p.__dim)
            return false;

        double sum_Products = 0;

        for (int i = 0; i < __dim; i++) {
            sum_Products += pow(p.getValue(i) - getValue(i), 2);
        }
        return sqrt(sum_Products);
    }
Example #30
0
	//Functions
	double Point::distanceTo(const Point &p) const
	{
		double distance = 0;
		double deltaX = 0;

		for (int i = 0; i < __dim; ++i)
		{
			deltaX += pow((__values[i] - p.getValue(i)), 2);
		}
		distance = sqrt(deltaX);
		return distance;
	}