view anagram/support/cint.cpp @ 13:43d8b194fb4e

Remove unused variables.
author David A. Holland
date Tue, 31 May 2022 00:59:00 -0400
parents 13d2b8934445
children
line wrap: on
line source

/*
 * AnaGram, A System for Syntax Directed Programming
 * Copyright 1993-1999 Parsifal Software. All Rights Reserved.
 * See the file COPYING for license and usage terms.
 *
 * ci1.cpp - Complex integer arithmetic
 */

#include "cint.h"
#include "minmax.h"


int cint::operator <= (const cint &s) const {
  return x <= s.x  && y <= s.y;
}

int cint::operator < (const cint &s) const {
  return x < s.x  && y < s.y;
}

int cint::operator >= (const cint &s) const {
  return x >= s.x && y >= s.y;
}

int cint::operator > (const cint &s) const {
  return x > s.x && y > s.y;
}

int cint::inside_rect(cint pos, cint size) const {
  return *this >= pos && *this < pos + size;
}

int cint::inside_rect(rect r) const {
  return *this >= r.pos && *this < r.pos + r.size;
}

int cint::on_boundary(cint pos, cint size) const {
  if (!inside_rect(pos, size)) {
    return 0;
  }
  pos += cint(1, 1);
  size -= cint(2, 2);
  if (inside_rect(pos, size)) {
    return 0;
  }
  return 1;
}


cint ulci(cint a, cint b) {
  cint c;
  c.x = min(a.x, b.x);
  c.y = min(a.y, b.y);
  return c;
}

cint lrci(cint a, cint b) {
  cint c;
  c.x = max(a.x, b.x);
  c.y = max(a.y, b.y);
  return c;
}

cint measure_string(const char *s) {
  int w=0, d=0, k=0;
  cint m;

  while (*s) {
    for (k=0; *s && *s!='\n'; s++, k++);
    w = max(w, k);
    d++;
    if (*s =='\n') {
      s++;
    }
  }
  m.x = w;
  m.y = d;
  return m;
}

int measure_line(const char *s) {
  int m;

  m = 0;
  while (*s && *s !='\n') {
    m++;
    s++;
  }
  return m;
}


cint place(cint measure, cint size, int jm) {
  int hm, vm;
  cint p;

  hm = (jm/10)&3;
  vm = jm%10;

  size = ulci(measure, size);
  p.x = (measure.x-size.x)*hm/2;
  p.y = (measure.y-size.y)*vm/2;
  return p;
}


rect place_rect(rect w, cint s, int jm) {
  cint p;

  p = place(w.size, s, jm);
  w.size = ulci(w.size, p+s) - p;
  w.pos += p;
  return w;
}