1/* 2 Project: Graphos 3 GRImageEditor.m 4 5 Copyright (C) 2015 GNUstep Application Project 6 7 Author: Ing. Riccardo Mottola 8 9 Created: 2015-03-24 10 11 This application is free software; you can redistribute it and/or 12 modify it under the terms of the GNU General Public 13 License as published by the Free Software Foundation; either 14 version 2 of the License, or (at your option) any later version. 15 16 This application is distributed in the hope that it will be useful, 17 but WITHOUT ANY WARRANTY; without even the implied warranty of 18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 Library General Public License for more details. 20 21 You should have received a copy of the GNU General Public 22 License along with this library; if not, write to the Free 23 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 24 */ 25 26#import "GRImage.h" 27#import "GRImageEditor.h" 28 29@implementation GRImageEditor 30 31- (NSPoint)constrainControlPoint:(NSPoint)p 32{ 33 NSPoint pos; 34 CGFloat w, h; 35 NSPoint retP; 36 float ratio; 37 float wSign; 38 float hSign; 39 40 ratio = [(GRImage *)object originalRatio]; 41 retP = p; 42 pos = [(GRBox *)object position]; 43 w = pos.x-p.x; 44 h = pos.y-p.y; 45 /* we adjust the deltas, but need to retain the sign of w and h */ 46 wSign = 1.0; 47 hSign = 1.0; 48 if (w < 0) 49 wSign = -1.0; 50 if (h < 0) 51 hSign = -1.0; 52 if (fabs(w / h) > ratio) 53 w = wSign * fabs(h * ratio); 54 else 55 h = hSign * fabs(w / ratio); 56 57 retP.x = pos.x-w; 58 retP.y = pos.y-h; 59 60 return retP; 61} 62 63 64@end 65