Created
October 15, 2015 16:37
-
-
Save novogrammer/616add1337f1af21a82c to your computer and use it in GitHub Desktop.
ofRectangleに欲しいメソッド
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
//ofRectangleにこのメソッド欲しいなー | |
inline ofRectangle ofRectangle_contain(const ofRectangle& _this,const ofRectangle& target){ | |
ofRectangle rect=target; | |
float thisAspectRatio=_this.getAspectRatio(); | |
float targetAspectRatio=target.getAspectRatio(); | |
if(thisAspectRatio<targetAspectRatio){ | |
//横が余る | |
rect.width=target.height*thisAspectRatio; | |
rect.x=(target.width-rect.width)*0.5f; | |
}else{ | |
//縦が余る | |
rect.height=target.width/thisAspectRatio; | |
rect.y=(target.height-rect.height)*0.5f; | |
} | |
return rect; | |
} | |
//ofRectangleにこのメソッド欲しいなー | |
inline ofRectangle ofRectangle_cover(const ofRectangle& _this,const ofRectangle& target){ | |
ofRectangle rect=target; | |
float thisAspectRatio=_this.getAspectRatio(); | |
float targetAspectRatio=target.getAspectRatio(); | |
if(thisAspectRatio<targetAspectRatio){ | |
//縦がはみ出る | |
rect.height=target.width/thisAspectRatio; | |
rect.y=(target.height-rect.height)*0.5f; | |
}else{ | |
//横がはみ出る | |
rect.width=target.height*thisAspectRatio; | |
rect.x=(target.width-rect.width)*0.5f; | |
} | |
return rect; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment