Skip to content

Commit

Permalink
fix some performance issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Evil-Spirit committed Feb 22, 2019
1 parent 9d09ad5 commit 97896ae
Show file tree
Hide file tree
Showing 18 changed files with 262 additions and 180 deletions.
2 changes: 0 additions & 2 deletions Assets/Code/Constraints/CirclesDistance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ public override IEnumerable<Exp> equations {
var c1 = GetEntity(1);
var r0 = c0.Radius();
var r1 = c1.Radius();
var cp0 = getCenterPoint(c0);
var cp1 = getCenterPoint(c1);
if(isCentersCoincident(c0, c1)) {
if(option == Option.FirstInside) {
yield return r0 - r1 - value.exp;
Expand Down
2 changes: 0 additions & 2 deletions Assets/Code/Constraints/Diameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public override double ValueToLabel(double value) {
}

protected override void OnDraw(LineCanvas canvas) {
var pl = getPlane();
var p = GetEntity(0).CenterInPlane(null).Eval();
var lo = getPlane().projectVectorInto(getLabelOffset());
var dir = (lo - p).normalized;
Expand All @@ -45,7 +44,6 @@ protected override void OnDraw(LineCanvas canvas) {

if(showAsRadius) {
var rpt = p + dir * r;
var rdir = lo - rpt;
drawPointsDistance(p, p + dir * r, canvas, Camera.main, arrow0: false, arrow1: true);
canvas.DrawLine(rpt, lo);
} else {
Expand Down
4 changes: 2 additions & 2 deletions Assets/Code/Constraints/PointsDistance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ Vector3 GetPointPosInPlane(int i, IPlane plane) {
}

protected override void OnDraw(LineCanvas canvas) {
Vector3 p0p = GetPointInPlane(0, null).Eval();
Vector3 p1p = GetPointInPlane(1, null).Eval();
Vector3 p0p = GetPointPosInPlane(0, null);
Vector3 p1p = GetPointPosInPlane(1, null);
drawPointsDistance(p0p, p1p, canvas, Camera.main, false, true, true, 0);
}

Expand Down
10 changes: 4 additions & 6 deletions Assets/Code/DetailEditor/DetailEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ public static DetailEditor instance {
}

Detail detail;

public Detail GetDetail() { return detail; }

public UndoRedo undoRedo;

public GameObject labelParent;
Expand Down Expand Up @@ -447,12 +450,7 @@ public List<IdPath> Paste(string str) {
sk.idMapping = null;

var objs = result.Select(o => sk.GetChild(o.Value)).ToList();
foreach(var obj in objs) {
var sko = obj as SketchObject;
if(sko == null) continue;
if(!(sko is Entity) || (sko as Entity).type != IEntityType.Point) continue;
sko.Drag(delta);
}
MoveTool.ShiftObjects(objs, delta);

return objs.Select(o => o.id).ToList();
}
Expand Down
8 changes: 0 additions & 8 deletions Assets/Code/Entities/Entity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -240,14 +240,6 @@ public int GetChildrenCount() {
return children.Count;
}

public Id GetChildGuid(int i) {
return children[i].guid;
}

public void SetChildGuid(int i, Id guid) {
children[i].SetGuid(guid);
}

IEnumerable<ExpVector> IEntity.points {
get {
for(var it = points.GetEnumerator(); it.MoveNext(); ) {
Expand Down
8 changes: 6 additions & 2 deletions Assets/Code/Entities/PointEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,16 @@ public Vector3 pos {
}
}

ExpVector exp_;
public ExpVector exp {
get {
if(exp_ == null) {
exp_ = new ExpVector(x, y, z);
}
if(transform != null) {
return transform(new ExpVector(x, y, z));
return transform(exp_);
}
return new ExpVector(x, y, z);
return exp_;
}
}

Expand Down
4 changes: 2 additions & 2 deletions Assets/Code/Features/ExtrusionFeature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public class ExtrusionFeature : MeshFeature {
public Param extrude = new Param("e", 5.0);
GameObject go;

public Sketch sketch {
public Sketch sourceSketch {
get {
return (source as SketchFeature).GetSketch();
}
Expand All @@ -201,7 +201,7 @@ public override ICADObject GetChild(Id guid) {
var result = base.GetChild(guid);
if(result != null) return result;

var entity = sketch.GetEntity(guid.WithoutSecond());
var entity = sourceSketch.GetEntity(guid.WithoutSecond());
if(guid.second == 2) return new ExtrudedPointEntity(entity as PointEntity, this);
return new ExtrudedEntity(entity, this, guid.second);
}
Expand Down
6 changes: 3 additions & 3 deletions Assets/Code/Features/LinearArrayFeature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ protected override void OnReadMeshFeature(XmlNode xml) {
*/
public ExpVector shiftDir {
get {
var skf = source as SketchFeature;
//var skf = source as SketchFeature;
return new ExpVector(dx, dy, 0f);
}
}
Expand Down Expand Up @@ -253,9 +253,9 @@ public override Bounds bounds {
}

public void DrawGizmos(Vector3 mouse, Camera camera) {
var ray = camera.ScreenPointToRay(mouse);
HashSet<int> hits = new HashSet<int>();
drawGizmos = true;
//HashSet<int> hits = new HashSet<int>();
//var ray = camera.ScreenPointToRay(mouse);
//FindHits(ray, 0, repeatCount - 1, ref hits);
double dist = 0;
OnHover(mouse, camera, Matrix4x4.identity, ref dist);
Expand Down
14 changes: 7 additions & 7 deletions Assets/Code/Features/RevolveFeature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ public IEntity origin {
}
}

public Sketch sketch {
public Sketch sourceSketch {
get {
return (source as SketchFeature).GetSketch();
}
Expand All @@ -265,7 +265,7 @@ public override ICADObject GetChild(Id guid) {
var result = base.GetChild(guid);
if(result != null) return result;

var entity = sketch.GetEntity(guid.WithoutSecond());
var entity = sourceSketch.GetEntity(guid.WithoutSecond());
if(guid.second == 2) return new RevolvedPointEntity(entity as PointEntity, this);
return new RevolvedEntity(entity, this, guid.second);
}
Expand Down Expand Up @@ -349,7 +349,7 @@ protected override void OnUpdateDirty() {
var prj = ExpVector.ProjectPointToLine(pos, o, o + ax);
if((prj - pos).magnitude < 1e-6) continue;

var ax1 = Vector3.Cross(sketch.plane.n, pos - prj);
var ax1 = Vector3.Cross(sourceSketch.plane.n, pos - prj);
shouldInvertAxis = (Vector3.Dot(ax, ax1) > 0f);
axisDirectionFound = true;
break;
Expand All @@ -363,7 +363,7 @@ protected override void OnUpdateDirty() {
var prj = ExpVector.ProjectPointToLine(pos, o, o + ax);
if((prj - pos).magnitude < 1e-6) continue;

var ax1 = Vector3.Cross(sketch.plane.n, pos - prj);
var ax1 = Vector3.Cross(sourceSketch.plane.n, pos - prj);
shouldInvertAxis = (Vector3.Dot(ax, ax1) > 0f);
axisDirectionFound = true;
break;
Expand Down Expand Up @@ -411,7 +411,7 @@ protected override ICADObject OnHover(Vector3 mouse, Camera camera, UnityEngine.
var points = sk.GetSketch().entityList.OfType<PointEntity>();
double min = -1.0;
IEntity hover = null;
var sktf = tf * sk.GetTransform();
//var sktf = tf * sk.GetTransform();
foreach(var p in points) {
var e = new RevolvedPointEntity(p, this);
double d = e.Hover(mouse, camera, tf);
Expand All @@ -422,7 +422,7 @@ protected override ICADObject OnHover(Vector3 mouse, Camera camera, UnityEngine.
hover = e;
}

foreach(var p in sketch.entityList) {
foreach(var p in sourceSketch.entityList) {
var e = new RevolvedEntity(p, this, 0);
double d = e.Hover(mouse, camera, tf);
if(d < 0) continue;
Expand All @@ -432,7 +432,7 @@ protected override ICADObject OnHover(Vector3 mouse, Camera camera, UnityEngine.
hover = e;
}

foreach(var p in sketch.entityList) {
foreach(var p in sourceSketch.entityList) {
var e = new RevolvedEntity(p, this, 1);
double d = e.Hover(mouse, camera, tf);
if(d < 0) continue;
Expand Down
4 changes: 2 additions & 2 deletions Assets/Code/Geometry/MeshUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static void CreateMeshRegion(List<List<Vector3>> polygons, ref Mesh mesh)
public static void DrawTriangulation(List<List<Vector3>> polygons, LineCanvas canvas) {
foreach(var p in polygons) {
var pv = new List<Vector3>(p);
var triangles = Triangulation.Triangulate(pv, canvas);
/*var triangles = */Triangulation.Triangulate(pv, canvas);
}
}

Expand Down Expand Up @@ -177,7 +177,7 @@ public static Solid CreateSolidRevolve(List<List<Entity>> entitiyLoops, float an
if(!isHelix && Mathf.Abs(angle) > 360f) angle = Mathf.Sign(angle) * 360f;
bool inversed = angle < 0f;
int subdiv = (int)Mathf.Ceil(Math.Abs(angle) / angleStep);
var drot = UnityEngine.Matrix4x4.Translate(origin) * UnityEngine.Matrix4x4.Rotate(Quaternion.AngleAxis(angle / subdiv, axis)) * UnityEngine.Matrix4x4.Translate(-origin);
//var drot = UnityEngine.Matrix4x4.Translate(origin) * UnityEngine.Matrix4x4.Rotate(Quaternion.AngleAxis(angle / subdiv, axis)) * UnityEngine.Matrix4x4.Translate(-origin);

Func<float, Vector3, Vector3> PointOn = (float a, Vector3 point) => {
var ax = axis;
Expand Down
10 changes: 10 additions & 0 deletions Assets/Code/Sketch/IdPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ public override string ToString() {
if(second == 0) return value.ToString("X");
return value.ToString("X") + ":" + second.ToString("X");
}

public override int GetHashCode() {
return (int)value;
}

public override bool Equals(object obj) {
var o = (Id)obj;
if(o == this) return true;
return value == o.value && second == o.second;
}
}

public class IdGenerator {
Expand Down
Loading

0 comments on commit 97896ae

Please sign in to comment.