コード例 #1
0
ファイル: field.cpp プロジェクト: akrupych/WebCheckersQT
bool Field::qcanBeatBL(const Cell *arg)
{
    if( arg == NULL || !arg->getFigure().isQueen() )
    {
        string exep = "ERROR! qcanBeatBL function cannot take not queen, or arg is NULL\n";
        throw exep;
    }

    unsigned char tmpcol = arg->getFigure().getColor();
    bool was_token = false;

    Cell* temp = getBottomLeft(arg);                       // Bottom Left element

    while( temp != NULL )                                   // while it's not an end of field
    {
        if( temp->isEmpty() )                               // if it's empty cell
        {
            if( was_token )                                 // and we beated some figure
            {
                temp->setCanMove(true);                     // then we can move on this
            }
            temp = getBottomLeft(temp);                       // set checking on next top right cell
        }

        else                                                // if it's not empty cell
        {
            if( temp->getFigure().getColor() == tmpcol )    // if it's friendly figure
            {
                break;
            }
            else                                            // !!! if it's an empty cell
            {
                if( was_token )                             // we can beat only 1 time per move!
                {
                    break;
                }

                // !!! not token
                if( getBottomLeft(temp)->isEmpty() )          // if next one is empty
                {
                    was_token = true;                       // we beated!
                    temp = getBottomLeft(temp);               // move to that pozition
                    temp->setCanMove(true);
                }
            }
        }
    }
    return was_token;
}
コード例 #2
0
Feature::Feature(const char* _filename)
{
  filename = strcpy(new char[std::strlen(_filename)+1], _filename);
  FILE* infile = fopen(filename, "rb");
  bit** bits = pbm_readpbm(infile, &cols, &rows);
  fclose(infile);
  cols32 = (cols + 31) / 32;
  right_mask = static_cast<unsigned int>(-1) << (32 - (cols % 32));
  // fprintf(stderr, "width %d height %d mask %x\n", cols, rows, right_mask);

  integers = new unsigned int[cols32 * rows];
  for (int y = 0; y < rows; y++) {
    int index = 0;
    for (int x = 0; x < cols32; x++) {
      int i = 0;
      for (int b = 0; b < 32; b++) {
	i = i << 1;
	if (index < cols && bits[y][index]) i++;
	index++;
      }
      integers[x + y * cols32] = i;
    }
  }
  pbm_freearray(bits, rows);
  /*
  fprintf(stderr, "%dx%d %s\n%x %x\n%x %x\n%x %x\n", cols, rows, filename,
	  integers[(rows - 3) * cols32], integers[(rows - 3) * cols32 + 1],
	  integers[(rows - 2) * cols32], integers[(rows - 2) * cols32 + 1],
	  integers[(rows - 1) * cols32], integers[(rows - 1) * cols32 + 1]);
  */
  if (getBottomLeft() == 0) {
    fprintf(stderr, "WARNING: bottom left in %s is zero\n", filename);
  }
}
コード例 #3
0
ファイル: glmRectangle.cpp プロジェクト: gobomus/ofxGlmTools
bool glmRectangle::clip( glm::vec3& _p0, glm::vec3& _p1) const {
    
    glm::vec3 topLeft     = getTopLeft();
    glm::vec3 topRight    = getTopRight();
    glm::vec3 bottomRight = getBottomRight();
    glm::vec3 bottomLeft  = getBottomLeft();
    
    if (!inside(_p0)) {
        glm::vec3 r;
        if (LineSegmentIntersection(_p0, _p1, topLeft,     topRight,    r)){
            _p0 = r;
        } else if (LineSegmentIntersection(_p0, _p1, topRight,    bottomRight, r)){
            _p0 = r;
        } else if (LineSegmentIntersection(_p0, _p1, bottomRight, bottomLeft,  r)){
            _p0 = r;
        } else if (LineSegmentIntersection(_p0, _p1, bottomLeft,  topLeft,     r)){
            _p0 = r;
        }
    }
    
    if (!inside(_p1)) {
        glm::vec3 r;
        if (LineSegmentIntersection(_p1, _p0, topLeft,     topRight,    r)){
            _p1 = r;
        } else if (LineSegmentIntersection(_p1, _p0, topRight,    bottomRight, r)){
            _p1 = r;
        } else if (LineSegmentIntersection(_p1, _p0, bottomRight, bottomLeft,  r)){
            _p1 = r;
        } else if (LineSegmentIntersection(_p1, _p0, bottomLeft,  topLeft,     r)){
            _p1 = r;
        }
    }
}
コード例 #4
0
ファイル: field.cpp プロジェクト: akrupych/WebCheckersQT
bool Field::canBeatBL(const Cell *arg)
{
    Cell* temp = getBottomLeft(arg);
    Cell* tempTR = getBottomLeft(temp);

    if( tempTR != NULL && !arg->isEmpty() )    // getTopRight checks arg for NULL value
    {
        if( !temp->isEmpty() )
        {
            if( arg->getFigure().getColor() == temp->getFigure().getColor() )
            {
                return false;
            }
            if( tempTR->isEmpty() )
            {
                tempTR->setCanMove(true);
            }
         }
    }
    return false;
}
コード例 #5
0
//----------------------------------------------------------
bool ofRectangle::intersects(const ofPoint& p0, const ofPoint& p1) const {
    // check for a line intersection
    ofPoint p;

    ofPoint topLeft     = getTopLeft();
    ofPoint topRight    = getTopRight();
    ofPoint bottomRight = getBottomRight();
    ofPoint bottomLeft  = getBottomLeft();

    return inside(p0) || // check end inside
           inside(p1) || // check end inside
           ofLineSegmentIntersection(p0, p1, topLeft,     topRight,    p) || // cross top
           ofLineSegmentIntersection(p0, p1, topRight,    bottomRight, p) || // cross right
           ofLineSegmentIntersection(p0, p1, bottomRight, bottomLeft,  p) || // cross bottom
           ofLineSegmentIntersection(p0, p1, bottomLeft,  topLeft,     p);   // cross left
}
コード例 #6
0
ファイル: frect.cpp プロジェクト: eriser/Voltex
//------------------------------------------------------------------------
Point& Rect::toPoint (Direction dir, Point& p) const
{
	switch (dir) {
	case kSouthWest:		return p = getBottomLeft ();
	case kWest:				return p = getLeftCenter ();
	case kNorthWest:		return p = getTopLeft ();
	case kNorth:			return p = getTopCenter ();
	case kNorthEast:		return p = getTopRight ();
	case kEast:				return p = getRightCenter ();
	case kSouthEast:		return p = getBottomRight ();
	case kSouth:			return p = getBottomCenter ();
	case kNoDirection:		return p = getCenter ();
	}

	return p;
}
コード例 #7
0
ファイル: glmRectangle.cpp プロジェクト: gobomus/ofxGlmTools
//----------------------------------------------------------
bool glmRectangle::intersects(const glm::vec3& p0, const glm::vec3& p1) const {
    // check for a line intersection
    glm::vec3 p;
    
    glm::vec3 topLeft     = getTopLeft();
    glm::vec3 topRight    = getTopRight();
    glm::vec3 bottomRight = getBottomRight();
    glm::vec3 bottomLeft  = getBottomLeft();
    
    return inside(p0) || // check end inside
    inside(p1) || // check end inside
    LineSegmentIntersection(p0, p1, topLeft,     topRight,    p) || // cross top
    LineSegmentIntersection(p0, p1, topRight,    bottomRight, p) || // cross right
    LineSegmentIntersection(p0, p1, bottomRight, bottomLeft,  p) || // cross bottom
    LineSegmentIntersection(p0, p1, bottomLeft,  topLeft,     p);   // cross left
}
コード例 #8
0
ファイル: TextField.cpp プロジェクト: AbdelghaniDr/ofxCvGui
		//----------
		TextField::TextField(string caption) {
			this->setCaption(caption);
			this->setBounds(ofRectangle(5, 0, 100, 50));
			this->onDraw += [this](ofxCvGui::DrawArguments & args) {
				//draw caption
				auto & captionFont = ofxAssets::font(ofxCvGui::getDefaultTypeface(), 12);
				captionFont.drawString(this->caption + " : ", 0, 15);
				
				//draw underline
				ofPushStyle();
				{
					const auto textFieldBounds = this->textField->getBounds();
					ofSetColor(100);
					ofSetLineWidth(1.0f);
					ofDrawLine(textFieldBounds.getBottomLeft(), textFieldBounds.getBottomRight());
				}
				ofPopStyle();
				
				//draw side line
				ofPushStyle();
				{
					ofSetLineWidth(1.0f);
					ofDrawLine(this->getWidth(), 0, this->getWidth(), 20);
				}
				ofPopStyle();
			};
			
			this->textField = make_shared<Utils::TextField>();
			this->textField->addListenersToParent(this);
			this->textField->setFont(ofxAssets::font(ofxCvGui::getDefaultTypeface(), 12));
			
			this->onBoundsChange += [this](BoundsChangeArguments & args) {
				this->textField->setBounds(ofRectangle(10, 20, args.localBounds.width - 20, 20));
			};
			this->onMouse += [this](MouseArguments & args) {
				if(args.takeMousePress(this)) {
					//if we clicked in here
					this->textField->focus();
				} else if (this->textField->isFocused() && !args.isLocal()) {
					this->textField->defocus();
				}
			};
		}
コード例 #9
0
ファイル: rect.cpp プロジェクト: LodePublishing/GUI
// dieses Rect relativ zum anderen...
eTouchType Rect::getTouchType(const Rect& rect) const
{
	if(!isTouched(rect)) {
		return TOUCHES_NO_TOUCH;
	}

	// ist 'rect' innerhalb dieses Rects?
	if(isRectInside(rect)) {
		return TOUCHES_IS_COMPLETELY_INSIDE;
	} else if(isTopLeftCornerInside(rect.getTopLeft()) && isBottomLeftCornerInside(rect.getBottomLeft())) {
		return TOUCHES_CROSSES_RIGHT_BORDER;
	} else if(isTopLeftCornerInside(rect.getTopLeft()) && isTopRightCornerInside(rect.getTopRight())) {
		return TOUCHES_CROSSES_LOWER_BORDER;
	} else if(isTopRightCornerInside(rect.getTopRight()) && isBottomRightCornerInside(rect.getBottomRight())) {
		return TOUCHES_CROSSES_LEFT_BORDER;
	} else if(isBottomRightCornerInside(rect.getBottomRight()) && isBottomLeftCornerInside(rect.getBottomLeft())) {
		return TOUCHES_CROSSES_UPPER_BORDER;
	} else if(isTopLeftCornerInside(rect.getTopLeft())) {
		return TOUCHES_CROSSES_BOTTOM_RIGHT_CORNER;
	} else if(isTopRightCornerInside(rect.getTopRight())) {
		return TOUCHES_CROSSES_BOTTOM_LEFT_CORNER;
	} else if(isBottomRightCornerInside(rect.getBottomRight())) {
		return TOUCHES_CROSSES_TOP_LEFT_CORNER;
	} else if(isBottomLeftCornerInside(rect.getBottomLeft())) {
		return TOUCHES_CROSSES_TOP_RIGHT_CORNER;
	}

	else if((rect.getLeft() < getLeft()) && (rect.getRight() > getRight()) && (rect.getTop() >= getTop()) && (rect.getBottom() <= getBottom())) { // ? = 
		return TOUCHES_CROSSES_LEFT_AND_RIGHT_BORDER;
	} else if((rect.getTop() < getTop()) && (rect.getBottom() > getBottom()) && (rect.getLeft() >= getLeft()) && (rect.getRight() <= getRight())) {
		return TOUCHES_CROSSES_TOP_AND_BOTTOM_BORDER;
	}

	else if((rect.getLeft() == getRight()) && (rect.getTop() == getTop()) && (rect.getBottom() == getBottom())) {
		return TOUCHES_RIGHT_BORDER;
	} else if((rect.getTop() == getBottom()) && (rect.getLeft() == getLeft()) && (rect.getRight() == getRight())) {
		return TOUCHES_LOWER_BORDER;
	} else if((rect.getRight() == getLeft()) && (rect.getTop() == getTop()) && (rect.getBottom() == getBottom())) {
		return TOUCHES_LEFT_BORDER;
	} else if((rect.getBottom() == getTop()) && (rect.getLeft() == getLeft()) && (rect.getRight() == getRight())) {
		return TOUCHES_UPPER_BORDER;
	}

	else if((rect.isTopLeftCornerInside(getTopLeft())) && (rect.isTopRightCornerInside(getTopRight())) && (!rect.isBottomRightCornerInside(getBottomRight())) && (!rect.isBottomLeftCornerInside(getBottomLeft()))) {
		return TOUCHES_CROSSES_UPPER_AREA;
	} else if((!rect.isTopLeftCornerInside(getTopLeft())) && (rect.isTopRightCornerInside(getTopRight())) && (rect.isBottomRightCornerInside(getBottomRight())) && (!rect.isBottomLeftCornerInside(getBottomLeft()))) {
		return TOUCHES_CROSSES_RIGHT_AREA;
	} else if((!rect.isTopLeftCornerInside(getTopLeft())) && (!rect.isTopRightCornerInside(getTopRight())) && (rect.isBottomRightCornerInside(getBottomRight())) && (rect.isBottomLeftCornerInside(getBottomLeft()))) {
		return TOUCHES_CROSSES_LOWER_AREA;
	} else if((rect.isTopLeftCornerInside(getTopLeft())) && (!rect.isTopRightCornerInside(getTopRight())) && (!rect.isBottomRightCornerInside(getBottomRight())) && (rect.isBottomLeftCornerInside(getBottomLeft()))) {
		return TOUCHES_CROSSES_LEFT_AREA;
	}

	else { 
		return TOUCHES_NO_TOUCH;
	}
}
コード例 #10
0
ファイル: Rectangle.cpp プロジェクト: southor/planet
	OrthogonalLine Rectangle::getBottomLine() const
	{
		return OrthogonalLine(OrthogonalLine::X_AXIS, getBottomLeft(), size.x);
	}