Add spaces around comparison operators in render/ and ui/ source files.

PiperOrigin-RevId: 536001297
Change-Id: Ia0d97bf9f886aea03b8363e4d97e18301520909f
This commit is contained in:
Yuval Tassa
2023-05-28 07:04:06 -07:00
committed by Copybara-Service
parent 455b1cd2e2
commit d1c6561f1c
5 changed files with 509 additions and 500 deletions
+74 -71
View File
@@ -60,7 +60,7 @@ void mjr_setBuffer(int framebuffer, mjrContext* con) {
// both available: use selected framebuffer
else {
// bind selected buffer
if (framebuffer==mjFB_WINDOW) {
if (framebuffer == mjFB_WINDOW) {
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glReadBuffer(con->windowDoublebuffer ? GL_BACK : GL_FRONT);
glDrawBuffer(con->windowDoublebuffer ? GL_BACK : GL_FRONT);
@@ -79,7 +79,7 @@ void mjr_setBuffer(int framebuffer, mjrContext* con) {
// make con->currentBuffer current again
void mjr_restoreBuffer(const mjrContext* con) {
if (con->currentBuffer==mjFB_WINDOW) {
if (con->currentBuffer == mjFB_WINDOW) {
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glReadBuffer(con->windowDoublebuffer ? GL_BACK : GL_FRONT);
glDrawBuffer(con->windowDoublebuffer ? GL_BACK : GL_FRONT);
@@ -106,7 +106,7 @@ void mjr_readPixels(unsigned char* rgb, float* depth,
}
// read from window
if (con->currentBuffer==mjFB_WINDOW) {
if (con->currentBuffer == mjFB_WINDOW) {
// read rgb and depth
if (rgb) {
glReadPixels(viewport.left, viewport.bottom, viewport.width, viewport.height,
@@ -193,7 +193,7 @@ void mjr_blitBuffer(mjrRect src, mjrRect dst,
// construct mask and filter for blit
GLbitfield mask = (flg_color ? GL_COLOR_BUFFER_BIT : 0) |
(flg_depth ? GL_DEPTH_BUFFER_BIT : 0);
GLenum filter = (!flg_depth && (src.width!=dst.width || src.height!=dst.height)) ?
GLenum filter = (!flg_depth && (src.width != dst.width || src.height != dst.height)) ?
GL_LINEAR : GL_NEAREST;
// make sure both buffers are available and we have something to do
@@ -207,7 +207,7 @@ void mjr_blitBuffer(mjrRect src, mjrRect dst,
}
// from window to offsreen
if (con->currentBuffer==mjFB_WINDOW) {
if (con->currentBuffer == mjFB_WINDOW) {
// offscreen is multisample: go through resolve
if (con->offSamples) {
// prepare to blit from window to resolve
@@ -291,7 +291,7 @@ void mjr_blitBuffer(mjrRect src, mjrRect dst,
// Set Aux buffer for custom OpenGL rendering (call restoreBuffer when done).
void mjr_setAux(int index, const mjrContext* con) {
// check index
if (index<0 || index>=mjNAUX) {
if (index < 0 || index >= mjNAUX) {
mju_error("Invalid aux buffer index");
}
@@ -310,7 +310,7 @@ void mjr_setAux(int index, const mjrContext* con) {
// Blit from Aux buffer to con->currentBuffer.
void mjr_blitAux(int index, mjrRect src, int left, int bottom, const mjrContext* con) {
// check index
if (index<0 || index>=mjNAUX) {
if (index < 0 || index >= mjNAUX) {
mju_error("Invalid aux buffer index");
}
@@ -338,7 +338,7 @@ void mjr_blitAux(int index, mjrRect src, int left, int bottom, const mjrContext*
glReadBuffer(GL_COLOR_ATTACHMENT0);
// set destination
if (con->currentBuffer==mjFB_WINDOW) {
if (con->currentBuffer == mjFB_WINDOW) {
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
glDrawBuffer(con->windowDoublebuffer ? GL_BACK : GL_FRONT);
} else {
@@ -391,7 +391,7 @@ void mjr_textActual(int font, const char* txt, const mjrContext* con,
}
// shadow text
if (font==mjFONT_SHADOW) {
if (font == mjFONT_SHADOW) {
// blend shadow with black
glListBase(con->baseFontShadow);
glColor4f(0, 0, 0, 0.5);
@@ -407,7 +407,7 @@ void mjr_textActual(int font, const char* txt, const mjrContext* con,
// regular text (normal or big)
else {
glListBase(font==mjFONT_BIG ? con->baseFontBig : con->baseFontNormal);
glListBase(font == mjFONT_BIG ? con->baseFontBig : con->baseFontNormal);
glColor4f(r, g, b, 1);
glRasterPos3f(x, y, z);
glCallLists((GLsizei)strlen(txt), GL_UNSIGNED_BYTE, txt);
@@ -433,16 +433,16 @@ static int draw_overlay(int font, mjrRect viewport, int skip, int gridpos,
float red, float green, float blue,
const char* overlay, const mjrContext* con) {
int pos, ncthis, nc, nr, W, H, flg_big = (font==mjFONT_BIG);
int pos, ncthis, nc, nr, W, H, flg_big = (font == mjFONT_BIG);
int PAD = 5, sz = mjMIN(mjMAXOVERLAY, (int)strlen(overlay));
char text[mjMAXOVERLAY];
// count rows and columns of text rectangle in pixels
nr = flg_big ? con->charHeightBig : con->charHeight;
ncthis = nc = 0;
for (int i=0; i<sz; i++) {
for (int i=0; i < sz; i++) {
// process this char
if (overlay[i]!='\n') {
if (overlay[i] != '\n') {
ncthis += flg_big ? con->charWidthBig[(unsigned char)overlay[i]]
: con->charWidth[(unsigned char)overlay[i]];
nc = mjMAX(nc, ncthis);
@@ -503,10 +503,10 @@ static int draw_overlay(int font, mjrRect viewport, int skip, int gridpos,
// draw text line by line
nr = flg_big ? con->charHeightBig : con->charHeight;
pos = 0;
for (int i=0; i<sz; i++) {
for (int i=0; i < sz; i++) {
// terminate line and draw
if (overlay[i]=='\n' || i==sz-1) {
if (overlay[i]=='\n') {
if (overlay[i] == '\n' || i == sz-1) {
if (overlay[i] == '\n') {
text[pos] = 0;
} else {
text[pos] = overlay[i];
@@ -536,7 +536,7 @@ void mjr_overlay(int font, int gridpos, mjrRect viewport,
int skip = 0;
// empty viewport: nothing to do
if (viewport.width<=0 || viewport.height<=0) {
if (viewport.width <= 0 || viewport.height <= 0) {
return;
}
@@ -546,7 +546,7 @@ void mjr_overlay(int font, int gridpos, mjrRect viewport,
// two-column
if (overlay2 && overlay2[0]) {
// left side
if (gridpos==mjGRID_TOPLEFT || gridpos==mjGRID_BOTTOMLEFT) {
if (gridpos == mjGRID_TOPLEFT || gridpos == mjGRID_BOTTOMLEFT) {
skip = draw_overlay(font, viewport, 0, gridpos, .7, .7, .7, overlay, con);
draw_overlay(font, viewport, skip, gridpos, 1, 1, 1, overlay2, con);
}
@@ -575,7 +575,7 @@ mjrRect mjr_maxViewport(const mjrContext* con) {
// window: get from scissor box
int dims[4];
if (con->currentBuffer==mjFB_WINDOW) {
if (con->currentBuffer == mjFB_WINDOW) {
glGetIntegerv(GL_SCISSOR_BOX, dims);
res.width = dims[2];
res.height = dims[3];
@@ -589,7 +589,7 @@ mjrRect mjr_maxViewport(const mjrContext* con) {
// draw rectangle
void mjr_rectangle(mjrRect viewport, float r, float g, float b, float a) {
// empty viewport: nothing to do
if (viewport.width<=0 || viewport.height<=0) {
if (viewport.width <= 0 || viewport.height <= 0) {
return;
}
@@ -616,7 +616,7 @@ void mjr_label(mjrRect viewport, int font, const char* txt,
float r, float g, float b, float a, float rt, float gt, float bt,
const mjrContext* con) {
// empty viewport: nothing to do
if (viewport.width<=0 || viewport.height<=0) {
if (viewport.width <= 0 || viewport.height <= 0) {
return;
}
@@ -658,7 +658,7 @@ void mjr_label(mjrRect viewport, int font, const char* txt,
if (txt && con->rangeFont) {
// compute width
int i = 0, width = 0;
if (font==mjFONT_BIG) {
if (font == mjFONT_BIG) {
while (txt[i]) {
width += con->charWidthBig[(unsigned char)txt[i++]];
}
@@ -670,10 +670,10 @@ void mjr_label(mjrRect viewport, int font, const char* txt,
// compute center
int cx = (W - width)/2;
int cy = (H - (font==mjFONT_BIG ? con->charHeightBig : con->charHeight))/2;
int cy = (H - (font == mjFONT_BIG ? con->charHeightBig : con->charHeight))/2;
// draw
glListBase(font==mjFONT_BIG ? con->baseFontBig : con->baseFontNormal);
glListBase(font == mjFONT_BIG ? con->baseFontBig : con->baseFontNormal);
glColor3f(rt, gt, bt);
glRasterPos2i(mjMAX(0, cx), cy);
glCallLists((GLsizei)strlen(txt), GL_UNSIGNED_BYTE, txt);
@@ -691,15 +691,15 @@ static void maketext(const char* format, char* txt, float num, int txt_sz) {
// locate trailing zeros
i = strlen(txt);
while (i>0 && txt[i-1]=='0') {
while (i > 0 && txt[i-1] == '0') {
i--;
}
if (i<=1) {
if (i <= 1) {
return;
}
// strip if preceding char is '.'
if (txt[i-1]=='.') {
if (txt[i-1] == '.') {
txt[i-1] = 0;
}
@@ -707,12 +707,12 @@ static void maketext(const char* format, char* txt, float num, int txt_sz) {
else {
// find regular preceding digits
j = i-1;
while (j>=0 && txt[j]>='0' && txt[j]<='9') {
while (j >= 0 && txt[j] >= '0' && txt[j] <= '9') {
j--;
}
// '.' found: strip
if (j>=0 && txt[j]=='.') {
if (j >= 0 && txt[j] == '.') {
txt[i] = 0;
}
}
@@ -743,7 +743,7 @@ void mjr_figure(mjrRect viewport, mjvFigure* fig, const mjrContext* con) {
char datatxt[STRING_BUFSIZE];
// empty viewport: nothing to do
if (viewport.width<=0 || viewport.height<=0) {
if (viewport.width <= 0 || viewport.height <= 0) {
return;
}
@@ -763,12 +763,12 @@ void mjr_figure(mjrRect viewport, mjvFigure* fig, const mjrContext* con) {
glDisable(GL_BLEND);
// determine range along (x,y)
for (int axis=0; axis<2; axis++) {
for (int axis=0; axis < 2; axis++) {
// init ranges, set flag
range[axis][0] = fig->range[axis][0];
range[axis][1] = fig->range[axis][1];
int flg;
if (fig->range[axis][0]<fig->range[axis][1]) {
if (fig->range[axis][0] < fig->range[axis][1]) {
flg = 1;
} else {
flg = 0;
@@ -776,8 +776,8 @@ void mjr_figure(mjrRect viewport, mjvFigure* fig, const mjrContext* con) {
// determine range: scan line data, find min and max
if (!flg || fig->flg_extend) {
for (int n=0; n<mjMAXLINE; n++) {
for (int i=0; i<fig->linepnt[n]; i++) {
for (int n=0; n < mjMAXLINE; n++) {
for (int i=0; i < fig->linepnt[n]; i++) {
// get data
float ldata = fig->linedata[n][2*i+axis];
@@ -796,12 +796,12 @@ void mjr_figure(mjrRect viewport, mjvFigure* fig, const mjrContext* con) {
// otherwise regular update
else {
// update minimum
if (range[axis][0]>ldata) {
if (range[axis][0] > ldata) {
range[axis][0] = ldata;
}
// update maximum
if (range[axis][1]<ldata) {
if (range[axis][1] < ldata) {
range[axis][1] = ldata;
}
}
@@ -810,7 +810,7 @@ void mjr_figure(mjrRect viewport, mjvFigure* fig, const mjrContext* con) {
}
// make sure range is not too small
if (range[axis][1]-range[axis][0]<minrange) {
if (range[axis][1]-range[axis][0] < minrange) {
float needed = minrange - (range[axis][1]-range[axis][0]);
range[axis][0] -= 0.5f*needed;
range[axis][1] += 0.5f*needed;
@@ -833,7 +833,7 @@ void mjr_figure(mjrRect viewport, mjvFigure* fig, const mjrContext* con) {
// set projection in pixels
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if (viewport.width<=1 || viewport.height<=1) {
if (viewport.width <= 1 || viewport.height <= 1) {
return;
}
glOrtho(0, viewport.width-1, 0, viewport.height-1, -1, 1);
@@ -843,29 +843,32 @@ void mjr_figure(mjrRect viewport, mjvFigure* fig, const mjrContext* con) {
if (fig->title[0]) {
// find address of selected subplot title
int subadr = 0, subcnt = 0;
while (subcnt<fig->subplot && subadr<1000 && fig->title[subadr]) {
while (subcnt < fig->subplot && subadr < 1000 && fig->title[subadr]) {
// skip non-space
while (subadr<1000 && fig->title[subadr] && fig->title[subadr]!=' ') {
while (subadr < 1000 && fig->title[subadr] && fig->title[subadr] != ' ') {
subadr++;
}
// skip space, count
int cntspace = 0;
while (subadr<1000 && fig->title[subadr]==' ') {
while (subadr < 1000 && fig->title[subadr] == ' ') {
subadr++;
cntspace++;
}
// count subplot if 2+ spaces
if (cntspace>1) {
if (cntspace > 1) {
subcnt++;
}
}
// find length of selected subplot title (skip non-space or single space)
int sublen = 0;
while ((subadr+sublen<1000 && fig->title[subadr+sublen] && fig->title[subadr+sublen]!=' ') ||
(subadr+sublen+1<1000 && fig->title[subadr+sublen+1] && fig->title[subadr+sublen+1]!=' ')) {
while ((subadr+sublen < 1000 &&
fig->title[subadr+sublen] &&
fig->title[subadr+sublen] != ' ') ||
(subadr+sublen+1 < 1000 && fig->title[subadr+sublen+1] &&
fig->title[subadr+sublen+1] != ' ')) {
sublen++;
}
@@ -876,7 +879,7 @@ void mjr_figure(mjrRect viewport, mjvFigure* fig, const mjrContext* con) {
// get title size
int sx_title = 0;
for (int i=subadr; i<subadr+sublen; i++) {
for (int i=subadr; i < subadr+sublen; i++) {
sx_title += con->charWidth[(unsigned char)fig->title[i]];
}
@@ -885,15 +888,15 @@ void mjr_figure(mjrRect viewport, mjvFigure* fig, const mjrContext* con) {
// compute left edge and address of extended title
int left1 = left, subadr1 = subadr;
while (subadr1>0 && left1>=con->charWidth[(unsigned char)fig->title[subadr1-1]]) {
while (subadr1 > 0 && left1 >= con->charWidth[(unsigned char)fig->title[subadr1-1]]) {
left1 -= con->charWidth[(unsigned char)fig->title[subadr1-1]];
subadr1--;
}
// compute right edge and length of extended title
int sublen1 = 0, right1 = left1;
while (sublen1+subadr1<1000 && fig->title[subadr1+sublen1] &&
right1+con->charWidth[(unsigned char)fig->title[subadr1+sublen1]]<viewport.width) {
while (sublen1+subadr1 < 1000 && fig->title[subadr1+sublen1] &&
right1+con->charWidth[(unsigned char)fig->title[subadr1+sublen1]] < viewport.width) {
right1 += con->charWidth[(unsigned char)fig->title[subadr1+sublen1]];
sublen1++;
}
@@ -932,7 +935,7 @@ void mjr_figure(mjrRect viewport, mjvFigure* fig, const mjrContext* con) {
// reduce viewport
viewport.bottom += (sy_label ? sy_label + PAD/2 : 0);
viewport.height -= (sy_label ? sy_label + PAD/2 : 0) + (sy_title ? sy_title + PAD : 0);
if (viewport.width<=0 || viewport.height<=0) {
if (viewport.width <= 0 || viewport.height <= 0) {
return;
}
glViewport(viewport.left, viewport.bottom, viewport.width, viewport.height);
@@ -944,7 +947,7 @@ void mjr_figure(mjrRect viewport, mjvFigure* fig, const mjrContext* con) {
}
// draw optional tick labels, reduce viewport
if (fig->gridsize[0]>1 && fig->gridsize[1]>1) {
if (fig->gridsize[0] > 1 && fig->gridsize[1] > 1) {
char txt[STRING_BUFSIZE];
// determine xtick height
@@ -965,7 +968,7 @@ void mjr_figure(mjrRect viewport, mjvFigure* fig, const mjrContext* con) {
int n = mjMIN(20, fig->gridsize[1]);
// generate all strings, find max width
for (int i=0; i<n; i++) {
for (int i=0; i < n; i++) {
const int txt_sz = mjSIZEOFARRAY(txt);
maketext(fig->yformat, txt, range[1][0] + (range[1][1]-range[1][0])*i/(float)(n-1),
txt_sz);
@@ -981,7 +984,7 @@ void mjr_figure(mjrRect viewport, mjvFigure* fig, const mjrContext* con) {
int n = mjMIN(20, fig->gridsize[0]);
// process ticks
for (int i=0; i<n; i++) {
for (int i=0; i < n; i++) {
// make text, get width
{
const int txt_sz = mjSIZEOFARRAY(txt);
@@ -993,7 +996,7 @@ void mjr_figure(mjrRect viewport, mjvFigure* fig, const mjrContext* con) {
// draw
mjr_textActual(mjFONT_NORMAL, txt, con,
PAD+ytick_width+
(i==0 ? 0 : (i==n-1 ? -w : -w/2))+
(i == 0 ? 0 : (i == n-1 ? -w : -w/2))+
(viewport.width-2*PAD-ytick_width)*i/(float)(n-1),
PAD, 0,
fig->textrgb[0], fig->textrgb[0], fig->textrgb[0]);
@@ -1006,7 +1009,7 @@ void mjr_figure(mjrRect viewport, mjvFigure* fig, const mjrContext* con) {
int n = mjMIN(20, fig->gridsize[1]);
// process ticks
for (int i=0; i<n; i++) {
for (int i=0; i < n; i++) {
// make text, get width
{
const int txt_sz = mjSIZEOFARRAY(txt);
@@ -1036,7 +1039,7 @@ void mjr_figure(mjrRect viewport, mjvFigure* fig, const mjrContext* con) {
viewport.width -= 2*PAD;
viewport.bottom += PAD;
viewport.height -= 2*PAD;
if (viewport.width<=0 || viewport.height<=0) {
if (viewport.width <= 0 || viewport.height <= 0) {
return;
}
glViewport(viewport.left, viewport.bottom, viewport.width, viewport.height);
@@ -1067,7 +1070,7 @@ void mjr_figure(mjrRect viewport, mjvFigure* fig, const mjrContext* con) {
glEnableClientState(GL_VERTEX_ARRAY);
// draw grid
if (fig->gridsize[0]>1 && fig->gridsize[1]>1) {
if (fig->gridsize[0] > 1 && fig->gridsize[1] > 1) {
// common GL state
glVertexPointer(2, GL_FLOAT, 0, griddata);
glColor3fv(fig->gridrgb);
@@ -1075,7 +1078,7 @@ void mjr_figure(mjrRect viewport, mjvFigure* fig, const mjrContext* con) {
// prepare vertical lines
int n = mjMIN(20, fig->gridsize[0]);
for (int i=0; i<n; i++) {
for (int i=0; i < n; i++) {
griddata[4*i] = i/(float)(n-1);
griddata[4*i+1] = 0;
griddata[4*i+2] = griddata[4*i];
@@ -1087,7 +1090,7 @@ void mjr_figure(mjrRect viewport, mjvFigure* fig, const mjrContext* con) {
// prepare horizontal lines
n = mjMIN(20, fig->gridsize[1]);
for (int i=0; i<n; i++) {
for (int i=0; i < n; i++) {
griddata[4*i] = 0;
griddata[4*i+1] = i/(float)(n-1);
griddata[4*i+2] = 1;
@@ -1107,7 +1110,7 @@ void mjr_figure(mjrRect viewport, mjvFigure* fig, const mjrContext* con) {
range[1][0] - dify*offset, range[1][1] + dify*offset, -1, 1);
// draw lines: back to front
for (int n=mjMAXLINE-1; n>=0; n--)
for (int n=mjMAXLINE-1; n >= 0; n--)
if (fig->linepnt[n]) {
// GL state
glVertexPointer(2, GL_FLOAT, 0, fig->linedata[n]);
@@ -1134,14 +1137,14 @@ void mjr_figure(mjrRect viewport, mjvFigure* fig, const mjrContext* con) {
// set matrix projection in pixels
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if (viewport.width<=1 || viewport.height<=1) {
if (viewport.width <= 1 || viewport.height <= 1) {
return;
}
glOrtho(0, viewport.width-1, 0, viewport.height-1, -1, 1);
// find legend size
int lw = 0, lh = 0, cnt = 0;
for (int n=fig->legendoffset; n<mjMAXLINE; n++) {
for (int n=fig->legendoffset; n < mjMAXLINE; n++) {
if (fig->linename[n][0]) {
// max width, accumulate height
lw = mjMAX(lw, textwidth(con, fig->linename[n]));
@@ -1151,7 +1154,7 @@ void mjr_figure(mjrRect viewport, mjvFigure* fig, const mjrContext* con) {
cnt++;
// too big: correct and break
if (lh+2*PAD >=viewport.height) {
if (lh+2*PAD >= viewport.height) {
cnt--;
lh -= con->charHeight;
break;
@@ -1163,10 +1166,10 @@ void mjr_figure(mjrRect viewport, mjvFigure* fig, const mjrContext* con) {
int hcnt = -1;
int hx = fig->highlight[0] - viewport.left;
int hy = fig->highlight[1] - viewport.bottom;
if (hx>=viewport.width-PAD-lw &&
hx<=viewport.width-PAD &&
hy>=viewport.height-PAD-lh &&
hy<=viewport.height-PAD) {
if (hx >= viewport.width-PAD-lw &&
hx <= viewport.width-PAD &&
hy >= viewport.height-PAD-lh &&
hy <= viewport.height-PAD) {
hcnt = (viewport.height-PAD-hy) / con->charHeight;
}
@@ -1185,7 +1188,7 @@ void mjr_figure(mjrRect viewport, mjvFigure* fig, const mjrContext* con) {
// find named lines and draw text
cnt = 0;
for (int n=fig->legendoffset; n<mjMAXLINE; n++) {
for (int n=fig->legendoffset; n < mjMAXLINE; n++) {
if (fig->linename[n][0]) {
// get width
int width = textwidth(con, fig->linename[n]);
@@ -1196,7 +1199,7 @@ void mjr_figure(mjrRect viewport, mjvFigure* fig, const mjrContext* con) {
fig->linergb[n][0], fig->linergb[n][1], fig->linergb[n][2]);
// save hlight
if (hcnt==cnt) {
if (hcnt == cnt) {
hlight = n;
}
@@ -1212,7 +1215,7 @@ void mjr_figure(mjrRect viewport, mjvFigure* fig, const mjrContext* con) {
}
// draw highlight
if (hlight>=0 && hlight<mjMAXLINE) {
if (hlight >= 0 && hlight < mjMAXLINE) {
// line-rendering projection
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
@@ -1230,8 +1233,8 @@ void mjr_figure(mjrRect viewport, mjvFigure* fig, const mjrContext* con) {
// find nearest x-value
int ibest = -1;
float best = 0;
for (int i=0; i<fig->linepnt[hlight]; i++) {
if (ibest<0 || best>fabs(fig->selection-fig->linedata[hlight][2*i])) {
for (int i=0; i < fig->linepnt[hlight]; i++) {
if (ibest < 0 || best > fabs(fig->selection-fig->linedata[hlight][2*i])) {
ibest = i;
best = fabs(fig->selection-fig->linedata[hlight][2*i]);
}