public LDRect(LDRect rect) { this.xp = rect.xp; this.yp = rect.yp; this.w = rect.w; this.h = rect.h; }
public LDPolygon(LDRect r) { this.Add(r.topLeft()); this.Add(r.topRight()); this.Add(r.bottomRight()); this.Add(r.bottomLeft()); }
//矩形に含まれるかどうかの軽量な簡易当たり判定 public bool isPreHit(LDPoint pt, float hitRange = 0) { LDRect rect = getBounds(); //上下左右を拡張 rect.adjust(-hitRange, -hitRange, hitRange, hitRange); return(rect.contains(pt)); }
public LDRect intersected(LDRect other) { LDRect a = this.normalized(); LDRect b = other.normalized(); LDRect intersected = new LDRect(0, 0, 0, 0); intersected.setTop(Math.Max(a.top(), b.top())); intersected.setBottom(Math.Min(a.bottom(), b.bottom())); intersected.setLeft(Math.Max(a.left(), b.left())); intersected.setRight(Math.Min(a.right(), b.right())); return(intersected); }
public void copyFrom(LDGridTransform src) { m_gridPoints = new List <List <LDPoint> >(); foreach (var p in src.m_gridPoints) { m_gridPoints.Add(new List <LDPoint>()); foreach (var q in p) { m_gridPoints[m_gridPoints.Count - 1].Add(new LDPoint(q)); } } m_originRect = new LDRect(src.m_originRect); }
public LDGridTransform createExtendedGrid(int extend = 1) { LDRect bounds = getBounds(); LDGridTransform grid = new LDGridTransform( getPoint(0, 0).x() - bounds.width(), getPoint(0, 0).y() - bounds.height(), bounds.width() + bounds.width() * 2, bounds.height() + bounds.height() * 2, getRow() + 1, getColumn() + 1 ); grid.copyFrom(this, 1, 1); return(grid); }
public LDRect normalized() { LDRect normalized = new LDRect(this); if (normalized.w < 0) { normalized.xp = this.right(); normalized.w *= -1; } if (normalized.h < 0) { normalized.yp = this.bottom(); normalized.h *= -1; } return(normalized); }
//時計回りに4点 public LDGridTransform(LDPoint topLeft, LDPoint topRight, LDPoint bottomRight, LDPoint bottomLeft, int row = 1, int col = 1) { m_originRect = math.PointUtil.getBoundingRect(new LDPointList { topLeft, topRight, bottomLeft, bottomRight }); LDQuadTransform quad = new LDQuadTransform(topLeft, topRight, bottomRight, bottomLeft); for (int i = 0; i < row + 1; ++i) { m_gridPoints.Add(new List<LDPoint>()); for (int j = 0; j < col + 1; ++j) { m_gridPoints[i].Add(quad.transform((float)j / col, (float)i / row)); } } clearBoundsCache(); }
public LDRect boundingRect() { if (this.Count == 0) { return(new LDRect(0, 0, 0, 0)); } LDRect boundingRect = new LDRect(this[0], this[0]); foreach (var p in this) { boundingRect.setBottom(Math.Max(p.y(), boundingRect.bottom())); boundingRect.setRight(Math.Max(p.x(), boundingRect.right())); boundingRect.setLeft(Math.Min(p.x(), boundingRect.left())); boundingRect.setTop(Math.Min(p.y(), boundingRect.top())); } return(boundingRect); }
public bool intersects(LDRect r) { throw new NotImplementedException(); }
public bool intersects(LDRect r) { return this.intersected(r).isValid(); }
public bool contains(LDRect r) { throw new NotImplementedException(); }
public LDRect intersected(LDRect other) { throw new NotImplementedException(); }
public LDRect united(LDRect other) { LDRect a = this.normalized(); LDRect b = other.normalized(); LDRect intersected = new LDRect(0, 0, 0, 0); intersected.setTop(Math.Min(a.top(), b.top())); intersected.setBottom(Math.Max(a.bottom(), b.bottom())); intersected.setLeft(Math.Min(a.left(), b.left())); intersected.setRight(Math.Max(a.right(), b.right())); return intersected; }
public LDRect normalized() { LDRect normalized = new LDRect(this); if (normalized.w < 0) { normalized.xp = this.right(); normalized.w *= -1; } if (normalized.h < 0) { normalized.yp = this.bottom(); normalized.h *= -1; } return normalized; }
public LDRect united(LDRect other) { throw new NotImplementedException(); }
public void copyFrom(LDGridTransform src) { m_gridPoints = src.m_gridPoints; m_originRect = src.m_originRect; }
public void copyFrom(LDGridTransform src) { m_gridPoints = new List<List<LDPoint>>(); foreach(var p in src.m_gridPoints) { m_gridPoints.Add(new List<LDPoint>()); foreach(var q in p) { m_gridPoints[m_gridPoints.Count - 1].Add(new LDPoint(q)); } } m_originRect = new LDRect(src.m_originRect); }
public bool contains(LDRect r) { return this.contains(r.topLeft()) && this.contains(r.topRight()) && this.contains(r.bottomLeft()) && this.contains(r.bottomRight()); }
public LDRect getBounds() { if (m_cacheBounds.size() == new LDSize(0, 0)) { //TODO const関数内でのmutableの変更はスレッドセーフにしないといけない? m_cacheBounds = math.PointUtil.getBoundingRect(toForm()); } return m_cacheBounds; }
public bool contains(LDRect r) { return(this.contains(r.topLeft()) && this.contains(r.topRight()) && this.contains(r.bottomLeft()) && this.contains(r.bottomRight())); }
public bool intersects(LDRect r) { return(this.intersected(r).isValid()); }