source: liacs/MIR2010/SourceCode/cximage/ximath.cpp@ 298

Last change on this file since 298 was 95, checked in by Rick van der Zwet, 15 years ago

Bad boy, improper move of directory

File size: 1.8 KB
RevLine 
[95]1#include "ximage.h"
2#include "ximath.h"
3#include <math.h>
4
5//this module should contain some classes for geometrical transformations
6//usable with selections, etc... once it's done, that is. :)
7
8CxPoint2::CxPoint2()
9{
10 x=y=0.0f;
11}
12
13CxPoint2::CxPoint2(float const x_, float const y_)
14{
15 x=x_;
16 y=y_;
17}
18
19CxPoint2::CxPoint2(CxPoint2 const &p)
20{
21 x=p.x;
22 y=p.y;
23}
24
25float CxPoint2::Distance(CxPoint2 const p2)
26{
27 return (float)sqrt((x-p2.x)*(x-p2.x)+(y-p2.y)*(y-p2.y));
28}
29
30float CxPoint2::Distance(float const x_, float const y_)
31{
32 return (float)sqrt((x-x_)*(x-x_)+(y-y_)*(y-y_));
33}
34
35CxRect2::CxRect2()
36{
37}
38
39CxRect2::CxRect2(float const x1_, float const y1_, float const x2_, float const y2_)
40{
41 botLeft.x=x1_;
42 botLeft.y=y1_;
43 topRight.x=x2_;
44 topRight.y=y2_;
45}
46
47CxRect2::CxRect2(CxRect2 const &p)
48{
49 botLeft=p.botLeft;
50 topRight=p.topRight;
51}
52
53float CxRect2::Surface() const
54/*
55 * Returns the surface of rectangle.
56 */
57{
58 return (topRight.x-botLeft.x)*(topRight.y-botLeft.y);
59}
60
61CxRect2 CxRect2::CrossSection(CxRect2 const &r2) const
62/*
63 * Returns crossection with another rectangle.
64 */
65{
66 CxRect2 cs;
67 cs.botLeft.x=max(botLeft.x, r2.botLeft.x);
68 cs.botLeft.y=max(botLeft.y, r2.botLeft.y);
69 cs.topRight.x=min(topRight.x, r2.topRight.x);
70 cs.topRight.y=min(topRight.y, r2.topRight.y);
71 if (cs.botLeft.x<=cs.topRight.x && cs.botLeft.y<=cs.topRight.y) {
72 return cs;
73 } else {
74 return CxRect2(0,0,0,0);
75 }//if
76}
77
78CxPoint2 CxRect2::Center() const
79/*
80 * Returns the center point of rectangle.
81 */
82{
83 return CxPoint2((topRight.x+botLeft.x)/2.0f, (topRight.y+botLeft.y)/2.0f);
84}
85
86float CxRect2::Width() const
87//returns rectangle width
88{
89 return topRight.x-botLeft.x;
90}
91
92float CxRect2::Height() const
93//returns rectangle height
94{
95 return topRight.y-botLeft.y;
96}
97
Note: See TracBrowser for help on using the repository browser.